title: Are there deprecated practices for multithread and multiprocessor programming that I should no longer use?

text: In the early days of FORTRAN and BASIC, essentially all programs were written with GOTO statements. The result was spaghetti code and the solution was structured programming. Similarly, pointers can have difficult to control characteristics in our programs. C++ started with plenty of pointers, but use of references are recommended. Libraries like STL can reduce some of our dependency. There are also idioms to create smart pointers that have better characteristics, and some version of C++ permit references and managed code. Programming practices like inheritance and polymorphism use a lot of pointers behind the scenes (just as for, while, do structured programming generates code filled with branch instructions). Languages like Java eliminate pointers and use garbage collection to manage dynamically allocated data instead of depending on programmers to match all their new and delete statements. In my reading, I have seen examples of multi-process and multi-thread programming that don't seem to use semaphores. Do they use the same thing with different names or do they have new ways of structuring protection of resources from concurrent use? For example, a specific example of a system for multithread programming with multicore processors is OpenMP. It represents a critical region as follows, without the use of semaphores, which seem not to be included in the environment.               th_id = omp_get_thread_num();     #pragma omp critical     {       cout << "Hello World from thread " << th_id << '\n';     }      This example is an excerpt from: http://en.wikipedia.org/wiki/OpenMP Alternatively, similar protection of threads from each other using semaphores with functions wait() and signal() might look like this:               wait(sem);     th_id = get_thread_num();     cout << "Hello World from thread " << th_id << '\n';     signal(sem);      In this example, things are pretty simple, and just a simple review is enough to show the wait() and signal() calls are matched and even with a lot of concurrency, thread safety is provided. But other algorithms are more complicated and use multiple semaphores (both binary and counting) spread across multiple functions with complex conditions that can be called by many threads. The consequences of creating deadlock or failing to make things thread safe can be hard to manage. Do these systems like OpenMP eliminate the problems with semaphores?   Do they move the problem somewhere else?   How do I transform my favorite semaphore using algorithm to not use semaphores anymore?


title: What methods are available to show colleagues the advantages of a database+application solution over Excel?

text: I work in a company where there are Excel spreadsheets everywhere. As my colleagues are non-programmers, I'm sure they haven't contemplated that there might be a better/easier/more productive way of managing their data. Naturally, I advocate an application of sorts that can leverage the features you find in relational databases and interactive front ends, tailored to the needs of the various workflows currently distributed over disparate spreadsheets. The problem I have is that I have tried to explain the merits of such systems to various parties, but short of actually writing them from scratch I'm having a hard time convincing them, or even just exposing them to the greener grass. People in general understand Excel (even if they aren't power users) but perhaps go all fuzzy when the word 'database' pops up or you start talking about 'code'. Can anyone suggest a method, with evidence of how a workflow was improved by switching from spreadsheets to an actual application? **UPDATE** Thanks to everyone for their replies. It seems that there are no textbook methods as such, more a range of philosophical approaches to the problem i.e. the problem isn't that Excel is profligate, the problem is in how to communicate the fact that there are sometimes better tools for the job.


title: Use TFS to track bugs from Production Support

text: I have just moved to a new company and they are using TFS 2010 (2012 in a couple of months) as their version control system and recently started to use it as a work tracking system for the developers. However, there doesn't seem to be a bug tracking system for use by people outside development & test. Production support are getting reports of issues, fixing them on the fly and reporting back to their users at the moment. This needs to be changed but I don't really want to have a sperate system for tracking bugs and tracking dev work. Is there a way that I can create a very light weight way of entering bugs into TFS similar to the way that FogBugz does? Logging into TFS to fill out a bug report seems to be a lot heavier and you have to associate it with a particular application. Support may be able to do this but I want to be able to triage the item and potentially change the association to something other than an application. I have used FogBugz in the past and when adding a bug, you can add a much/little as you want to the item so it is at least recorded and later you can bounce it back to get more information when you come to triage the ticket.


title: Binary Tree/Knowledge Base design C++

text: Currently I have a binary tree template setup where my main is using it with strings to make a question/answer game. I'm using a knowledge base that works as an interface to the binary tree that main uses (main has no access to node or binary tree classes). My code seems to work fine inserting/rearranging nodes as necessary but I think my design is pretty bad. Is it usually best to just put the Node and BinaryTree classes in the same file since neither is independently useful? Or is it even standard when using binary trees to just make node a nested class inside the tree class? Not sure how to not use class friending (assuming this is bad design) unless I just do away with the knowledge base. Without knowledge base being able to see private node members it wouldn't be able to move it's "current" node pointer around the tree through questions/guesses unless it passed its current pointer by reference to a binary tree function that moved it each time. Also with this setup binary tree doesn't really do anything except provide a root node as k base is handling the inserting/rearranging/differentiating between questions and guesses, so I'm not sure how to move some traversal, etc. functionality from kbase to btree without just making a bunch of kbase functions that call their btree counterparts. Is there a way to use std::swap in each file (node/tree/base) also without polluting with the utility header? This design looks to be bad OO-wise, any help is appreciated.


title: JOIN vs. INNER JOIN and FULL OUTER JOIN

text: I know there is a difference between `INNER JOIN` and `FULL OUTER JOIN`, I can see it, but, what is the difference between the two following: `JOIN ... ON...` and `INNER JOIN...ON...` and still yet `JOIN...ON...` vs `FULL OUTER JOIN...ON...` Reason being is I think maybe just using `JOIN` is messing up a query I am working on that is posted on SO, link to question HERE. So basically what is the syntactical difference between the actual set operations themselves? Thank You,


title: Motivate developers to keep up with admin tasks

text: We started off using Scrum, but recently changed to Kanban because fixed iterations didn't work in our situation. Kanban isn't working either, because team members are not updating the Kanban board. **Everyone understands what it is for** and why we have it. **Everyone agrees we should keep it up to date** , but somehow it never actually happens. The reason given is that it takes too long to write out a new card and pin it to the board. One developer said they wanted an all-electronic board to avoid this overhead, but I don't believe that this would solve the problem. (The board is right next to the cubicle where the developers sit.) I'm not the team leader (in fact I'm not even on the team). I cannot impose sanctions or offer rewards - nor would I want to anyway because I think it's bad for team morale. In any case, the team needs to completely self-administer whatever solution is found. I've run out of ideas. Any suggestions?


title: How much logging should I do at production for SQLExcpetions?

text: I'm writing a small database-centric application in Java Swing that will be used internally in a small company. I haven't much experience with developing production-level applications. I don't use an ORM, just a few simple methods that run SQL queries with Java JDBC. On every method that access the database I use a `try-catch` statement for `SQLException` and `IOException`. Should I do any logging here? In case I should, how much should I log? Please give me examples of good practice in this case.


title: Why do people still say Java is slow?

text: For a long time in SO and in other places Java has the reputation of being slow. From jokes to many comments in questions and answers, people still believe Java is slow based solely on experience with it in the 90s. This is my issue: we have disproved (most) of the reasons that people believe Java is slow. Outside of small things, Java is pretty fast. So why is it that people still refuse to believe Java is fast now? Is it part of their mindset that anything thats not C/C++ is slow? Is it because people don't check over time? Is it because people are just biased?


title: int* i; or int *i; or int * i;

text: What is your favorite method to declare a pointer?               int* i;      or               int *i;      or               int * i;      or               int*i;      Please explain why. see also: http://www.stroustrup.com/bs_faq2.html#whitespace


title: How do you deal with intentionally bad code?

text: There are many stories about intentionally bad code, not only on TheDailyWTF but also on SO. Typical cases include:   * Having a useless time-wasting construct (e.g. an empty loop counting to some huge value) so programmers can easily "speed up" the application by removing it when they are tasked to.   * Providing intentionally misleading, wrong or no documentation to generate expensive support requests.   * Readily generating errors, or worse, generating even though everything worked fine, locking up the application so an expensive support call is required to unlock. These points display a more or less malicious attitude (even though sometimes by accident), especially the first point occurs rather often. How should one deal with such constructs? Ignore the issue, or just remove the offending code? Notify their manager, or speak to the person who introduced the "feature"?


title: For Windows developers who would like to get into the Mac OS X software development industry, what's a great way to get started?

text: For a developer that wants to start developing software for Mac OS X, what is the best way to get started?


title: Constant Interface antipattern - PHP

text: I came across this Wikiepedia article which says that using interfaces for defining constants is not a good thing. Solution suggested there is to define constants in a final class and use static import. That works for Java. I come from the PHP world which does not have the "import" thing. So, what is the acceptable solution for PHP?


title: Web development for an otherwise widely experienced programmer?

text: I have been [hobby] programming for years now and know several languages including Objective-C, Java, C#, Python, C, and C++ well. I understand many programming patterns and have used several different frameworks. However, I know almost nothing about web development. I'm looking for a resource that, instead of diving right into code, kind of gives me a bird's eye view of how all the technologies work together. Oftentimes, I'll see several things studied in depth like HTML, CSS, JavaScript, ActionScript, AJAX, etc., but no explanation of where they all fit in the big picture. I'd also like to avoid all-encompassing IDE's starting out, as that tends to make it harder to actually understand whats going in the learning phase. Any links, resources, preferably free and online, advice, etc. much appreciated. Thanks!


title: How to learn/become capable of thinking out of the box?

text: In every problem solving there's always people who think differently, who come with a 6th option when only 5 were suggested by others, who think "out of the box". Please tell how one can achieve such ability? And what it takes to achieve it?


title: Python - Is this a bad strategy pattern?

text: I've got a Python project wherein a basic object is created and various different attributes are modified/given to it via what I _thought_ was a good example of a strategy pattern. In this silly game there are enemies with multiple different potential patterns of movement. The Enemy class has a basic pattern of movement it defaults to; otherwise, a strategy pattern is implemented to randomly choose different ones as the game progresses. The Enemy's `obj.update()` is something like this:               def update(self):         self.unique_action()         self.check_if_shooting()         self.find_new_rect()      So I'd been replacing `self.unique_action` on the fly with a strategy pattern using what I think are called 'higher-order functions'.               def new_pattern_of_movement(obj, func):         def inner(*args, **kwargs):             ##code for doing different stuff             ##intentionally NOT returning the function -              ##the idea is to replace the default unique_action         return inner          …     ##eventually when generating bad guys for the level…     newEnemy = Enemy()     new_AI = random.choice([new_pattern_of_movement, other_pattern, some_other_pattern]) #etc etc     newEnemy.unique_action = new_AI(newEnemy, newEnemy.unique_action)      After a while, I thought, "self, why not change their attributes as part of the wrapper as well? you change their methods, just set their point_value and graphics and all that dumb stuff too" and I was like "welp I can do that"               def alt_action(obj):         def inner(*args, **kwargs):             ##code for their unique_action             ##again, not returning obj.unique_action         obj.point_value += 100         obj.color = colors.YELLOW         obj.speed -= 1         return inner      Evidently, this is regarded as "very JavaScript-y". I find it terribly simple though, and preferable to stringing along a bunch of objects that inherit from a long chain of ancestors. My job isn't on the line or anything here, but in such a situation is it really that critical to split these up into separate classes? The first example, at the least, seems fine because it really is just replacing one method with another, but in the second example, I'm definitely redefining object attributes, and I go a bit further than depicted here (replacing the object's `self.draw()` methods and that if it's necessary). It might be bad, but it's _so stupidly easy_. Is this a good example of how _not_ to implement a strategy pattern?


title: if else empty curly braces

text: for(int i = 0; i < str.length(); i++)      {         if(i != str.length() - 1 && Character.toString(str.charAt(i)).equals("*"))      {           if(i != 0 && Character.toString(str.charAt(i - 1)).equals(Character.toString(str.charAt(i + 1)))) {           } else if(i == 0) {           } else {             return false;           }         }       }       return true      what does the empty braces after if/else statement mean or which value is returned


title: Friday afternoon, nothing to do - try and learn something?

text: Its Friday afternoon and I've literally done everything expected of me. I'm thinking I should spend this productively, and fancy running through the asp.net mvc tutorial (since we've got nothing MVC here) - is this a bad thing? I don't want to feel like I'm wasting company time.


title: How do I make an estimate for my first website?

text: Technically not my first, but my new client wants to enter into negotiations regarding the cost of a website. It's fairly straight-forward, it's a little bit more than a portfolio page, and I should be able to finish it without much complications. However, I don't know how to make an estimate to enter negotiations. One that will not scare the client away, and will ensure that I'm making the best out of it as well.


title: How detailed should public release notes be?

text: When releasing a software update, how detailed should the notes be? Specifically, how detailed should bug fixes be?


title: random generator not good enough?

text: During an interview I was asked to implement a random generator in java without using any existing random number libraries that takes as an argument int n, and returns a random number between 0 and n. This was the implementation I provided:               public static int random(int n) {         int r = 0;         for (int i =0; i <n;i++) {             r+=helper();         }         return r;     }          // helper that returns 0 or 1     private static int helper() {         long t = System.nanoTime();         if (t%2 == 0) {             return 1;         } else {             return 0;         }     }      He said it's not right but he wouldn't tell me what he was expecting. Why did he say it's wrong? How would you have done it differently?


title: Standardized code documentation format, where is it?

text: I'm currently looking into API documentation generation tools and I noticed that apparently there are no efforts going on in standardization. Javadoc style is kind of an ubiquitous convention... it is used for Java (duh), PHP (PHPDocumentor, Doxygen, Stubbles), C/C++ (Doxygen again)... and there is even IDE support for it even in other languages that are not java. Even NaturalDocs which has a completely different syntax for documentation has some compatibility for it. So my question is: **are there any efforts going on in standardizing in-code documentation syntax?** , which can in turn be used for documentation generators or language metadata across different languages?.


title: Why fork a library for your own application?

text: Why should a programmer ever fork a library for inclusion in a widely used application? I ask this question because I was reading an article about why Chromium isn't packaged for many Linux distros like Fedora. Apparently its largely due to the fact that Google has forked a number of libraries, modified them, and included them in Chromium. This has driven up the complexity of packaging releases. There are a number of reasons why this can be a bad thing, but how strong a case can you actually make for doing so in a large widely used application such as Chromium? The original article: http://ostatic.com/blog/making-projects-easier-to- package-why-chromium-isnt-in-fedora Isn't it usually worth the effort to make slight modifications to your own program in order to use a popular and well developed library?


title: Parser combinator that looks like BNF

text: Is it possible to construct a parser combinator library that reads like a BNF grammar? I don't know of any, so I started wondering if there are reasons it's impossible or undesirable to do so. It seems to me it would be the best of both worlds. Functional languages such as F# allow operator overloading. Is it just a matter of providing the right syntax, or is there more to it?


title: What is the benefit of passing a delegate to the constructor instead of just having the client code create and pass the ParserSettings?

text: When answering a question on Stack Overflow, the library appeared to have a weird way to specify configuration, through an `Action` passed to the constructor:               public Parser(Action<ParserSettings> configuration)     {         if (configuration == null) throw new ArgumentNullException("configuration");         this.settings = new ParserSettings();         configuration(this.settings);         this.settings.Consumed = true;     }          internal Parser(ParserSettings settings)     {         this.settings = settings;         this.settings.Consumed = true;     }      So to specify the settings you provide a `Action<ParserSettings>` that modifies the settings:               var parser = new Parser( s => { s.CaseSensitive = false; } );      I don't understand what this pattern accomplishes. What is the benefit of passing a delegate to the constructor instead of just having the client code create and pass the `ParserSettings` to the constructor?


title: Is it fair to charge again for checking why my code not working on client's server?

text: So, I was tasked by client to help him convert his wp menu to javascript dropdown. I did on my development server. He did see the change and I was paid. I deliver the code he deploy it. But, no change on his server. So, I have to spent hours debugging it on his server. It turns out, his other plugin is not compatible with my change. That plugin is really custom. I have to change my code to make sure it's compatible with that plugin. My question is, **is it fair for me to charge him for the hours I spent on debugging it AND actually fixing it?** or **is it still my responsibility, to make sure my code deployed properly?**


title: Is it better to be specialized in a few areas or have general abilities in many?

text: My situation is this. I will be graduating soon with a degree in Computer Science. I did have a job for a while working as a Web Developer for a small graphic design company. During this time, we did work on a few large scale projects for the local university. I eventually had to leave that job after the economy crashed due to a lack of available work. Since then I haven't had any jobs related to my field as there aren't usually many available in the area I live in. I have been actively searching for jobs for the last 4 months and have had very little if any positive feedback. This has left me wondering if perhaps my qualifications are what they should be. I would say in general I have a basic to intermediate understanding of many languages and systems. I'm not sure I could say I'm specialized in anything, though web development using PHP/MySQL would be the closest thing I have to a specialty. That being said I'm not sure at this point that I want to pursue only web development as I would prefer to get more into desktop application development. Do employers look more for people with specialties than they do those that have broad general abilities?


title: When should I start the server side coding?

text: I am creating a website, where users can upload their own videos. So far I am just building the main structure with HTML and CSS. Is it a better practice to write server-side code _before_ the site layout is finished? Does it not make a difference?


title: What did Linus Torvalds mean by his quotation about portability?

text: In a debate with Andrew Tanenbaum over microkernel vs. monolithic operating system architecture, Linus Torvalds said, > Portability is for people who cannot write new programs. What did he mean by that?


title: GPS accuracy with software

text: I spoke with a guy who claimed that he's working (programming) on a GPS-system that is going to be accurate to the centimeter.   * Is this even possible?    * What is the limiting factor, the big distance between the satellite and the GPS, or is it the software?    * Can the software be improved to make a GPS accurate to centimeters?


title: Open source license that requires visible attribution in derivative works?

text: My company has a client-side web application that we would like to open- source. We don't want to impose any restrictions on usage, except that any modifications and derivative works should contain a **visible** attribution, e.g. show our name and/or logo - we want it to be visible that our code is being used in the application. As I understand, while licenses like BSD 3-clause contain an attribution requirement, it can be satisfied with something like a HTML comment only. How to license to ensure that derivative works are visibly labeled?


title: What is the best way to handle dynamic content?

text: So we run a site where there are elements of the interface that could potentially be changed at any moment in the backend. Specifically we run a web service where certain functions are loaded dynamically. However, there are times where we remove certian functions and we want the experience to be as seamless for the user as possible. Now we've considered a few methods of solving this   1. Ping the server every few seconds. If the functions are outdated/no longer available refresh the users page. While this would work the best, I feel like having that much IO can't be too good   2. When the user clicks a function, if it's outdated/no longer available, alert them in the response and refresh the page. This would also work fairly well. I guess I'm more wondering how web apps like Google Docs work where you have content that has to be synced up across multiple users and that isn't more than a few seconds outdated Sorry if this isn't the best place to ask this. I figured this was more of a site architecture question and that this might be the place to ask it over SO.


title: Advice for learning Javascript with prior knowledge of C++?

text: Recently I have become interested in learning Javascript for web development. I currently know HTML, CSS, and beginner/intermediate C++. I understand polymorphism, inheritance, and all of that fun stuff. Would any of these skills carry over to Javascript? In what key ways does Javascript differ from C++?


title: How can I gather client's data on Google App Engine without using Datastore/Backend Instances too much?

text: One of the projects I'm working on is online survey engine. It's my first big commercial project on Google App Engine. I need your advice on how to collect stats and efficiently record them in DataStore without bankrupting me. Initial requirements are:   * After user finishes survey client sends list of pairs [ID (int) + PercentHit (double)]. This list shows how close answers of this user match predefined answers of reference answerers (which identified by IDs). I call them "target IDs".   * Creator of the survey wants to see aggregated % for given IDs for last hour, particular timeframe or from the beginning of the survey.   * Some surveys may have thousands of target/reference answerers. So I created entity               public class HitsStatsDO implements Serializable     {         @Id         transient private Long id;         transient private Long version = (long) 0;              transient private Long startDate;              @Parent transient private Key parent;   // fake parent which contains target id         @Transient int targetId;              private double avgPercent;         private long hitCount;     }      But writing HitsStatsDO for each target from each user would give a lot of data. For instance I had a survey with 3000 targets which was answered by ~4 million people within one week with 300K people taking survey in first day. Even if we assume they were answering it evenly for 24 hours it would give us ~1040 writes/second. Obviously it hits concurrent writes limit of Datastore. I decided I'll collect data for one hour and save that, that's why there are `avgPercent` and `hitCount` in `HitsStatsDO`. GAE instances are stateless so I had to use dynamic backend instance. There I have something like this:               // Contains stats for one hour     private class Shard     {         ReadWriteLock lock = new ReentrantReadWriteLock();         Map<Integer, HitsStatsDO> map = new HashMap<Integer, HitsStatsDO>(); // Key is target ID              public void saveToDatastore();         public void updateStats(Long startDate, Map<Integer, Double> hits);     }      and map with shard for current hour and previous hour (which doesn't stay here for long)               private HashMap<Long, Shard> shards = new HashMap<Long, Shard>();   // Key is HitsStatsDO.startDate      So once per hour I dump Shard for previous hour to Datastore. Plus I have `class LifetimeStats` which keeps `Map<Integer, HitsStatsDO>` in memcached where map-key is target ID. Also in my backend shutdown hook method I dump stats for unfinished hour to Datastore. There is only one major issue here - **I have only ONE backend instance** :) It raises following questions on which I'd like to hear your opinion:   * Can I do this without using backend instance ?   * What if one instance is not enough ?   * How can I split data between multiple _dynamic_ backend instances? It hard because I don't know how many I have because Google creates new one as load increases.   * I know I can launch exact number of _resident_ backend instances. But how many ? 2, 5, 10 ? What if I have no load at all for a week. Constantly running 10 backend instances is too expensive.   * What do I do with data from clients while backend instance is dead/restarting? One thing to note is that I can't change client much. Currently it's JavaScript embedded into web-pages of customers. I can change RPC in some way but architecturally I cannot replace client with Google Docs forms for example.


title: How to get experience in large scale databases?

text: I have written applications that are very small scale and the code I write works fine for them. But I have often wondered how the server side code I write would scale up from 100s of queries per day to millions. Also when looking at possible jobs/projects, people are often looking for developers with experience in this sort of high traffic database design so I would at least like to be able to say, I havent gotten to work on a project that was this popular, but I at least have tried to simulate it. Are there tools or frameworks that can generate a lot of traffic or at least simulate what would happen with traffic on different orders of magnitude so I could get some practice writing optimized code for higher traffic applicaitons?


title: What is wrong with my logic for the divide and conquer algorithm for Closest pair problem?

text: I have been following Coursera's course on Algorithms and came up with a thought about the divide/conquer algorithm for the closest pair problem, that I want clarified. As per Prof Roughgarden's algorithm (which you can see here if you're interested): For a given set of points P, of which we have two copies - sorted in X and Y direction - Px and Py, the algorithm can be given as closestPair(Px,Py):   1. Divide points into left half - Q, and right half - R, and form sorted copies of both halves along x and y directions - Qx,Qy,Rx,Ry   2. Let closestPair(Qx,Qy) be points p1 and q1   3. Let closestPair(Rx,Ry) be p2,q2   4. Let delta be minimum of dist(p1,q1) and dist(p2,q2)   5. This is the unfortunate case, let p3,q3 be the closestSplitPair(Px,Py,delta)   6. Return the best result Now, the clarification that I want is related to step 5. I should say this beforehand, that what I'm suggesting, is barely any improvement at all, but if you're still interested, read ahead. Prof R says that since the points are already sorted in X and Y directions, to find the best pair in step 5, we need to iterate over points in the strip of width 2*delta, starting from bottom to up, and in the inner loop we need only 7 comparisions. Can this be bettered to just one? How I think is possible seemed a little difficult to explain in plain text, so I drew a diagram and wrote it on paper and uploaded it here: ![enter image description here](http://i.stack.imgur.com/XhqWc.jpg) Since no one else came up with is, I'm pretty sure there's some error in my line of thought. But I have literally been thinking about this for HOURS now, and I just HAD to post this. It's all that is in my head. Can someone point out where I'm going wrong?


title: Why is MaybeChannelBound callable?

text: The Queue class in the python kombu library inherits from MaybeChannelBound, which in turn implements the **call** method (making it callable). The **call** () method itself is a thin wrapper around the bind() method. It is not clear why this was done, as calling the bind() method seems (to my simple mind, at least) to be clearer and more descriptive of the intent of the function. Why would somebody use the **call** () method in a situation like this?


title: How do I implement the MPL? What's this "Exhibit A" thingy?

text: I'm about to start an open-source project which shall be licensed under Mozilla Public License (MPL). The problem is, I'm not sure what's this "Exhibit A" thing... Am I supposed to put that wordy "Exhibit A" in each and every source file contained in the project? And what about the MPL text proper; must I provide a complete text of the MPL in the root directory of the project? I'd really appreciate it if someone can point me to a guide on how to _release_ software under MPL (as opposed to _using_ software with MPL). TIA.


title: FIFO lock with mutiple threads/processes

text: I need to use FIFO in my application in linux+C, I have multiple threads and processes, I read some where that writing to a FIFO is atomic below some value (I believe 4k) especially I'm writing max of 300 bytes, Am I safe here?


title: Dependency Injection: Only for single-instance objects?

text: What if I want to also decouple my application, from classes like Product or User? (which usually have more than one instance) Take a look at this example:               class Controller {         public function someAction() {             $product_1 = new Product();             $product_2 = new Product();             // do something with the products         }     }      Is it right to say that Controller now depends on Product? I was thinking that we could decouple them too (as we would with single- instance objects like Database) In this example, however ugly, they are decoupled:               class Controller {         public function someAction(ProductInterface $new_product) {             $product_1 = clone $new_product;             $product_2 = clone $new_product;             // do something with the products         }     }      Has anyone done something like this before? Is it excessive?


title: Can *any* program task be expressed without state?

text: This is a theoretical question, but after many years of programming in what I now realize is "normal" imperative technique, using C++ mainly, I've discovered this other world of functional programming, which I stumbled upon accidentally while casually learning JavaScript. This has led me to wonder if you could technically replace any complete state- oriented program with a different implementation that is purely functional and without state? It's an intriguing idea and I must admit that there is a clarity and elegance in functional programming that has really blown my mind.


title: Do some best practices depend on skill?

text: Is there evidence that some software development best practices depend on programming skill level? I mean, these methods are good, but maybe the way the are used or the extent might vary? This question arose after I read Paul Graham's commentary about OOP, and the last bullet point of this accepted answer. It proposes that where, how, and how much to use unit tests might depend on your programming skill. So do top programmers use different approaches than average programmers?


title: Is QA or testing a lot of overhead or not utilized properly?

text: From my experiences in software development (Eg. Waterfall ) I see it that most of the times it is the development team that sweats it out with the BA folk to get requirement clarity. The development folks then slog it out to meet deliverable deadlines. Where is the QA - they might be free - but will only hitch onto the bandwagon after the code is delivered. Then starts a slew of communication regarding what is a defect and what is a requirement change / clarity needed. From QA perspective - log a defect / bug / issue - and then its the development team responsibility to go figure it out. Clearly this is problematic and affects my opinion of the role and value that QA brings to the table in the Waterfall model. The question is if Agile is actually geared towards reducing this 'waste' by getting testing involved early in the development so that issues get eliminated at the start? If so then what aspects of Agile help solve some of the above problems I have experienced?


title: Please explain the statement that the function an+b belongs to O(n^2) and and Θ(n)?

text: Let's say I have a linear function `f(n)= an+b`, what is the best way to prove that this function belongs to O(n2) and `Θ(n)`? I do not need mathematical rigor here. I need a programmers answer. Some logical way of explaining. This is precisely why I didn't post the question in mathematics Q&A and instead in the Programmers Q&A.


title: Has there been any formal proof that documentation in general is incomplete and obsolete to a certain grade?

text: I'm a web developer and I'm currently once again in a situation where a partly clueless ops department requires a "complete" documentation required for technical support of our application by a third-party, including "every possible error situation". Since there is no common ground on what this third- party should be capable of (ops constantly talk about "a person from the street should be able to do it"), I consider such documentation impossible and my experience tells me that every documentation is obsolete and incomplete, even if just a bit. I can't help to wonder: has there been any study or maybe even a proof that this is actually the case? Maybe even Gödel's incompletness theorems could be applied here?


title: RequestContextHolder.currentRequestAttributes() and accessing HTTP Session

text: Need to access `HTTP` session for fetching as well storing some information.I am using `Spring-MVC` for my application and i have 2 options here.   1. User `Request/ Session` in my Controller method and do my work   2. Use `RequestContextHolde` to access Session information. I am separating some calculation logic from Controller and want to access Session information in this new layer and for that i have 2 options   1. Pass session or Request object to other method in other layer and perform my work.   2. use `RequestContextHolder.currentRequestAttributes()` to access `request/ session` and perform my work. I am not sure which is right way to go? with second approach, i can see that method calling will be more clean and i need not to pass `request/ session` each time.


title: How do I distinguish between things belonging to the standard library, specific gems, and those that are user-generated in Ruby?

text: I'm a beginning programmer, that for various reasons is using an existing Ruby codebase to learn to program. My goal is to be able to understand and eventually extend this codebase. However, I find it hard to understand what is a _standard library function_ , a _gem function_ , or a _user-created_ function. Distinguishing between functions may not be the only thing that I need to do, there might be other "thingies" moving around too. The reason for the question is that I want to be able to read the code, and as I go through identify what documentation I need to read in order to understand the code. Hence, my question is: in Ruby code, how do I distinguish between things belonging to the standard library, specific gems, and those that are user- generated, so that I may look in the right place to understand what identified functions (and other things) does?


title: The Apache License, v2.0: Copyright License vs Patent License

text: > # The Apache License, v2.0 > > [..] > > **2\. Grant of Copyright License** > > Subject to the terms and conditions of this License, each Contributor hereby > grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty- > free, irrevocable copyright license to reproduce, prepare Derivative Works > of, publicly display, publicly perform, sublicense and distribute the Work > and such Derivative Works in Source or Object form. > > [..] > > **3\. Grant of Patent License** > > Subject to the terms and conditions of this License, each Contributor hereby > grants to you a perpetual, worldwide, non-exclusive, no-charge, royalty- > free, irrevocable (except as stated in this section) patent license to make, > have made, use offer to sell, sell, import, and otherwise transfer the Work, > where such license applies only to those patent claims licensable by such > Contributor that are necessarily infringed by their Contribution(s) alone or > by combination of their Contribution(s) with the Work to which such > Contribution(s) was submitted. If You institute patent litigation against > any entity (including cross-claim or counterclaim in lawsuit) alleging that > the Work or a Contribution incorporated within theWork constitutes direct or > contributory patent infringement, then any patent licenses granted to You > under this License for that Work shall terminate as of the date such > litigation is filed. While the meaning of the **Copyright License** provision is rather clear, I did not get the meaning of the **Patent License** provision.   * Which advantages does the "Grant of Patent License" provision further give to Contributors? Why are they useful?   * Is the "Grant of Patent License" provision useful only in case of patent litigation?


title: How useful are Lisp macros?

text: Common Lisp allows you to write macros that do whatever source transformation you want. Scheme gives you a hygienic pattern-matching system that lets you perform transformations as well. How useful are macros in practice? Paul Graham said in Beating the Averages that: > The source code of the Viaweb editor was probably about 20-25% macros. What sorts of things do people actually end up doing with macros?


title: How to prevent deep indentations?

text: What steps and measures can I take to prevent deep indentations in my code?


title: Do I really need a disclaimer for free software?

text: If I publish some software on my website which can be downloaded and used free of charge, do I still need a disclaimer? I mean, I am not even selling anything, there is no contract, so why should there be an _implied warranty_? (Which also makes me wonder why there are disclaimers on things like the MIT license.) **Edit:** I am not a US citizen, I am kind of looking for answers as general as possible and as specific as necessary.


title: What's the current best practice for C multithreading?

text: I've been a Java (and PHP) developer for most of my life, but will need to use C for my next project. I remember some basic stuff we did back in school with fork, pthread, semaphores, etc. but I'm not sure if that's still the "way to go" here, or if there have been any recent developments/improvements etc. Google's results seem to be fairly dated. Or does that just mean that this is still the current "state of the art"? Or will I have to use a (system-independent) libary like glib if I want higher-level abstractions, like synchronized queues? What other libraries are there? (The programm will only have to run on Linux though)


title: Rails + Heroku Architecture

text: I'm in the process of developing a Rails app that I plan on subsequently deploying to Heroku. I've never run apps on Heroku (outside of the free simple app) so I have some questions on a few things on how I should architect some aspects of my app to run. I want a service to run on a schedule to check for inactive users to send a 'we haven't seen you in a while' type of email. Would this just be it's own worker dyno in Heroku? Or would that be integrated into the web app as a background job of sorts? In relation to that, I will have a worker dyno that will handle sending account confirmation emails, among other random emails, would it make sense to have that operation be coupled with the process above? Or would it have to be a completely separate dyno? I've done plenty of this type of work in .Net hence some of my confusion on this switch to Rails.


title: Testing on different operating systems

text: I am a developer who has windows 7 installed as the host operating system with vmware. I have linux installed using vmware. Therefore I am able to test java and c++ apps on windows 7 and Linux. I also want to test them on windows 8 and I want to familiarise myself with windows 8. I am debating whether to upgrade my host operating system to windows 8 or install it on vmware?


title: Growing mobile developers inside a web development org

text: I work for a "mature web startup" as a web developer (mainly using PHP). Our main site has about 8 million registered members at the moment. However, the site is basically impossible to use on anything that's not a real computer. One of our most-requested features, if not _the_ most requested, is a mobile app or mobile version of the site. I think we need to do it. Management thinks we need to do it. In fact, everyone in the company thinks we need to do it. But it's nigh impossible to hire someone with iPhone/Android skills in the present market. I'm the only person at the company with any level of mobile development experience currently, and I'm not that good (yet), so I'm seeking comments on how to bootstrap a capacity for mobile development. Anything from general tips (should I focus on developing my personal skills first or try to pick up a more experienced mobile dev?) to specific recommendations on training, etc., may be helpful, as long as it doesn't reduce to "sucks to be you." :-)


title: Should all classes have a default constructor as part of good coding convention

text: From the texts I have read so far, the conventions talk about organizing `constructors`, starting with the `default`, if any. I am wondering, should all classes have a `default constructor` anyway. This will at least help to create a simple instance of the `class` on the fly, without having to use a `parameterized constructor`, which itself may require additional `imports` for specific parameter type.


title: Designing an API for service operations with closely related parameters

text: I'm having trouble deciding how to design this service API.               public class GetCurrentValuesRequest     {         public int ReferenceID { get; set; }         public int[] FilterIDs { get; set; }     }          public class GetDefaultValuesRequest     {         public int[] FilterIDs { get; set; }     }          public class GetValuesAsOfDateRequest     {         public int ReferenceID { get; set; }         public int[] FilterIDs { get; set; }         public DateTime AsOf { get; set; }     }          public class GetValuesAsOfChangeSetRequest     {         public int ReferenceID { get; set; }         public int[] FilterIDs { get; set; }         public long ChangeSetIDs { get; set; }     }          public class GetProposedValuesRequest     {         public int ReferenceID { get; set; }         public int[] FilterIDs { get; set; }         public long ApprovalKey { get; set; }     }          public class GetValuesIfModifiedRequest     {         public int ReferenceID { get; set; }         public int[] FilterIDs { get; set; }         public DateTime Since { get; set; }     }          public class GetValuesResponse     {         public string[] Results { get; set; }     }          public class GetValuesIfModifiedResponse     {         public string[] Results { get; set; }         public bool IsModified { get; set; }     }          public interface IService     {         GetValuesResponse GetValues(GetCurrentValuesRequest request);              GetValuesResponse GetValues(GetDefaultValuesRequest request);              GetValuesResponse GetValues(GetValuesAsOfDateRequest request);              GetValuesResponse GetValues(GetValuesAsOfChangeSetRequest request);              GetValuesResponse GetValues(GetProposedValuesRequest request);              GetValuesIfModifiedResponse GetValuesIfModified(GetValuesIfModifiedRequest request);     }      I've thought about changing it to have make the `IfModified` request / response subclasses of the simple `GetValues` request response and only including one `GetValues` call. The server would return a different response depending on the input request, but that requires user to call `IService` this:               var response = (GetValuesIfModifiedResponse)serviceClient.GetValues(new GetValuesIfModifiedRequest() { ... });      I've also thought about placing `IsModified` in the simple `GetValuesResponse`, and only populating it if a `GetValuesIfModifiedRequest` is passed into it. But that seems a bit strange to include it in a result from a method which does not actually do anything with it. Also, it might throw of a user if they see it and expect to be able to use it in their code. `bool? IsModified` is better, but I'm not entirely sold on it just yet. Any suggestions for how to best design this API?


title: Client auto-detect required server

text: I have a project that requires a client app to communicate with a server. I was wondering if there is a way for the client app to detect available servers and "know" by some method or another which server is the one it needs. The client is built with .net and c#, the server is a simple SQL database.They are on the same network. Is there a built in mechanism to do this or is the task more complex then it seems at first? I don't have more details ATM, it's still just an idea. The reason behind it is that when a user uses the client app, we don't want him to enter connection strings manually if he doesn't have to.


title: Image Processing in browser is too slow on Android compared to that with desktop browser

text: ## Situation I've written a simple black and white image filter application with JavaScript using html5 canvas. Here is an example of the app . (I don't know why it does not work in jsfiddle, so I gave the link to the source code). On my desktop browser and Firefox OS, for images of dimensions less than 1024X768 px, the application worked fine and so I posted it on the marketplace. But when I downloaded it on my Android with the Firefox browser, the application was running very very slow even for images 500x500 having size of 100kbs. ## Implementation Basically what I did was, I set the canvas `display: hidden`, get the image buffer data, take the individual pixel values and modify them (typical point operations), and then generate a .png image from the resulting operation and use an `img` tag to display it, because I could not control the canvas to fit the user screen without overflowing (for images with dimensions greater than screen dimensions). Below are fragments of code from the original code                   function $(tagname, classname){         if(!classname)             return document.getElementsByTagName(tagname);         if(!tagname || tagname == '')             return document.getElementsByClassName(classname);              return document.querySelectorAll(tagname + '.' + classname);          }          function init(imageObj){         var ctx, i, data,image,             len = $('canvas').length;         parentCanvas = $('canvas')[0];         parentContext = parentCanvas.getContext('2d');         if(!parentContext) alert("err");         w = (imageObj.naturalWidth);         h = (imageObj.naturalHeight);         parentCanvas.width = w;         parentCanvas.height = h;         parentContext.drawImage(imageObj, 0, 0, w, h);         parentBuffer = parentContext.getImageData(0, 0, w, h);         image = document.getElementById("canvas");         if(!image){             image = document.createElement('img');             image.id = "canvas";         }            image.src = parentCanvas.toDataURL("image/png");         $('','container')[0].appendChild(image);         //fit();     }     var Effects = {         '1' : function redfilterbw (brgba) {             var utils = new Utils();             var res = utils.monochrome(brgba, 1, 0, 0);             rgba = {                 r : res,                 g : res,                 b : res,                 a : brgba.a             };         },         '11' : function subcontrast(brgba) {         var utils = new Utils();         var res = utils.adjustContrast(brgba,5,-1);         rgba = {             r : res.r,             g : res.g,             b : res.b,             a : brgba.a         };     }, ...     '12' : function addcontrast(brgba) {         var utils = new Utils();         var res = utils.adjustContrast(brgba,5,1);         rgba = {             r : res.r,             g : res.g,             b : res.b,             a : brgba.a         };         };     function Utils () {}          Utils.prototype.monochrome = function (brgba, rwt, gwt, bwt) {         var opr, scale;             scale = 1 / (rwt + gwt + bwt);         rwt *= scale;         gwt *= scale;         bwt *= scale;              opr = parseInt(brgba.r) * rwt + parseInt(brgba.g) * gwt + parseInt(brgba.b) * bwt ;              return opr;     };     Utils.prototype.adjustContrast = function (brgba, mag, charge) {         var opr, adjust = mag * charge, //charge is whether image contrast will increase or decrease and mag is magniute, so its like +5 or -5             factor = (259 * (adjust + 255)) / (255 * (259 - adjust));         opr = {             r : (factor * (brgba.r   - 128) + 128),             g : (factor * (brgba.g   - 128) + 128),             b : (factor * (brgba.b   - 128) + 128),             a : brgba.a         };         return opr;     };     function fit(){              document.getElementById("canvas").src = parentCanvas.toDataURL("image/png");     }          function process (index) {         var i, j, len, data, layer, ctxn, buffer, utils;         utils = new Utils();             //the indexes 9 to 12 are for brightness adjustment hence i need the current context whereas rest are independent operations requiring parentContext.         if (index != 9 && index != 10 && index != 11 && index !=12) {             ctxn = utils.getParentContext();         } else {             ctxn = utils.getthisContext();         }              buffer = ctxn.getImageData(0, 0, w, h);         data = buffer.data;              for(i = 0; i < data.length; i += 4){             rgba = {                 r : data[i],                 g : data[i+1],                 b : data[i+2],                 a : data[i+3]             };             window['Effects'][index](rgba);             data[i] = parseInt(rgba.r);             data[i+1] = parseInt(rgba.g);             data[i+2] = parseInt(rgba.b);         }              ctxn.putImageData(buffer, 0, 0);         fit();     }      ## Explanation of attempts Firstly I don't think, what I have done here is the best way to get the job done, nor maybe the standard way to write a good application. For the time being I thought I had solution which was to first have preview of the image displayed upon which the users would apply the filter and when they save it the effect would be applied to the original image. But the algorithms I found http://stackoverflow.com/questions/18922880/ were slow, I mean the topmost rated algorithm takes nearly a minute on my pc. I do not think that approach will work. ## Request I am looking for a review of my code and implementation, I am particularly interested in how it could be improved and sped up. I am also open to new implementation suggestions and conventions on how to handle images in web- applications.


title: Is mocking for unit testing appropriate in this scenario?

text: I have written around 20 methods in Java and all of them call some web services. None of these web services are available yet. To carry on with the server side coding, I hard-coded the results that the web-service is expected to give. Can we unit test these methods? As far as I know, unit testing is mocking the input values and see how the program responds. Are mocking both input and ouput values meaningful? **Edit :** The answers here suggest I should be writing unit test cases. Now, **how can I write it without modifying the existing code ?** Consider the following sample code (hypothetical code) :                   public int getAge()         {                 Service s = locate("ageservice"); // line 1                 int age = s.execute(empId); // line 2                  return age; // line 3           }      Now How do we mock the output ? Right now , I am commenting out _'line 1'_ and replacing _line 2_ with `int age= 50`. Is this right ? Can anyone point me to the right way of doing it ?


title: Advice/guidelines for managing a distributed development team

text: What are some strategies, methodologies and best-practices for managing a distributed team?   * What can be done to encourage and enforce communication between the various team members?    * Is it possible to adapt/implement existing agile development methodologies over a distributed team? Related but not identical:   * http://programmers.stackexchange.com/questions/7942/what-tools-are-available-for-remote-communication-when-working-from-home-or-with   * http://programmers.stackexchange.com/questions/18/which-programming-specialities-are-needed-in-a-good-web-development-team


title: Any best practices for a distributed agile team?

text: Our scrum teams are split geographically (not ideal I know!) due to specific knowledge only being available in certain countries. So one team of say 7 members, has the business person in one city, 2 devs in another, 2 other devs in another and 2 qa's in another. Any suggestions for how to manage this type of graphically dispersed team? Any best practices? How do you do standups? via skype video? do we ensure that people travel every 6 weeks (the half time of trust apparently)? how do we do the task board? Virtually or via video? would kanban work better in this setup?


title: how to reduce communication time in distributed teams

text: We have 10 distributed teams in our company and we are developing 3 huge web applications. A lot of time of our developers is spent with writing emails. We are using scrum and for that we had a daily stand-up meeting, but other questions regarding product features, design issues are always communicated via email? Is there a method or techniques available to reduce the time which is used to communicate!


title: How to choose a proper parser generator for PHP

text: Some programmers avoid regexes in some situations (see this popular @nickf comment), perhaps using a parsing framework such as Lex/Yacc. Others prefer to stay within PHP, perhaps using regular expressions, as it avoids the need for another framework. When must we use a "real" parser generator instead of coding a parser directly in PHP? What is the best PHP tool-kit for parsing complex things and what factors can help me determine which is the best? As I mentioned earlier, perhaps there is no best solution, but simply good practices to help select a solution. * * * ## NOTE **Read below only if you is a answer writer** My question was edited: now have good english and objectivity (!), thanks a lot for @FrustratedWithFormsDesigner, @gnat and @Matt. But, perhaps with @Matt editins, losted my point of view.   * My point is not a "Regular expressions vs. framework" dichotomy (!).   * I think (and see examples) that programming PHP, we have a good "tool kit", not only with _regular expresions_ (see the power of preg_replace_callback), strings functions, etc., for simple or very specific parsing tasks; but also with XML Manipulation, for complex tasks! See de "parsing power" of process with DOM and/or XSLT...   * I see also cases where I have a dilema about use this "PHP native tool kit", or install and learn about some external _paser generator_ (plugged as a library, or a class, etc.).


title: How do you make your applications looking more sexy?

text: The other title of this question could also be: How to improve my creativeness? During the past years I noticed that a loot of my small applications that I write in my free time to ease my life could also be useful for some of my friends. They asked me to get them a copy. Even if the applications are working as they should I feel a little bit embarrassed because they GUIs are all looking really ugly. The problem is, I always used standard and default-looking Buttons, TextBoxes etc. Now I thought about how to improve this. And yes I know it is possible to use themes, ImageButtons, ColorBrushes and so on. And now the real problem is: I can't really see which colors fit together and make a good design. Are there any techniques, books, other resources that help to improve to get a feeling for good designs, color combinations, UI element choose?


title: How to read thousands lines of code without any documentation?

text: Previously I was searching for a good TimeLine control for a WPF project. I found an answer in Here which direct me to this CodePlex project. Now I want to change code to feed my culture needs. But there are some mismatches! My question is: **How you interact with such thousands lines of code?** EDIT: Any shortcut will be great!


title: How to start a new major version of my application, but still keep the old version 'alive'

text: I have two applications, called A and B. The current version of these applciations are 7.x (some customers run 7.1, others run 7.2, ...). Both applications use a same common framework (let's call this C), like this:               +---+ +---+     | A | | B |     +---------+     |    C    |     +---------+      Because of some important new customers, I want to have the functionality of A and B in one big application. Merging A and B into one application is not possible, so I am now trying to integrate the functionality of A into B. So far so good, but I starting to encounter some problems. First of all, customers that only use the base functionality of B are not interested in all the new functionality of A that is added (and which causes additional overhead for them). They just want to upgrade their version B with support for new Windows versions, ... and maybe also want all the nice functionality that is added to C (the common framework) as well. Second, customers that are currently using application A, don't want to directly move to application B, although the combined functionality of A+B would help them in the long term. For easy upgrades, they want to stick with A, and even see some improvements in C. Third, all of the developments I'm doing in B might have an impact on the common layer C. E.g. in order to improve performance of a module in B, I have to refactor a module in C, but since C is also used in A, I need to do much more work. Additionally, A is an older, less-structured application, and every change in C might make A more unstable. Question is how to proceed? I am currently thinking on splitting B in a 7.x release (I could still do some minor developments here and release 7.3, 7.4 in the coming years if needed), and an 8.x release (which would contain all the new functionality). To solve the problem of the common layer, I could also split C into an old C (7.x) and a new C (8.x). This gives the following result:               +-------+ +-------+  +-------+     | A 7.x | | B 7.x |  | B 8.x |     +-----------------+  +-------+     |      C 7.x      |  | C 8.x |     +-----------------+  +-------+      Application A would not evolve anymore and would stick to the 7.x version of the common layer C. Splitting C means that all developments in C will either not be seen in the old A and B (which would still be release 7.x), or if they must be done in release 7.x of A and B, would require doing the developments in both releases. An alternative could be to split B into B 7.x and B 8.x, but this would limit the refactoring possibilities in C, and actually only solves the first two problems. Does anybody have any experience with such a kind of major release change? Any other ideas?


title: When is code "legacy"?

text: We've all done it, we've labelled some code (often stuff we've inherited) as "legacy"? But it's still used in the production systems - so is it really legacy? And what makes it legacy? Should we shy away from this unwarranted labelling of perfectly functioning code; where the labelling is a pure convinience which allows us to push through new stuff and keep upper management nice and happy? * * * ### Summary of answers Looking through the answers I see four general themes. Here is as I see the breakdown:   1. Any code that has been delivered: 6   2. Dead systems: 2.5   3. No unit tests: 2   4. Developers are not around: 1.5


title: What's the best way to learn code if you are just starting out?

text: I'm just starting out with some articles and tutorials. I am looking for some guidance on which languages to start with and what is the best way to go about learning code, books, tutorials, classes. Which tutorials or books are best? Is it possible to learn this stuff online? If so how? Thanks for any help!


title: Why would I use code contracts

text: I recently stumbled upon Microsoft's framework for code contracts. I read a bit of documentation and found myself constantly asking: "Why would I ever want to do this, as it does not and often cannot perform a static analysis." Now, I have a kind of defensive programming style already, with guarding exceptions like this:               if(var == null) { throw new NullArgumentException(); }      I'm also using NullObject Pattern alot and have rarely any problems. Add Unit Tests to it and you're all set up. I have never used asserts and never missed them. Quite the contrary. I really hate code that has lots of meaningless asserts in it, which is just noise to me and distracts me from what I really want to see. Code contracts, at least the Microsoft way are much the same - and even worse. They add lots of noise and complexity to the code. In 99% an exception will be thrown anyway - so I don't care whether it's from the assert/contract or the actual problem. Just very, very few cases remain in which the program states really becomes corrupted. So frankly, what is the benefit of using code contracts? Is there any at all? If you already use unit tests and code defensively I feel that introducing contracts is just not worth the cost and puts noise in your code that a maintainer will curse when he's updating that method, much like I do when I cannot see what the code is doing due to useless asserts. I have yet to see a good reason to pay that price.


title: When should development stop and QA begin?

text: We write a complete functional specification for our development team of two. We do not have professional testers however we have drafted in the help of our available helpdesk personnel to perform 'QA testing'. We have had problems in the past where complete chunks of functionality do not work, or the code is delivered is simply not according to the spec. My questions are: at what stage should developers stop coding at hand over to the QA team? Is it too much to ask the developers to review their code against the spec before handing over to the QA team?


title: Licensing code under GPL: are revisions prior to adding GPL license still GPLed?

text: Suppose I have an already existing codebase which does not have any license headers in any of the source files, nor does it have `COPYING` file. So when I add all the neccessary GPL "cruft" to, say, revision 1000, will all previous revisions be GPLed as well or do I need to rewrite my repository history to include GPL license from the revision 0?


title: Clever way to license/obfuscate web applications until the client has paid for it

text: I am doing contract work for various clients and I was wondering how best to go about safeguarding myself against non-payment. The projects will be ASP.NET web applications, most likely intranet-based. I don't have any more details than that. I imagine that the client will want to run and test the applications from their side before making any payment. Is there any way I can "package" the application so that they can't access the source code? Is there an easy way I can make the application break after a certain number of days unless it is "unlocked" by me?


title: How far do you trust automerge?

text: Suppose you're getting the latest version of a file from source control and a conflict occurs. There are four possible types of changes in the conflict:   1. Yours   2. Theirs   3. Both   4. Conflicting Naturally, in cases 3 and 4 you'd want to review the changes manually (in the latter case you even have to resolve it). Regarding cases 1 and 2 I'm not sure, but I'm thinking only changes of type 2 (Theirs) should prompt manual inspection. The reason being, you know what you changed, as opposed to "their" changes which may break your changes. So I'm thinking one could skip reviewing his own changes (case 1), and manually review / resolve the other changes (cases 2-4). Other developers suggested more extreme approaches - such as only reviewing conflicting (or "both") changes and trusting automerge for the rest. The other extreme is reviewing all the changes every time. Of course, other parameters may factor in. For example, if you only made a single correction to a file, and there are 200 changes made by others, then provided you can be reasonably sure that your change is unrelated (say it's an SQL file and you wrote a new separate stored procedure), perhaps you can skip reviewing the other changes. I am torn between the dangers of not inspecting changes and the time and energy that could be saved by trusting the automatic merge. Supposedly, you have compilation and unit/component/e2e tests that will expose bad merges.


title: Java: How to make local fields & parameters final without having a 'final' keyword on each declaration

text: By default, I want all my local variables and method parameters to be final. Unfortunately, the Java language designers chose a different default: variables&parameters are by default non-final, and final variables&parameters need to be declared with the `final` keyword. So I need to add lots of finals. (And obviously I don't do this manually, but have my IDE add them for me.) So I end up with source code where every default case is marked, whereas exceptions to my preferred default are barely visible. For readability, I would like it to be the other way round, i.e. only non-final local variables and parameters should be marked/highlighted/annotated/... Is this possible? I'm open to solutions that integrate at different levels, e.g. folding within the editor, style checkers, build steps, etc...


title: How to make security usable in a web application?

text: I'm in the planning stages of developing a web application that I want to make as secure as possible. I'm pretty clear about how to do that from a technical point of view, but there is one massive potential security hole: I want the site to have users. As anyone who has ever been a user knows, users forget usernames, forget passwords, sometimes forget that they even had an account with your site. Users respond to phishing emails and give away their credentials. If you do anything that they find too complicated they won't use your site, it has to be simple and all happen in as few clicks as possible, but we have to balance that out by making it as hard as possible for users to accidentally give away their credentials and to keep access to the service as secure as possible. What I'm particularly interested in are strategies that go beyond the standard username and password combination and ways of recovering or resetting passwords that make things easy for users but hard for anyone trying to steal their account. I know a lot of sites provide an extra user-set security question, but because I don't trust users not to create a stupid question like "what is 1+1" I don't see how this can guarantee security. Are there strategies that could be useable to the most clueless user but challenging to a determined and targetted attack aiming to break into their account? If not what are the closest things we could get? As a user what are the best/worst sites for this you have encountered and why?


title: Shortest distance between two points (to solve a problem)

text: I have recently started work at a company using their proprietary CMS. Unfortunately, there is virtually no documentation for the application, and the source comments are also quite sparse. Normally, given a particular task - I work down through the choices below, going to the next step if I can't find a solution 1: Consult the documentation (n/a) on how to do task X (i.e. create a page) 2: Read the source code - output variables - generally halt search after digging 4 or 5 steps into class/method chain 3: Ask the existing development team how they might achieve X in their application 4: Read the (uncommented) source again - go "rabbit hunting" - pursue each chain to completion 5: Make tea On the one hand, my employer is looking for technical capability. On the other, they are looking for speed of execution. They are averse to me asking the other developer for assistance (despite the lack of documentation), yet seem surprised when I've then had to spend an hour (or two) rabbit hunting through their application for the origin of variable or method X. Bear in mind that I've been employed as an intermediate developer. So, I wanted to get an outside perspective, is my process of elimination unreasonable? I can't imagine anyone writing a Zend Framework app without the documentation (and sometimes they struggle despite that...) - so working on some proprietary app with none is proving somewhat tricky.


title: How to restrict user submitted CSS within <div>

text: We are having rich text editor in which we can insert html. if any input contains `<style>` tag then the css is applied to entire window. is it possible to restrict that CSS to be applied within `<div>` not entire window?


title: What is the etymology of the phrase "Source Code"?

text: With the movie "Source Code" just coming out today, I have had to explain the meaning of the phrase to non-techies. Then I was asked _why_ source code is called source code and couldn't really answer. I know some of my coworkers seem to prefer referring to source code as "program text", or "program files" instead. "Program Text" makes much more sense to me than "source code", but most people seem to use the phrase "source code". Does anyone know the origins and etymology of the phrase "source code"?


title: Sorting Algorithm : output

text: I faced this problem on a website and I quite can't understand the output, please help me understand it :- Bogosort, is a dumb algorithm which shuffles the sequence randomly until it is sorted. But here we have tweaked it a little, so that if after the last shuffle several first elements end up in the right places we will fix them and don't shuffle those elements furthermore. We will do the same for the last elements if they are in the right places. For example, if the initial sequence is (3, 5, 1, 6, 4, 2) and after one shuffle we get (1, 2, 5, 4, 3, 6) we will keep 1, 2 and 6 and proceed with sorting (5, 4, 3) using the same algorithm. Calculate the expected amount of shuffles for the improved algorithm to sort the sequence of the first n natural numbers given that no elements are in the right places initially. Input:               2     6     10      Output:               2     1826/189     877318/35343      For each test case output the expected amount of shuffles needed for the improved algorithm to sort the sequence of first n natural numbers in the form of irreducible fractions. I just can't understand the output.


title: Which is the more testable C function implementation?

text: I write code in C. I have been striving to write more testable code but I am a little confused on deciding between writing pure functions that are really good for testing but require smaller functions and hurt readability in my opinion and writing functions that do modify some internal state. For example (all state variables are declared static and hence are "private" to my module): Which of this is more testable in your opinion:               int outer_API_bar()     {        // Modify internal state        internal_foo()     }          int internal_foo()     {       // Do stuff            if (internal_state_variable)       {          // Do some more stuff          internal_state_variable = false;       }     }      OR               int outer_API_bar()     {        // Modify internal state             internal_foo(internal_state_variable)             // This could be another function if repeated many        // times in the module        if (internal_state_variable)        {           internal_state_variable = false;        }     }          int internal_foo(bool arg)     {       // Do stuff            if (arg)       {          // Do some more stuff       }     }      Although second implementation is more testable wrt to internal_foo as it has no sideeffects but it makes bar uglier and requires smaller functions that make it hard for the reader to even follow small snippets as he has to constantly shift attention to different functions. Which one do you think is better ? Compare this to writing OOPS code, the private functions most of the time use internal state and are not pure. Testing is done by setting up internal state on a mock object instance and testing the private function. I am getting a little confused on whether to use or whether to pass in internal state to private functions for the sake of "testability"


title: Is it a bad practice to cite URLs as references in comments?

text: Sometimes I think it's useful to cite a webpage ( _e.g._ Stack Overflow questions) to justify and explain a piece of code. Is this considered bad practice?


title: Rule of thumb for field sizes

text: What VARCHAR sizes should be used for first and last names, phone numbers (preferably international), email adresses, urls, dictionary words and file names? Edit: Zapped the introductory phrase to form a concrete question.


title: How to gain personal practice at heavyweight development methodologies?

text: I'm in a new job where the project needs to meet strict quality standards, be heavily documented, managed in great detail, UML diagrams, and all those things that are opposite of "cowboy coding" where most of my past work experience has been. Think of the way large-scale aerospace or medical device software is developed. I'm glad to leave the chaos of cowboy coding and am curious to see how well heavyweight engineering methods go. But how can one rapidly gain experience with the heavy methods? Besides simply being in the job for some number of months/years, that is. With a mere language, or new API, one can hack up a toy test program, read, deliberately make mistakes to see what happens, etc. Like becoming good at bicycle riding or playing a musical instrument, practice is essential. It is easy to pick up a flute and spend half an hour every day; no need to join an orchestra or be a full-time flute consultant. But how to practice software engineering activities that are large, complex, involve teams, and much of which is all about communicating and planning, and avoiding miscommunications and exceeding schedule and budget limits? This doesn't seem possible to do solo. Is there a way a small number of people could simulate engineering a whole big project on a small scale in a short time (one day)?


title: Are software developers who ignore quality/standards better for the company?

text: Do software developers who choose not to put code optimization, standards and best practices as top priority, create more useful code than those developers who choose to worry about optimization, implementation of coding standards and practices above completing tasks on time? How do these differing methologies compare when it comes to individual performance reviews? How do these styles compare in peer reviews? What is the best way to influence your team to implement more best practices during the SDLC?


title: How to automate a tasks system in a CMS software

text: I'm currently developing v2.0 of my personal cms. However, I'm stuck. I strongly feel that my old solution for "tasks" is not very dynamic and must be revisited. Currently I'm looking the whole concept of how to dynamically add tasks and run them. **What I mean by task system**   Like always in cms software, there are a lot of content, such as images, dynamic files, database entries, etc. I created my own task system aka. The Parser (sounds evil right?) It is made of two files, one parser-classes and other the triggers with the `$parser = new ParserClasses();` (I hope you understand what I mean.) Some of the features the parser does:   * First turn off the site (after the parser is done, turn it back on)   * Checks for active files (files that don't have parent mysql entry, will be deleted)   * Clears out old cache   * Generates new static cache   * Deals with languages and translation related cache   * and other tasks related to cms management and maintenance **Why do I want to make it more automatic**   Basically all plugins and some themes (add-ons in general,) use this task system. But the problem is that it's not very dynamical, because all functions sit in one huge class. This means that the add-on cannot be installed without opening your php editor. **How I was planning to do it**   First I would create my own _task language_ , with preset functions to handle files, cache, etc. (very broad example: `GenerateFreshCache('pages')`). Now, storing it is the issue.. My ideas are:   1. To create tasks-table in mysql database. Then add tasks there, with my _task language_. Later `while()` them from the database and `eval()`. _(This is a good way, because I can add scheduled times and similar in function, for CRON jobs. Or even categorize the tasks.)_   2. Add .php files to some folder, where they get loaded. They will probably use the same _task language_ , but don't need to be `eval()`'ed. _(I'm scared that this would slow down the parser, because so many files are getting included.)_ However, I'm not sure about those ideas and I'm hoping someone has already come across this functionality and can give me pointers. All crazy ideas and concepts are welcome, thanks in advance. **Conclusion**   Thanks to everyone who replied. I picked the answer, that helped me the most and not "ohh, too much work, use framework". My task systems core is done and working. Took 2-3 days and currently ~600 lines of code and two classes (outer and inner core.) I finally ended up with two mysql tables, one with tasks (task db) and another with combos (multiple tasks combined together for easier run.) Also, added some features so it would be safe to run via ajax (cant really talk about that, top secret^^). There are might be too many loops, handling the tasks parsing, however this makes adding new tasks very very simple.. Just add it to tasks DB and add the task to cron-list-automatic-run- list or run it straight up via the admin panel.


title: What are the benefits of having a remote database for your command line utility

text: I'm current working on a command line app that will grab resources online for you when you're setting up a new project locally. Right now all the urls for the resources I need are hardcoded into the application and adding new targets require updating the software. What are the benefits of hosting a database remotely that the application would query to get new packages. Sort of like `npm` and any other generic package manager out there. Are there any best practises in setting something like this up?


title: Can regexp be used to check for palindromes?

text: Can regexp pattern matching be used to check for palindromes within a given text in Java? My intuition is that in order to check for palindromes, we may need to remember the character that was parsed, which cannot be done using regexp. Is that correct?


title: using / linking to MS-PL licensed code from (A)GPLv3

text: I have some trouble understanding MSPL (Microsoft Permissive License) conditions regarding linking to / using a library under MSPL from a project of mine which I want to license on either AGPLv3 or pure GPLv3 (the Affero-part should not play a major role in my question as far as i can see - but please correct me if I am wrong). What I know for sure is that MSPL is incompatible with all versions of the GPL. But is there some kind of linking exception that allows using it from within GPL covered code? Background: I want to use ASP.NET MVC 2 as well as Managed Extensibility Framework (both licensed under MSPL) in my web application project as frameworks. Thus, I will be referencing to them. But I want my web application to be licensed under GPLv3. I DO NOT want to modify or distribute ASP.NET MVC2 or MEF neither in source nor binary form along with my web application. I really guess this is possible, but I can't find any passage in the MSPL which explicitly allows me to do so. If anybody has a link with more information on that, greatly appreciated! What I am also pretty sure about: if ASP.NET MVC2 or MEF would be licensed under GPLv2 (and v2 only) I could definitely NOT use GPLv3 as my projects license. Even though I would not ship source or binary of ASP.NET or MEF then, my project would still be considered a derived work. EDIT: I should mention that I do not want to use original .NET4 from Microsoft but Mono. Mono ships with ASP.NET MVC2 and MEF, both licensed under MSPL.


title: Should temporary code be put under version control and how?

text: Here are some examples of temporary/local code. It is needed in order to work with the codebase, but would be harmful to be part of it:   1. Project files. Paths may need to be edited in order to reflect the layout on the current PC.   2. Makefiles. For example optimization may need to be turned off during debugging, but not for the CI server.   3. Dirty ugly hacks. For example `return 7` in the middle of a function, in order to test something, depending on the function, and suspected to break at value of 7. Or 7 is the code of the not yet implemented button, that I am implementing and need to test throughout the life of my branch.  I have tried keeping those in a git commit that I always rebase to the top before pushing to the repo and then push `HEAD~`. This is quite inconvenient and doesn't work with svn. Stashing scares me even more - "did I remember to pop after pushing??". Keeping the code out of version control introduces unpleasant noise everytime a commit is being assembled plus it might accidentally get introduced into a commit some friday evening. What would be a sane solution for such throw-away code?


title: Why does Aptana need Git installed on Windows?

text: Why does Aptana Studio need Git installed on Windows?


title: Augmenting functionality of subclasses without code duplication in C++

text: I have to add common functionality to some classes that share the same superclass, preferably without bloating the superclass. The simplified inheritance chain looks like this:               Element -> HTMLElement -> HTMLAnchorElement     Element -> SVGElement -> SVGAlement      The default `doSomething()` method on `Element` is no-op by default, but there are some subclasses that need an actual implementation that requires some extra overridden methods and instance members. I cannot put a full implementation of `doSomething()` in `Element` because 1) it is only relevant for some of the subclasses, 2) its implementation has a performance impact and 3) it depends on a method that could be overridden by a class in the inheritance chain between the superclass and a subclass, e.g. `SVGElement` in my example. Especially because of the third point, I wanted to solve the problem using a template class, as follows (it is a kind of decorator for classes):               struct Element {         virtual void doSomething() {}     };          // T should be an instance of Element     template<class T>     struct AugmentedElement : public T {         // doSomething is expensive and uses T         virtual void doSomething() override {}         // Used by doSomething         virtual bool shouldDoSomething() = 0;     };          class SVGElement : public Element { /* ... */ };     class SVGAElement : public AugmentedElement<SVGElement> {         // some non-trivial check         bool shouldDoSomething() { /* ... */ return true; }     };     // Similarly for HTMLAElement and others      I looked around (in the existing (huge) codebase and on the internet), but didn't find any similar code snippets, let alone an evaluation of the effectiveness and pitfalls of this approach. Is my design the right way to go, or is there a better way to add common functionality to some subclasses of a given superclass?


title: How can I make sense of the word "Functor" from a semantic standpoint?

text: When facing new programming jargon words, I first try to reason about them from an semantic and etymological standpoint when possible (that is, when they aren't obscure acronyms). For instance, you can get the beginning of a hint of what things like Polymorphism or even Monad are about with the help of a little Greek/Latin. At the very least, once you've learned the concept, the word itself appears to go along with it well. I guess that's part of why we name things names, to make mental representations and associations more fluent. I found Functor to be a tougher nut to crack. Not so much the C++ meaning -- an object that acts ( _-or_ ) as a function ( _funct-_ ), but the various functional meanings (in ML, Haskell) definitely left me puzzled. From the (mathematics) Functor Wikipedia article, it seems the word was borrowed from linguistics. I think I get what a "function word" or "functor" means in that context - a word that "makes function" as opposed to a word that "makes sense". But I can't really relate that to the notion of Functor in category theory, let alone functional programming. I imagined a _Functor_ to be something that creates functions, or behaves like a function, or short for "functional constructor", but none of those seems to fit... How do experienced functional programmers reason about this ? Do they just need any label to put in front of a concept and be fine with it ? Generally speaking, isn't it partly why advanced functional programming is hard to grasp for mere mortals compared to, say, OO -- very abstract in that you can't relate it to anything familiar ? Note that I don't need a definition of Functor, only an explanation that would allow me to relate it to something more tangible, if there is any.


title: Is there a way to use RAII techniques in COM?

text: I am caught between two conceptual models of how to construct objects, and am having trouble working out what standard I want to adopt. I prefer to program in .NET and often try to use RAII and read-only properties to make immutable objects with their data passed in through constructor parameters. This has been a major advance compared to the VB6 days when we had to simulate constructors and by convention call "Init" or "Factory.Create" to get objects into a good state. However, I am often making COM-callable wrappers to let me call functions via Automation from other applications. As you probably know, COM wants objects to have a constructor without any parameters. This is a dissonance with the RAII/immutable scheme that I have been using with such success in the .NET world. I remember older object models like ADO where you would usually instantiate an object, set properties like ConnectionString, then call Open. The object could be immutable not via a ReadOnly declaration, but via throwing an "Can't change while open" exception on the property setter. Is this the best pattern to use for COM? Am I missing a better way to skin this cat? Since RAII came out of the C++ community, how do they handle COM being based on a different initialization scheme?


title: Estimation of Effort and Schedule for a project with almost no familiar elements

text: To the best of my understanding the schedule for the project is derived using the effort estimates for the individual tasks (in person hours), and the number of relevant resources used for the particular task. As discussed in this question, we are starting a project using a new platform, featuring a brand new API and feature-set. How do we estimate the schedule of the tasks involved in the project, knowing only the top level task breakdown? Also, if some efforts are allocated to the tasks, the estimations would have a wide probability distribution. What is the best way to communicate the same to management?


title: Factory method vs Factory design pattern

text: I know about Simple Factory Idiom, Factory Method and Abstract Factory Design patterns. But I have two situations that I'm not sure how to call (PHP code example) :               class User {       public static function LoadUserById($id) {         $objUser = new User();         //load details from DB         return $objUser;       }     }          class UserFactory {        public function Create($id) {         $objUser = new User();         //load details from DB         return $objUser;        }     }      What are these two situations? Simple Factories (programming idiom) or are they called something else? Is a good practice to name the class UserFactory? Isn't this something that might get confused with the A factory design pattern? Should I use different name for it like UserFinder? When I think of the Factory Design Pattern I always think of examples where there are families of components derived from a parent class but it is clearly not the case here.


title: When would one give up backward compatibility in favor of new and improved interface implementation?

text: I have been working at the same software company for more than ten years. As a result, I have implemented a large code base using various object-oriented programming languages. I was a beginner programmer when I first started my career and I didn't know much about good interface and class design principles. I would like to think that my design skills have improved over time, but I now face more and more difficulties in improving my earlier code because of backward compatibility concerns. My code is used by a large number of customers as part of the products that my company sells. My question is: when should one stop trying to keep backward compatibility of old interfaces and bite the bullet in favor of implementing a brand new design? I think there comes a point where keeping backward compatibility becomes such a big burden that useful changes to interfaces become impossible. Has anyone experienced similar concerns, who can provide some feedback?


title: Incremental and partial drawing of the large graphs

text: I have the following problem: I'm developing a software for data visualization where I get a graph structure and represent it in 3D space. So far, I've been using force-based algorithms to draw graphs and it worked well, until I got requirement that my software should represent very big number of vertices and edges (few millions). It would be very impractical to hold all those in memory, so I'm looking for an algorithm that will enable me to stream small portions of graph as I "walk" through the space. However, the main problem is in showing and dynamically repositioning of vertices, since I don't have already predefined positions, and I must calculate them. Can you point me to some algorithms for incremental drawing and streaming of graph? Thanks in advance!


title: programming PID loops in C

text: I'm an electrical engineer that was kind of thrust into the digital world and learning as I go. I'm programming a TI processor to do a PID (proportional- integral-derivative) loop, illustrated by this diagram: ![PID loop image from Wikipedia](http://i.stack.imgur.com/g7Rsk.png) I'll also describe it: Negative feedback op-amp, with non-inverting terminal grounded. Input through negative terminal. The feedback loop is an RE series circuit in parallel with a resistor and all that in parallel with a cap. Anyone have any idea how to convert this circuit to C code? I'm a bit out of my element on this and could use the help.


title: Anonymous software license

text: I am aware of some of the problems of the concept of "releasing a work to the public domain" (as mentioned here and here; I haven't listened to this specific discussion yet). IANAL, but the main problems seem to be as follows:   1. Releasing to the public domain doesn't exist in many jurisdictions; rather, a work becomes public domain after copyright _expires_.   2. Some moral rights are inalienable due to (certain ratifications of) article 6bis of the Berne Convention. However, aren't you still allowed to publish a work anonymously? If you anonymously publish a work, in such a way that authorship can't be proven or even distinguished, wouldn't that effectively "unlicense" your code? I would think so: since then any claim of authorship can't be validated, the rights implied by authorship can't be enforced, not even by the original author. If so, I'd really like to know which permissive license (ISC/MIT/BSD-style) would be fit for such publications. (Especially when they've managed to get rid of the lengthy `THIS SOFTWARE IS PROVIDED IN "SCREAMING CAPS"`-style liability waiver.) If no such license exists yet, how would one modify an existing license to be suitable for an anonymous publication?


title: Why is it so hard to get people to pay for software?

text: Where I come from software is considered something you can get for free (same goes for movies, etc.) The willingness not to pay for software is quite strong. It is putting me off, that people would rather go through hoops and risk legal issues than to pay a small amount of money for a piece of software. This attitude is somehow embedded in the society. I'm just trying to understand the situation. What do you think is causing this? Why won't some people pay for software even if it's cheap and they use it every day?


title: How to write less code

text: A quality what I would like to develop is to write more concise code. With writing more concise, at least in my opinion, the opportunity to add bugs to the code is smaller. It is easier to read the code for other. My question is if it is something that just comes with experience or is it something you can do explicitly for developing that quality?