Writing my own voice recognition code

**Problem Description** I am wanting to use voice recognition as part of a hardware project, which I would like to be completely self containing (I'm using small low power, low speed devices such as Arduino's and Raspberry Pi's, Kinects etc, no running traditional computer with an OS is involved. So a closed / self containing project). Voice recognition can be very complicated depending on the level of sophistication you desire. I have what I believe a comparatively simple set of requirements. I only want to recognise my own voice, and I have a small dictionary of 20 or so words I'd like to recognise. Thus I don't require complex speech-to-text and voice recognition libraries or any of the excellent 3rd party software I find via Internet search engines (there is no shortage of these!). I believe my requirements are "simple enough" (within reason) that I can code my own solution. **I am wondering if anyone has written their own process like this, and is my method is massively flawed? Is there a better way to do this without requiring a high level of mathematics or having to write a complex algorithm?** That is the solution I have tried to think up below. **Solution Description** I will be writing this in C but I wish to discuss a language agnostic process, focussing on the process its self. So lets ignore that if we can. **1 .** I will pre-record my dictionary of words to match those being spoken. We can imagine I have 20 recordings of my 20 different words, or perhaps short phrases or sentences of two or three words. I believe this makes the process of comparing two recording files easier than actually converting the audio to text and comparing two strings. **2 .** A microphone is connected to my hardware device running my code. [1]. The code is continuously taking fixed length samples, say 10msec in length for example, and storing 10 consecutive samples for example, in a circular logging style. [2]. (I'm inventing these figures off the top of my head so they are only examples to describe the process). _[1] This would likely be connected through a band-pass filter and op-amp, as would the dictionary recordings be made, to keep the stored and collected audio samples smaller._ _[2] I'm not sure exactly how I will take a sample, I need to work out a method though were I produce a numerical figure (integer/float/double) that represents the audio of a 10msec sample (perhaps a CRC value or MD5 sum etc of the audio sample), or a stream of figures (a stream of audio readings of frequencies perhaps). Ultimately a "sample" will be a numerical figure or figures. This part is going to be much more hardware involved so not really for discussion here._ **3 .** The code looks at it's stored 10 consecutive samples and looks for a volume increase to indicate a word or phrase is being said (a break from silence) and then increases is consecutive sample collecting to say 500 samples for example. That would mean it captures 5 seconds of audio in 10 msec samples. It is these samples or "slices" that are compared between the stored sound and captured sound. If a high enough percentage of samples captured matched the equivalent stored ones, the code assumes its the same word.               The start of a store recording of the world "hello" for example,     stored words are split into 10 msec samples also          Stored Sample No           | 1| 2| 3| 4| 5| 6| 7|  8|     Stored Sample Value        |27|38|41|16|59|77|200|78|          Incoming audio (me saying "hello") with some "blank" samples     at the start to symbolise silence          Incoming Sample No         | 1| 2| 3| 4| 5| 6| 7| 8| 9|10| 11|12|     Incoming Sample Value      |  |  |  |20|27|38|46|16|59|77|200|78|      **4 .** Once the code has collected a full sample stream, it then chops off the blanks samples at the start to produce the following audio recording. It could also move the sample set backwards and forwards a few places to better align with the stored sample. This produces a sample set like the below:               Stored Sample No           | 1| 2| 3| 4| 5| 6|  7| 8|     Stored Sample Value        |27|38|41|16|59|77|200|78|          Incoming Sample No      |-1| 1| 2| 3| 4| 5| 6|  7| 8|     Incoming Sample Value   |20|27|38|46|16|59|81|201|78|      **5 .** I believe that by having a percentage value for how close each sample must be, so sample 7 differs by a value of 1 which is less than %1, and a percentage value for the total number of samples which must be within their sample matching percentage, the code has an easily tunable level of accuracy. I have never done anything like this with audio before, it could be a lot of work. This is why I am asking this question, if you perhaps already know the answer to this question to be obvious (what ever that answer may be). I am hoping this won't be a computationally massive tasks as some of the hardware I will be using will be low sec stuff. In the hundreds of Megahertz (Maybe 1Ghz using an over-clocked Rasp Pi). So this is a rather crude way to match audio samples using lower computational power. I'm not aiming for instant results, but less than 30 seconds for a decent proof of concept. **PS** I don't have the rep to tag this with a new tag like "audio", "audio recognition", "voice", "voice recognition" etc.


Handling or preventing conflicts in a multi-user system

I have a web application that is accessed by multiple users from different locations worldwide. Let's say I have an "edit" form for a specific document and two (or more) users are editing the document at the same time. I know that both of the users can edit the document and submit it, but user1 will not see that user2 made changes to the document and might submit an older version of it. I was thinking about adding some kind of a lock, but then, if user1 only opened the document for edit, but never changed anything (and kept it open) user2 will never be able to edit it. Therefore, I was thinking to add a Timeout for the editor, but then user1 might time out before he finished doing his changes to the document (let's say, went out for launch). The question is, how would one prevent the document from being edited from one user while the other changes it? Note: if this question does not belong here, please explain why and where could I ask such a question.


Status update & news feed database design / architecture

Imagine a application similar to Facebook, where you have status updates and a news feed. The names and profile pictures can be changed. There are also several different types of updates requiring a different layout template for each type. I hate my implementation and would like some feedback on how to improve it. When I store the status update in the database, I basically store the HTML template in the database with some of the update specific information in it as well. Since the profile pic and poster name can change, I'm keeping placeholders in the HTML stored in the database like '{USER_PROFILE_PIC}' and replacing that with the most current value when the record is pulled & displayed. I hate doing it this way because if we want to do a design change down the road, we are stuck with this HTML in the database. I'm doing this all in SQL Server. I'm open to other databases if needed, I just am looking for a good way to pull dynamic status updates from a database and display them with up to the moment info. TIA


Feature boundaries in functional programming

I very much enjoy the functional programming paradigm, but I am still not sure how to go about designing a small/medium project with it. When using OO, I have a set of labelled entities (classes) with clearly defined boundaries. I can reason about stuff like:   * what is this class doing?   * should I put this code _inside_ or _outside_ a class?   * should I split this class in two?   * how would a client like to use this class? So one big benefit of classes is that they provide **boundaries** for a piece of functionality. I find that this helps a lot when designing an application. In functional programming, everything seems to be about composing and abstracting functions and data structures. Type classes in haskell are mainly there to offer polymorphism. Same for prototypes in clojure. When designing an application written in a functional style, what is a good "unit of feature" one can define, label, and reason about?


Is There Any Benefit To Participating On Sites Like TopCoder And Or GoogleCode?

Apart from the obvious reasons, like financial, employment and recognition, what are the practical/real benefits to using programming competition sites? It seems quite algorithmic and maths heavy, but how does that map to something practical, in your everyday programming?


Is it possible to represent mutation of object-graph efficiently with immutable states?

I am practicing using of immutable object in C++. My personal goal is representing generic object graph (in heap) with sequence of immutable graphs. Building the multi-version graph itself isn't that much hard. The problem is performance. Brute-force versioning needs full copy of graph, and this was not acceptable. I tried to share unchanged nodes. But in this case, I got a new problem; references. Reference to other object must be updated in whole graph. This needs visiting all nodes for each time I derive a new graph version. And this mutates the nodes with references, so they also should be derived (by copying). Performance won't be better much than brute-force copying. As far as I can imagine, there's no real efficient way to represent mutation of object graph with immutable states. So I am asking for some idea on this. Is it possible to represent mutation of object graph efficiently with immutable state?


Reverse engineering: what is it really good for?

I have some innocent/beginner questions:   * What is reverse engineering good for?   * As a programmer, should I learn the art of reverse engineering?   * What are the benefits to a programmer who is experienced with it?


DAO Design with Child Objects

If I have objects that represent a hierarchy of relationships. For example: Person     Spouse       Spouse Contact       Spouse Address     Person Contact     Person Address Each of the items listed has a database table related to an object. Each object/table has an ID, Parent ID (Spouse ID for Spouse Address records) and Base ID (Person in the example). Given that hierarchies can be arbitrarily deep and wide, how would you design the objects and data access layer?


Solution with multiple projects and (GitHub) single issue tracker and repository

I have a Visual Studio solution with multiple projects:   * `Acme.Core`   * `Acme.Core.Tests`   * `Acme.UI.MvcSite1`   * `Acme.UI.MvcSite2`   * `Acme.UI.WinformsApp1`   * `Acme.UI.WinformsApp2`   * ... The entire solution is checked-in in a single GitHub (private) repo. `Acme.Core` contains our business logic and all `UI` projects are deployables. UI projects have different requirements and features, but some of them are implemented in more than one project. All issues are opened in a single issue tracker and classified using labels (`[MvcSite1]`, `[WinformsApp1]`, etc) but I'm thinking it's starting to get messy. Is it ok to use a single repository and issue tracker to track multiple projects in one solution?


How are effort estimations and duration estimations distinct? At present my understanding is that effort is related to the amount of work required for one person to complete a task, and duration is the total amount of time required to complete the task, irrespective of resources. Is this the commonly accepted definition?


How do the Application and Database Interface Layers interact at their boundary?

I was watching one of Uncle Bob's videos and he brought up the Database Interface Layer. He had this diagram showing it: ![High level view](http://i.stack.imgur.com/TKb0b.png) These arrows show that the DB Interface Layer is aware of and calls the Application and Database layer, but not vice versa. The DB Interface Layer has "data records" in it. These are "classes" that have the name of the table and the fields of the columns. These are what I usually call DTOs. But these data records have all public fields and no/few methods. The DB Interface layer is responsible for grabbing the data from the database, populating the "data records" and implementing an interface in the Application Layer like so: ![Picture of the boundry](http://i.stack.imgur.com/PxFzN.png) I'm a little confused because I've never heard about this separation before. Every project I've worked on uses the DTOs in the view which is apparently wrong (at least according to Uncle Bob's video). Also, I've never worked on a project where the DB Interface Layer calls the Application Layer. It's always the Application layer asking the DB Interface Layer for information. For example, by using a DAO. But this is starting to make sense. Whenever I use hibernate I'm always pulling my hair out because I try to make the DTOs more OO and the library always fights me. So, I guess what I'm trying to ask is, what does the code look like on/at the boundary between the Application and the Database Interface Layer? For example, how does the Application get the implementation of the Order Gateway Implementation? Is the Order Gateway Implementation a DAO? I don't have a clear picture of how the POS can use the Order Gateway vs how/when the Order Gateway gets populated with data.


whole project of consuming web services with php

We are in the middle of a strange situation. We and a partner firm have to put up a web portal. They have a lot of functionality already done on their other portal and we are the managing firm on the project. But there are also some new development needed on their side which is designed by us. Strange thing is, we are going to do the GUI on the project and they will provide us some web services to gather data. They are using .NET and we will be using PHP for the frontend project. So what do you think that the best approach is to avoid communication and integration problems? For example   1. We provide them with just the view files and they do the rest all by themselves?   2. We develop a PHP project where we gather the required data using SOAP/REST web services?  Thanks in advance guys.


Is this a correct way to use nested classes to keep track of data?

I have some instruments. Each instrument should have a name (string) and description (string). Each instrument can have some setups, which these setups are each a series of commands(string[] or List). I want this class to be flexible so I can easily add or remove a whole instrument, or add or remove setups for any instrument that is existing in the class. At the end, I want to save this class in properties of my assembly so each time the program starts it can be loaded. I am also thinking about serializing it and save it on disk for moving to another copy of the software. So please let me know what you think about this approach and if you think this can be improved or even I should consider going with another way please let me know!               namespace MeasurementSuite     {         /// <summary>         /// Setups for all instruments         /// </summary>         public class Setups         {             /// <summary>             /// An instrument             /// </summary>             public class Instrument             {                 /// <summary>                 /// Name of the instrument                 /// </summary>                 public string Name { get; set; }                 /// <summary>                 /// Info about the instrument                 /// </summary>                 public string Info { get; set; }                 /// <summary>                 /// List of existing setups                 /// </summary>                 public List<Setup> SetupList { get; set; }                      /// <summary>                 /// Adds a setup to the instrument                 /// </summary>                 /// <param name="name"></param>                 /// <param name="commands"></param>                 private void AddSetup(string name, string[] commands)                 {                     this.SetupList.Add(new Setup(name, commands));                 }                      /// <summary>                 /// Removes a setup from the instrument                 /// </summary>                 /// <param name="name">Name of the setup</param>                 public void RemoveSetup(string name)                 {                     foreach (Setup setup in SetupList)                     {                         if (setup.Name == name)                         {                             SetupList.Remove(setup);                         }                     }                 }                     }                  /// <summary>             /// Setup for a instrument             /// </summary>             public class Setup             {                 /// <summary>                 /// Name of the setup                 /// </summary>                 public string Name { get; set; }                 /// <summary>                 /// Command sets for setup                 /// </summary>                 public string[] CommandSet { get; set; }                      /// <summary>                 /// Constructor                 /// </summary>                 /// <param name="name">Setup Name</param>                 /// <param name="commands">Setup Command sets</param>                 public Setup(string name, string[] commands)                 {                     this.Name = name;                     this.CommandSet = commands;                 }             }          }     }


Is it practical to abandon STL in C++ development?

I know in some areas (game industry, for example), STL is not recommended. So my question is: is it really a good practice not to use STL in some cases? If so, what's the biggest reasons of not using the modern C++'s STL?


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

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?


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

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.


Use TFS to track bugs from Production Support

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.


Binary Tree/Knowledge Base design C++

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.


JOIN vs. INNER JOIN and FULL OUTER JOIN

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,


Motivate developers to keep up with admin tasks

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?


How much logging should I do at production for SQLExcpetions?

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.


Why do people still say Java is slow?

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?


int* i; or int *i; or int * i;

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


How do you deal with intentionally bad code?

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"?


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

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


Constant Interface antipattern - PHP

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?


Web development for an otherwise widely experienced programmer?

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!


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

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?


Python - Is this a bad strategy pattern?

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?


if else empty curly braces

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


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

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.


How do I make an estimate for my first website?

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.


How detailed should public release notes be?

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


random generator not good enough?

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?


Standardized code documentation format, where is it?

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?.


Why fork a library for your own application?

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?


Parser combinator that looks like BNF

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?


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

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?


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

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?**


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

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?


When should I start the server side coding?

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?


What did Linus Torvalds mean by his quotation about portability?

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?


GPS accuracy with software

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?


Open source license that requires visible attribution in derivative works?

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?


What is the best way to handle dynamic content?

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.


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

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++?


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

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.


How to get experience in large scale databases?

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?


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

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?


Why is MaybeChannelBound callable?

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?


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

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.


FIFO lock with mutiple threads/processes

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?


Dependency Injection: Only for single-instance objects?

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?


Can *any* program task be expressed without state?

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.


Do some best practices depend on skill?

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?


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

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?


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

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.


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

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?


RequestContextHolder.currentRequestAttributes() and accessing HTTP Session

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.


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

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?


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

> # 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?


How useful are Lisp macros?

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?


How to prevent deep indentations?

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


Do I really need a disclaimer for free software?

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.


What's the current best practice for C multithreading?

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)


Rails + Heroku Architecture

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.


Testing on different operating systems

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?


Growing mobile developers inside a web development org

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." :-)


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

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.


Designing an API for service operations with closely related parameters

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?


Client auto-detect required server

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.


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

## 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.


Is mocking for unit testing appropriate in this scenario?

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 ?


Advice/guidelines for managing a distributed development team

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


Any best practices for a distributed agile team?

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?


how to reduce communication time in distributed teams

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!


How to choose a proper parser generator for PHP

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.).


How do you make your applications looking more sexy?

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?


How to read thousands lines of code without any documentation?

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!


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

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?


When is code "legacy"?

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


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

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!


Why would I use code contracts

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.


When should development stop and QA begin?

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?


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

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?


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

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?


How far do you trust automerge?

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.


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

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...


How to make security usable in a web application?

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?


Shortest distance between two points (to solve a problem)

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.


How to restrict user submitted CSS within <div>

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?


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

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"?


Sorting Algorithm : output

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.


Which is the more testable C function implementation?

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"


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

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?


Rule of thumb for field sizes

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.


How to gain personal practice at heavyweight development methodologies?

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)?


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

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?