Strategy for generating unique and secure identifiers for use in a "sometimes offline" web app

I have a web based project that allows users to work both online and offline and I'm looking for a way to generate unique ids for records on the client side. I'd like an approach that works while a user is offline (i.e. unable to talk to a server), is guaranteed to be unique, and is secure. By "secure", I'm specifically worried about clients submitting duplicate id's (maliciously or otherwise) and thereby wreaking havoc on data integrity. I've been doing some googling, hoping this was already a solved problem. I haven't found anything that's very definitive, especially in terms of approaches that are in use in production systems. I found some examples for systems where users will only access the data that they've created (e.g. a Todo list that's accessed on multiple devices, but only by the user who created it). Unfortunately, I need something a bit more sophisticated. I did find some really good ideas here, which are in line with how I was thinking things might work. Below is my proposed solution. ## Some Requirements   1. IDs should be globally unique (or at least unique within the system)   2. Generated on the client (i.e. via javascript in the browser)   3. Secure (as outlined above and otherwise)   4. Data can be viewed/edited by multiple users, including users who didn't author it   5. Doesn't cause significant performance issues for backend db's (such as MongoDB or CouchDB) ## Proposed Solution When users create an account, they would be given a uuid which was generated by the server and known to be unique within the system. This id must NOT be the same as the users authentication token. Let's call this id the users "id token". When a user creates a new record, they generate a new uuid in javascript (generated using window.crypto when available. See examples here). This id is concatenated with the "id token" the user received when they created their account. This new composite id (server side id token + client side uuid) is now the unique identifier for the record. When the user is online and submits this new record to the backend server, the server would:   1. Identify this as an "insert" action (i.e. not an update or a delete)   2. Validate both parts of the composite key are valid uuids   3. Validate that the provided "id token" part of the composite id is correct for the current user (i.e. it matches the id token the server assigned to the user when they created their account)   4. If everything is copasetic, insert the data into the db (being careful to do an insert and not an "upsert" so that if the id _does_ already exists it doesn't update an existing record by mistake) Queries, updates, and deletes wouldn't require any special logic. They would simply use the id for the record in the same manner as traditional applications. ## What are the advantages of this approach?   1. Client code can create new data while offline and know the id for that record immediately. I considered alternate approaches where a temporary id would be generated on the client which would later be swapped out for a "final" id when the system was online. However, this felt very brittle. Especially when you start thinking about creating child data with foreign keys that would also need to be updated. Not to mention dealing with urls that would change when the id changed.   2. By making ids a composite of a client generated value AND a server generated value, each user is effectively creating ids in a sandbox. This is intended to limit the damage that can be done by a malicious/rogue client. Also, any id collisions are on a per user basis, not global to the entire system.   3. Since a users id token is tied to their account, ids can only be generated in a users sandbox by clients that are authenticated (i.e. where the user successfully logged in). This is intended to keep malicious clients from creating bad ids for a user. Of course if a users auth token were stolen by a malicious client, they could do bad things. But, once an auth token has been stolen the account is compromised anyhow. In the event that this did happened, the damage done would be limited to the compromised account (not the entire system). ## Concerns Here are some of my concerns with this approach   1. Will this generate sufficiently unique ids for a large scale application? Is there any reason to think this will result in id collisions? Can javascript generate a sufficiently random uuid for this to work? It looks like window.crypto is fairly widely available and this project already requires reasonably modern browsers. (this question now has a separate SO question of its own)   2. Are there any loopholes that I'm missing which could allow a malicious user to compromise the system?   3. Is there reason to worry about DB performance when querying for a composite key made up of 2 uuids. How should this id be stored for best performance? Two separate fields or a single object field? Would there be a different "best" approach for Mongo vs Couch? I know that having a non-sequential primary key can cause notable performance issues when doing inserts. Would it be smarter to have an auto generated value for the primary key and store this id as a separate field? (this question now has a separate SO question of its own)   4. With this strategy, it would be easy to determine that a particular set of records was created by the same user (since they'd all share the same publicly visible id token). While I don't see any immediate issues with this, it's always better to not leak more info about internal details than is needed. Another possibility would be to hash the composite key, but that seems like it may be more trouble than it's worth.   5. In the event that there is an id collision for a user, there's not a simple way to recover. I suppose the client could generate a new id, but this seems like a lot of work for an edge case that really shouldn't ever happen. I'm intending to leave this unaddressed.   6. Only authenticated users can view and/or edit data. This is an acceptable limitation for my system. ## Conclusion Is above a reasonable plan? I realize some of this comes down to a judgement call based on a fuller understanding of the application in question.


Server-side vs Client-side web application Performance

I am an entry level programmer with only a few months of experience. Yesterday I was discussing with a colleague how we can improve the performance of a project we are working on together. The project is built with C# + Ext.NET + JS The plan was to move as many things as possible to client-side JavaScript instead of interacting with the server all the time. I thought this was a good idea, but couldn't help but wonder if there is a point where bringing everything to client-side starts making the web application slower. I understand that interacting with the server and reloading unnecessary data all the time is a waste of time in most cases, but I've also seen websites loaded with so much JS that the browser actually lags and the browsing the web application is just a pain. Is there a golden point? Are there certain 'rules'? How do you achieve maximum performance? Take Google Cloud apps, such as Docs for example, they're pretty fast for what they do, and they're web applications. That is some very good performance.


At what point should one consider using sql databases?

As the size of my data and the structures I use to hold it get larger and more complex, I start to wonder if I should learn to use sql databases. In the past, instead of unique tables, I would do something like the following:               'class Dog            String name            Toy[] toys            long  numberOfHairs            short numberOfFlees            etc.      Then I might have a sorted array based on numberOfFlees, a hash of names, a set of toys, etc. to suit my needs. This has worked fine for me with smaller projects, but at what point should I consider SQL. What will I lose and gain?


Arithmetic Coding Questions

I have been reading up on arithmetic coding and, while I understand how it works, all the guides and instructions I've read start with something like: > Set up your intervals based upon the frequency of symbols in your data; > i.e., more likely symbols get proportionally larger intervals. My main query is, once I have encoded my data, presumably I also need to include this statistical model with the encoding, otherwise the compressed data can't be decoded. Is that correct? I don't see this mentioned anywhere -- the most I've seen is that you need to include the number of iterations (i.e., encoded symbols) -- but unless I'm missing something, this also seems necessary to me. If this is true, that will obviously add an overhead to the final output. At what point does this outweigh the benefits of compression (e.g., say if I'm trying to compress just a few thousand bits)? Will the choice of symbol size also make a significant difference (e.g., if I'm looking at 2-bit words, rather than full octets/whatever)?


Build filter conditions for entities on client side

I have the requirement that users should be able to specify filter conditions for one kind of entity through a GUI on a thin client. These conditions must be   * convenient to generate, meaning the GUI should guide users as much as possible. They shouldn't have to write SQL or anything.   * stored with a time stamp, a user ID, a description, and whatnot...   * loaded and edited   * reusable by other users   * used for loading matching entities from the DB via an ORM framework. Ideally I could generate a predicate out of them - SQL or maybe an Expression, which the ORM can translate to SQL In my case users specify a condition for customers, for who invoices should be generated. There will be many different such "customer selections". I think the specification pattern might be a good match, but couldn't find any examples, where specifications are built through a GUI, serialized and stored/reloaded/edited via an app server and used to retrieve matching entities. Am I maybe overlooking the standard way to do such a thing? Colleagues have suggested to just build the SQL WHERE predicate on client side, but I don't like that. The client shouldn't know that much about persistence (column names...), and should only be allowed to use certain predicates, but not others. Also I'd have to parse these strings into separate predicates when I reload a condition to display them in a user friendly way.


Should the helper function in class be defined before the usage or after

I need to do the code review of fellow members. One of the member always defined the helper functions at the bottom and use them at top e,g               class Sample {          public function SendFile(){     file = $this-convertFile($file);     }          public function convertFile(){     //bla bla     }          }      I sometimes dont know if he has custom defined this function of it is inherited from base class or some builin php function . when i reach bottom then i find it was custom defined


Understanding Indian culture

I have been put in charge of managing and leading a team of programmers based in India. I have a feeling there are some cultural issues to overcome, aside from the obvious English 2nd language ones. For example, from my past experience working with Indians, I sense a certain reluctance to ask questions or advice, even when requirements are not clear. More than once I have seen Indian developers say they understand the requirements when they really don't, then just make their own unilateral assumptions about how things should be, and plough ahead on that basis without consulting with anybody else, so that we only realize a week or two down the line that they've been developing something completely other than what we wanted. Is that a general cultural thing, or did I just see a bad sample? Have you managed or worked with Indian teams? What other advice could you offer as to how best to manage and otherwise relate to them?


MVC JSon Request architecture

I am finding myself building up a whole bunch of JSON calls all through my application, which are basically actions spread across various controllers. I am considering creating a JSON Controller to keep all the JSON actions in one controller, so instead of;               Products/GetListJSON      I would call               JSON/Products      Might this have ramifications that I haven't considered? Can anyone think of any compelling reasons not to do this?


Create my own database system

I need to learn how databases work in order to use them more efficiently, and my way of learning is by doing. I want to create my own database system. I am not referring to creating a pseudo-database that would use query to parse files; this would simply be a filesystem interface with a query language. I am talking about the actual structure of a database engine. And since what I have in mind is neither relational nor document-oriented (it's "node-oriented", if that even exists), I would need any resource to be as abstract and high-level as possible. So how would I go about creating that? What resources/tutorials/books can I read to understand? The language does not matter in the slightest. Ideally, the code would be pseudo-code to illustrate the concept, not tied to a particular language, but anything would do. I was not able to find anything on the matter on google (since I am so illiterate on the subject, maybe I am just not entering the right search). If such resources are not available, then I guess something about how to create a client would at least be a step in the right direction.


Can I use a JQuery plugin under the CC BY-SA 3.0 license in a commercial webapp?

if a JQuery plugin is released under the CC BY-SA 3.0 license, can it be used as part of a closed source commercial web application which is not redistributed, just accessible on the web?


How do you proactively guard against errors of omission?

I'll preface this with I don't know if anyone else who's been programming as long as I have actually has this problem, but at the very least, the answer might help someone with less xp. I just stared at this code for 5 minutes, thinking I was losing my mind that it didn't work:                   var usedNames = new HashSet<string>();         Func<string, string> l = (s) =>             {                 for (int i = 0; ; i++)                 {                     var next = (s + i).TrimEnd('0');                     if (!usedNames.Contains(next))                     {                         return next;                     }                 }             };      Finally I noticed I forgot to add the used name to the hash set. Similarly, I've spent minutes upon minutes over omitting context.SaveChanges(). I think I get so distracted by the details that I'm thinking about that some really small details become invisible to me - it's almost at the level of mental block. Are there tactics to prevent this? update: a side effect of asking this was fixing the error it would have for i > 9 (Thanks!)                   var usedNames = new HashSet<string>();         Func<string, string> name = (s) =>             {                 string result = s;                 if(usedNames.Contains(s))                     for (int i = 1; ; result = s + i++)                         if (!usedNames.Contains(result))                             break;                 usedNames.Add(result);                 return result;             };


Sending an email with attachment from server side

I have to create a word document in a specific format and send it as attachment to some email addresses. I have a preview screen for the report which on approval has to be send in email. This is an ASP.NET MVC 3 application. I am left with a few options here.   1. I am creating the preview using html. I can convert this html into doc and send it, which would be a straight solution. But capturing the Response object's output is being a tough job.   2. I thought of using Mail merge functionality of MS word, where I'll be filling the placeholders of the doc template. But the problem is conceptually, it doesn't appear to be mail merge.   3. I have found someone suggesting to use RTF format and replace the placeholders with database values. Which is the right thing to do? What's the best solution here? Is there any other option than the three listed above?


I have an MIS degree. How do I sell myself as a programmer?

So, I graduated with a BSBA in Management Information Systems with honors almost 2 years ago which is more of a business degree. As of right now, I do have a job title of "Programmer", but it's more of a report writing position in an arbitrary, proprietary language called PowerOn with the occasional interesting project using more mainstream technologies like .Net and Java. I am also somewhat isoloated being the only programmer in the workplace, which I beleive is a detriment to my career path. The only people I have to bounce ideas against are those on the various SE sites. I don't regret going MIS, but over the past couple of years I have discovered my passion for coding, even though I have been doing some form of coding profesionally and as an enthusiast for years. I do want to persue my Masters in CS (at a later time), but I am not sure if I necessarily _need_ a CS degree to get in with a team of programmers. In addition, I do have a number classes I have taken for different laguanges on the way (C++, Java, SQL, and VB.Net) I beleive my strength is in problem solving where code is just a tool to tackling to problem if needed. My question: **How do I best sell myself as a programmer? Should I continue pounding out reports and wait till I have my masters in CS? Or am I viable to be a programmer as I stand?**


Why not apply Interface Segregation Principle to "extreme"

Providing that clients would typically consume just one method, though methods would be conceptually related, why not always apply the Interface Segregation Principle to the extreme and have [many] single-method interfaces? Is there an objective rule against this? Not something like "oh it feels wrong" or "but you will have so many types, it's hard to read and manage" but rather something logical and clear. (Still want to name contracts clearly, so functions are not a good fit?). Example:               IGeometryManager     {        Shape CreateTriangle();        Shape CreateCircle();        Shape CreateSquare();        Shape CreateEllipse();        Shape CreateCurve();        Shape CreateLine();        void RemoveAll();     }      Result:               ITriangleCreator     {        Shape CreateTriangle();     }          ICircleCreator     {        Shape CreateCircle();     }          ISquareCreator     {        Shape CreateSquare();     }          IEllipseCreator     {        Shape CreateEllipse();     }          ICurveCreator     {        Shape CreateCurve();     }          ILineCreator     {        Shape CreateLine();     }          IShapeRemover     {        void RemoveAll();     }      This is a relevant blog post, but I am not 100% persuaded by the authors logic: http://blog.ploeh.dk/2014/03/10/solid-the-next-step-is-functional


Where do you use Java Channels?

I have only used Java Channels and BufferedOutputStream and the input counter part for reading and writing simple integers and some strings here and there to the file.   However I do not understand the use of all these classes when there is `java.util.Scanner` class that provides easy ways to read and write to the files.   Java veterans please tell me the use of Channels and Streams over Scanner.


What's the progress on Haskell records?

Recently I stumbled once again on the issues of Haskells records, in particular the uniqueness of field names (it's a pain ...) I already read A proposal for records in Haskell  from SPJ and Greg Morrisett but it's last update was 2003.   Another paper Lightweight Extensible Records for Haskell from SPJ and Mark Jones is even older: It's from a Haskell workshop in 1999. **Now I wonder if the process of giving Haskell new records made any progress.   Does anybody know something about it or can point me to some further reading ?**


Which is the better: a <= b or a < b+1

For loops are usually inclusice, exclusive, meaning that you start at the bottom, and stops when you reach, but don't to the top. In Python:               for i in range(0,a):         print(i)      would print 0 through a-1. The same applies for Java:               for(int i = 0; i < a; i++){         System.out.println(i);     }      would also print 0 through a-1, allthough the syntax is somewhat clearer. So what if you want to print every number up to a, inclusive? Would you write               for(int i = 0; i <= a; i++){         System.out.println(i);     }      or               for(int i = 0; i < a + 1; i++){         System.out.println(i);     }      I guess the first makes the most sense, you're looping while i is less or equals to a, but the less than sign could easily be overlooked. The `a + 1` isn't that easy to miss, in my opinion. So my question is: Is there a better alternative of the two, and is there a convension for this thing? EDIT:   I just want to point out that i'm talking about integers here.


Interactive session with a command line program using Java?

I plan to write a website frontend for a free computer algebra system (Reduce, http://reduce-algebra.com/). On the webserver I have a Java virtual machine running, and Reduce is also installed. I can start the application via exec() in the Java file. But my question is the following: how can I emulate user inputs and how can I retrieve the outputs of the program? The main issue is that I want to log the whole session, not just call the program once, get the output, close it, and restart it again. I need a way that allows for interactive communication, i.e. a way to "paste" a command in the command line, and a way to "copy" the response back to the Java program.


Coding in 'core php' and separating logic from presentation

What are the various ways of acheiving this ? Can someone please guide me? I have to code a website for a friend (designer). The friend wants me to use core php and not any framework like codeigniter (something I really like and am comfortable with !) . I had a look at a couple of roll your own MVC frameworks guides, but am not sure if this is the ideal approach. Since any solution I might come up with may have various bugs/security issues. My goal is to use plain php , without the help of thirdparty frameworks, to code a site , where the logic is separate from the view . Thanks


When can I be sure a directed graph is acyclic?

The definition for directed acyclic graph is this: "there is no way to start at some vertex v and follow a sequence of edges that eventually loops back to v again." So far so good, but I am trying to find some premises that will be simpler to test and that will also guarantee the graph is acyclic. I came up with those premises, but they are pretty basic so I am sure other people figured it out in the past (or they are incorrect). The problem is I couldn't find anything related on books/online, hence why I decided to post this question. **Premise 1** : If all vertices of the graph have an incoming edge, then the graph can't be acyclic. Is this correct? **Premise 2** : Assume the graph in question does have one vertex with no incoming edges. In this case, in order to have a cycle, at least one of the other vertices would need to have two or more incoming edges. Is this correct?


Should I / can I bundle node.js and mongod together with my application?

I'm working on a web application that runs on node.js and uses MongoDB. It's important to mention that I plan to release the application as commercial software. The way I wrote the installer, it asks the user to confirm the location of the node and mongod binaries (after autodetecting first). I figured I could skip this step altogether by bundling said binaries together with my application or making the installer download them, but there are a few issues I need to address:   1. First and foremost, the licensing issue. The friendly folks at 10gen (the company that develops MongoDB) answered an email I sent them and told me their license allows this, and from what I can figure out, this is the case with node.js too. Are there any problems I should keep an eye out for?   2. Is it worth (from the user's point of view) fetching ~20MB of extra data during installation just for the convenience of not having to manually install node.js and mongod (the MongoDB server binary)?   3. Should I expect any problems if I bundle the 32-bit binaries and the user installs the application on a 64-bit machine?


What are the most over-saturated iPhone App category/markets?

I'm considering learning iPhone development and Objective C but don't want to avoid developing something for the most saturated markets and app categories. What categories should I avoid? Are there too many dating applications, or should I just stick to coming up with a creative game or two?


How do these hotshot developers keep changing their technology base?

Yesterday I was watching a lynda.com iphone development video and this developer started telling about how he has worked on 17 different languages from the days of mainframes in assembly/Cobol to now on iPhone Objective-C. My question is how do these developers keep shifting to new technology, without fearing the loss of experience they already have about a particular technology. I am trying to shift to Java from PHP and market considers this as non- relevant experience. How do these guys do it without losing the pay and not being considered a fresher in a particular technology.


How do you deal when an error occurs on 1 instance of your website/program/app?

I've had a couple of times in the time I've working, moments when I get an error ocurring in just 1 computer and it often takes me hours or days to figure out because it is (or at least seems) an isolated incident as it is not being presented in any other instance of whatever I'm checking. How do you guys deal with this? I've often had to just change the computer per se (like formatting, or stuff like that) because I simply cannot replicat the issue.


Support multiple frameworks in a JavaScript library

I have a small JavaScript library that I've written that depends on prototype.js. I'm considering creating a new version that would use jQuery instead. The goal is to make it easier for users to install ( _choose which framework you use!_ ) while not making it harder for me to maintain. The main issue I see is that I would need to support two separate versions with overlapping functionality. If there is a bug, then I would need to fix it in two separate places. How can I support multiple different frameworks in a JavaScript library without having a maintenance nightmare?


Should I always use "is" as prefix for boolean variables?

Should I always use `is` as prefix for boolean variables? What about booleans that indicate something in past? Should I write `isInitialized` or `wasInitialized`? Should I write for properties `IsManyMembers` or `HasManyMembers`? Is there any best practices? Or I should just write in accordance with English rules?


OOP Objects, nested objects, and DAO's

Here's something I keep struggling to figure out the best solution to. I've had this problem while working with PHP and Java so it's a fundamental understanding of OOP issue. Examples are in PHP. Let's say I have a few object's here. Song, Artist, ArtistProfile, User. So in some instances I want the ArtistProfile and an array of User objects (subscribers) when I call the Artist (e.g. the artist's profile page), in other instances I only want the Artist info, like when viewing a page of the song. Should I be nesting one object as part of another or should I be creating more specific objects for different usages. Option 1: Nested               Class Song {        private $songId;        private $songName;        private $year;        private $Artist; //Artist object     }          Class Artist {        private $artistId;        private $name;        private $age;        private $subscriberArr; //Array of User objects which then have more nested objects such as a Role object, Profile object        private $profile; //Profile object which could also have more nested objects     }          Class User {        private $userId;        private $name;        private $age;        private $role; //Role object        private $profile; //UserProfile object     }      Option 2: Build more objects               Class Song {        private $songId;        private $songName;        private $year;        private $artistId;     }          Class Artist {        private $artistId;        private $age;        private $name;     }          Class User {        private $userId;        private $name;        private $age;        private $roleId;     }          Class SongWithArtist {        private $song; //Basic Song object        private $artist; //Basic Artist object     }          Class ArtistWithProfile {        private $artist; //Basic artist object        private $profile; //Profile object        private $subscriberArr; //UserDisplay object containing basic User object     }           Class UserWithProfile {}      Option 1 means wasting a lot of time/resources grabbing information I may not need for that page but easier to manage. Option 2 is messy and requires keeping track of which object is what but faster and far less db calls. Which is the 'correct' option and/or is there a 3rd correct option?


Possibility Program for number of pieces

I would like to put a program together to calculate the number of 60' pieces would be needed from a list of shorter pieces. For example, I sell rebar cut to length from our standard length of 60'-0". Now the length the customer requires are as follows:               343 pc @ 12.5'     35 pc @ 13'     10 pc @ 15'     63 pc @ 15.5'.......      There are 56 total lengths ranging from 12.5' to 30.58' The idea is to limit the amount of waste from the 60' piece. The input from the user would be:   * number of differnt lengths   * Length of piece to cut from    * count of different lengths The result would be the number of prime pieces needed to fulfill the order. What well-known algorithms exist that could help me solve this problem?


Could ChromiumOS be re-written in Go from the ground up?

As Go seems able to performance match C and with Google obviously biased towards Go, I feel that it would be great way for Go to gain more traction. The way ChromiumOS/Chrome has jumped from an Ubuntu base to a Gentoo base, while they have the ability to avoid both and create exactly what they need from scratch, leads me to believe it could be something in the works. Time would of course be a factor, as would the lack of existing libraries as compared to C and Linux, but done in parallel whilst the current Linux based machines gain traction would mitigate any time to market issues for them. I'm a rank amateur when it comes to low-level programming though, are there any technical limitations in the language to prevent this from happening?


How does a concurrent garbage collector deal with variables?

Let's say it is a concurrent mark-and-sweep garbage collector. When such GC handles constant pointers it just walks through them (starting from roots), and marks every encountered data block. Then sweeps everything unmarked. A client code should mark the data blocks it uses as roots. But what to do with variables? Here is a situation:   1. `V` is a variable, which stores a pointer to object `A`.   2. `Thread 1` reads `V` and suspends.   3. `Thread 2` modifies `V` and makes it point to object `B`.   4. The garbage collector runs its "mark" phase and encounters that `A` is no longer referenced, then deallocates it during the "sweep" phase.   5. `Thread 1` awakens and tries to use `A` (already read from `V` at step 2) by marking it as root. **And fails** , because `A` is no longer exists. So, how to handle this? The `Thread 2` can mark the replaced object `A` with a special do-not-remove flag (similar flag is used for newly allocated objects). But when this flag should be removed? Of course `Thread 1` could do that. But `Thread 2` knows nothing about `Thread 1`, and thus can not be sure that this will be done ever. This may lead to `A` will never be freed. And if GC will remove that flag, then nothing prevents `A` from being removed when GC runs for the second time... The on-the-fly mark-and-sweep garbage collector descriptions I've read just mention that the replaced object should be "grayed". But without any specifics. A link to a more detailed description of the solution would be highly appreciated.


Is OAuth (2.0) is the right choice to make WCF WebService secure?

I have WCF webservice which serves to various mobile application. This was implemented with typical HTTPS/SSL. But there are some cases like Replay Attack needs to be considered in the security aspect. OAuth 2.0 looks like a viable solution for this problem (using nonce). And I can see some examples on web using DotnetOpenOAuth library to implement a server. Is OAuth is a right choice to use with WCF services? Is there any alternatives with .NET framework/Microsoft technologies to implement a secure WCF server?


A newbie in python trying to learn

Am trying to learn how to program before i go to uni and i stumbled upon a question which i have been unable to do. In the function write code to input two integers m and n and calculate and display the sum of all the integers from m to n e.g. if 4 and 8 were entered (in either order) the sum to be calculated would be 4+5+6+7+8. The sum should be calculated using a loop to repeatedly add numbers to a total. You are not allowed to use a formula to calculate the result. i have been able to do the basic addition but to keep adding is where am stuck at like if enter a value for m = 6 and n = 9, it should print out as 6+7+8+9 and add the values All contributions will be greatly appreciated. thanks


Two possible solutions to a problem, DB design

I saw the recent post about the person questioning his boss's solution (I believe my solution is better than my boss, so should I ignore him?) and decided to ask something similar but not as "clashing" as it sounded in the above link. To put it simply and more conceptually:   We have a web app that does phone billing for many different clients. The thing is, the person that started the project didn't consider that there are only 9999 possible phone extensions in our design (a bit naive, I know). We have come across a point where different clients's users will have to share the same `extension number`. In the DB level, the `extension number` is fixed as `unique` and the `Extensions` table has a foreign key to `Users`. The easiest solution as we saw was to remove this `unique` constraint and allow `extension numbers` to be duplicated because we can still check and validate to see which `Client` the `User` belongs to. However, the person that oversees my work believed it would cause future problems if we simply allowed for duplication. He suggested I create an intermediary table that links two tables together, namely `UserProfile` (which has a foreign key to User and `Client`) and the `Extension` table. Since my way seemed easier to do, I created a branch of the project to test if it works fine, which it does. Then I started implementing the other way and came across some complications, system-wide modifications, but I still think it's doable. The person that oversees my work is a sys admin that does some programming. I'm the full-time programmer, though without much experience (still young ;) ). It would be cool if I had some outside perspective on my dilemma? Thanks a lot guys.


Exposing domain models over API

I'm building a simple RESTful API for a web-based application I'm working on, and I'm wondering about the best way to go about exposing my domain models. Let's say I have a User class and I want to provide a JSON response with the various user properties. I obviously don't want to publicly expose every property of my model (things such as DateCreated, PasswordHash etc) due to security and bandwidth issues. I've read into Data Transfer Objects and I'm wondering if this is the way to go. If I'm right I could pass, for example, a User model to my User DTO and ensure said DTO only allows exposure of the User properties I choose (which would also help decouple my models from my public API). Is this solution appropriate or are there better ways to go about this? Thanks.


Maintaining good form while learning new technologies

I find that I have to learn new technologies fairly regularly as a contractor in order to keep competitive. However, I also find that (not only, but especially) in these circumstances, I tend to end up with really bad code flow and need to do a lot of rework in order to achieve a canonical solution. While I realise that there are those contract programmers out there have no problems with taking the money and running, I wish to maintain good relationships through a good codebase that is not only easy, but fun to maintain -- which ultimately translates into a more lucrative business for me in the long run, as architectural risks are kept minimal. However, I wonder if there are ways by which I could improve my ability to learn technologies _while at the same time_ getting structure closer to what is correct / canon, right from the start -- particularly given some poorly documented techs, or those that are documented in a fragmentary fashion. While there is no substitute for experience, I want to streamline this process, reducing the considerable refactoring time I suffer at present, as it is something I experience often.


Using High Level Abstractions

I'm not sure if I'm using the correct term, but would you program using High- level abstractions like Powerbuilder, or some CMS like MODx or DotNetNuke? I haven't dabbled in any of these yet. The reason I'm asking is that I kind of feel intimidated by the whole notion of using any abstraction over the languages I'm using. I'm thinking that my job might be over-simplified. While it may provide business solutions faster, I'd rather be coding straight from, in my case, .NET. Do/Would you use abstractions like these or prefer them over programming in lower level languages?


Clarification about MVC Design pattern

I've been reading up on MVC and I had a doubt. The example where the Model, View and Controller are all individual classes whose objects are created and used to deploy the application in another class. A GUI I've designed treats the Model, View and Controller as separate classes and for the most part changes can be made to each without breaking the other .However these separate classes are referenced within the Controller (UI) class. I have no 4th class that calls and creates objects for the Model, View and Controller. Does my setup still follow the MVC design methodology? Thanks.


How to manage with less technical knowledge?

I've become a project manager in my company and here is what I've experienced till now: At first, I was trying to keep in shape technically with other developers of the team (about 15 developers) and read as much as I could so that I would know almost everything going on in the project, from architecture, up to syntax consistency. However, soon I realized that it's almost impossible for you **to know everything**. Therefore it's natural that you fall back in the technical race. Imagine how much work it requires for you to learn **Ext JS** , **Angular JS** , **BRE** , **WCF** , **Enterprise Library** for logging, **Asterisk** , etc. etc. all at the same time. Thus it seems to me that this is not the correct path. I think the formula is: The more people you have to manage, the less technical knowledge you can possess. However, there are problems in not knowing what's going on inside your team technically:   1. You might not understand and detect bottlenecks just the way you would do when you were developing   2. You might not decide which technology is better at performance and productivity   3. In case of a technical dispute in team, you might not be able to help   4. The more distance you get from code, the less you might understand developer's stress, pressures, and feelings (this is a big concern for me)   5. You might not be able to forecast and predict the time necessary to get a task done   6. You loose your passion when a developer talks with enthusiasm about a problem that has been solved, because you don't understand like 40 percent of what he talks about, and the less you know about something, the more boring it might become for you   7. Developers would find it harder to explain something to you and they need to speak less technically   8. Bad developers (rare but existing) might misuse your lesser technical knowledge and cause all sort of problems   9. ... This phenomenon probably occurs in any career and profession. However, since the world of development and computer in general is moving forward with more speed (comparing to say, car industry), thus in a short period of time like 6 months you feel that you've fallen back. Version after version, feature after feature, library after library, you got the idea. I saw these questions, and they contain good suggestions. How can I maintain my technical skills after becoming a project manager?   How much should my project manager know?   How much should my project manager know?   Should a manager (or CEO) in an IT company have an IT background to perform in the organization?   How can I convince management to deal with technical debt? However, they're based more on personal experience and advises, which is of course good, but might not help that much. Do we have a book, or a well-thought and researched essay on this subject, on how to manage a team of software developers, **with lesser technical knowledge** than team members? What points should I take into account to lead effectively and make the whole team achieve success?


where exactly should python business logic be placed in django

I have just begun to learn Django/Python/Web Development. This problem has been troubling me for a while now. I am creating an application with multiple templates in Django. I have a views.py which is basically just rendering the responses to the respective templates and I have a models.py where I have structured my DB. In one of my templates, I need to upload an image (which I am able to do) and I need to run a logic which is based on the features of the uploaded image (not yet done). This logic involves a lot of heavy calculations. After performing the calculations, the logic should return some processed information (coordinates) to the template. I have been able to do all this actions successfully in a standalone python desktop application calling python files one after the other. However, since I now want to make this a web application I have begun using the Django framework. I have done a lot of searching but I am still not able to figure out where exactly should I place this Python file containing all the logic. Should I have another class based file `(logic.py)` and call it from the `view.py`? I googled and found that many developers are placing their business logic in their models.py in Django. However, I feel it is intuitively not right since model should exclusively communicate with the back end. Any help would be appreciated.Thanks in advance.


Is there such a thing as a "when" statement?

Is there a language or language feature that can handle "when" cases? That is, whenever some condition becomes true, in any scope or context, that extra code could be specified to execute? Note that this is different from a simple `if`, which must be in a particular scope and explicitly written. This when clause would almost be like an `if` that applied to every case in the execution of the program after it.


What's the advange of JRuby (or any other language ported to JVM)? Why would one use it?

Let's say I really like Ruby and I know Java. What's the deal behind these J* and Iron* languages that allow you to use the syntax of a foreign language to compile them into JVM or .NET bytecode? Basically, what's the advantage? Is it just because you like the runtime of one language, but not the syntax? Please advise!


Is ViewModel with more than one repository bad?

I'm working on a project with MVVM. Some ViewModels have more than one repository.   * **Is ViewModels with more than one repository bad?**   * **Please provide with why it's good/bad.**


When building a REST service with the HATEOAS constraint, it's very easy to advertise the existence of resources through linking. You make a `GET` to the root of my site and I respond with the root document listing all the first- tier resources:               {         users: { href: "/users" }         questions { href: "/questions" }     }      Clients which understand how to read these `href` values could perform `GET` requests on those and discover all the current resources available in the application. This works well for basic lookup scenarios, but doesn't indicate whether a resource is queryable. For example, it may be reasonable to perform:               GET /users?surname=Smith      Are there any formats that could express this query ability with enough information that a client could form a coherent query without needed prior knowledge of the resource? Additionally, is there any way to express that a client is allowed to perform a `POST` to a given location with an expected location. For example, it could be expected that a client perform the following to create a new question resource:               POST /questions          {         title: "Are there strategies for discovering REST services using HATEOAS?",         body: "When building a REST service with the HATEOAS constraint, it's very..."     }      When using HTML as the format for human consumption, we can express a lot of this through use of forms and written prompts to allow a human to discover the operations they are allowed to perform on a service. Are there formats which are capable of similar things for clients?


design of 'game engine' for small javascript games?

I'm making a group of two or three simple javascript games for fun. After someone finishes one game, they'll be presented with a harder or easier version of another game depending on whether the original game was won or lost. I have a high-level question about the design of things: So far I've created a class for one game type that manages the interaction with the UI and the state of the game itself. But for tracking how many of the subgames have been won, or for understanding whether the next game presented should be more or less difficult, are there arguments to be made for making a 'game engine' class? How does the engine communicate to the games? For instance, when a game is won, how is that information relayed to the engine? Is there a better or more common design? (If you want to see what I have so far, the games are slowly taking shape here: https://github.com/yosemitebandit/candela and can be viewed at http://yosemitebandit.com/candela)


Automatically adding data from JSON to SQL

I'm really new to this sort of stuff; my background is in C# mainly. Could anyone point me in the right direction? I need to set a script to automatically parse some JSON into an SQL database whenever the data has been updated on the server. I look at this file first which returns the file location for the data and the last modified time stamp: http://us.battle.net/api/wow/auction/data/medivh. I've spent the last hour googling, but I can't find an adequate answer. To summarise, the script needs to run every 15 minutes or so, check if the timestamp changed and if so, and pull the new data and enter it into an SQL database. Do I need to use PHP to parse and insert the JSON data into the database? If so, how do I manage to run the PHP code every x minutes?


Applications affected by memory performance

I'm writing a paper on the topic of applications affected more by memory performance than processor performance. I've got a lot written regarding the gap between the two, however I can't seem to find anything about the applications that might be affected more by memory performance than by processor speed. I suppose these are applications that make a large amount of memory references, but I have no idea what kind of applications would make such large number of references to make it stand out? Perhaps databases? Can you please give me any pointers on how to proceed, some links to papers? I'm really stuck.


Is the Java Integer cache a realization of the object pool pattern?

One of the best-known examples of a full-fledged object pool is the JDBC connection pool. Main reasons:   * objects in the pool are expensive to create and relate with external resources   * each object in the pool is served to at most one client a time   * objects in the pool need to be brought back to a clean state before being served again to a new client With the above in mind, can the Java Integer cache be regarded as a object pool realization? Here is why I doubt it:   * objects in the pool can be used by more than one client a time due to their immutability   * immutability also prevents pool objects from reaching a stale state   * there's no notion of a "free" object, ready to be allocated to a client


Requring static class setter to be called before constructor, bad design?

I have a class, say `Foo,` and every instance of Foo will need and contain the same List object, `myList.` Since every class instance will share the same List Object, I thought it would be good to make `myList` static and use a static function to set `myList` before the constructor is called. I was wondering if this was bad, because this requires the setter to be called before the constructor? If the person doesn't, the program will crash. Alternative way would be passing `myList` every time.


Best Practice: strategy regarding Website Projects and versioning

What are the best practices and strategy for designing and developing a website? The key parts I want considered are:   * DLL deployment    * IIS publishing   * project versioning    * namespace Please answer these questions with recommended steps you take for your own web sites. A sample walk-trough** (Please correct it with yours.)   1. You make a web Application   2. You make an IIS version of it   3. Copy the same to the IIS Web Folder   4. Copy the exact "Web Application" DLL into the IIS version folder ( or Will you build the wesite DLL here with csc or choose another method )   5. Add each project separately to the repository   6. Will anyway having both cause any conflicts (web application and website)?   7. Do you make separated projects?   8. How do you ensure that build of website assembly is always updated?   9. How will you go for versioning of these and sync them?   10. Moving the website DLL from the web application couldn't be a good idea How do you deal with that?   1. The most important part of this question for me is the number of projects/solutions you make for a website project.   I guess that probably they are 1 or 2 solutions, and as a professional developer, you will make them subversioned.   2. Do you change the namespaces, or assemblies? Will each of them have separated core assemblies? Will you share? If you share, how will you deal with that?   I think conflicts will occur.   3. Do you use a project as a container of the other one? How will subversioning be? ### What I use VisualSVN is my subversioning choice.   I had 2 projects similar to the formula above; I made a web project with pages, and after that I made a clone of it in the IIS. I fixed some addresses and paths issues and copied also the DLL inside the IIS-Version of the site, but I really do not know this way as a completely practical method because of the conflicts I mentioned.


Examples of limitations in IT due to different bit length by design

I am teaching the course "Introduction in Programming" for the first-year students and would like to find interesting examples where the datatype size in bits, chosen by design, led to certain known restrictions or important values. Here are some examples:   1. Due to the fact that the Bell teleprinter used 7-bit-code (later accepted as ASCII) until now have we often to encode attachments in electronic messages to contain only 7 bit data.   2. Classical limitation of 32-bit address space leads to the 4Gb maximal RAM size available for 32-bit systems and 4Gb maximal file size in FAT32. Do you know some other interesting examples how the choice of the data type (and especially its binary length) influenced the modern IT world. **Added after some discussion in comments:** _I am not going to teach how to overcome limitations._ I just want them to know that 1 byte can hold the values from -127..0..+127 o 0..255, 2 bytes cover the range 0..65535 etc by proving examples they know from other sources, like the above-mentioned base64 encoding etc. We are just learning the basic datatypes and I am trying to find a good reference for "how large" these types are.


Simplifying data search using .NET

An example on the asp.net site has an example of using Linq to create a search feature on a Music album site using MVC. The code looks like this -               public ActionResult Index(string movieGenre, string searchString)     {         var GenreLst = new List<string>();              var GenreQry = from d in db.Movies                        orderby d.Genre                        select d.Genre;              GenreLst.AddRange(GenreQry.Distinct());         ViewBag.movieGenre = new SelectList(GenreLst);              var movies = from m in db.Movies                      select m;              if (!String.IsNullOrEmpty(searchString))         {             movies = movies.Where(s => s.Title.Contains(searchString));         }              if (!string.IsNullOrEmpty(movieGenre))         {             movies = movies.Where(x => x.Genre == movieGenre);         }              return View(movies);     }      I have seen similar examples in other tutorials and I have tried them in a real-world business app that I develop/maintain. In practice this pattern doesn't seem to scale well because as the search criteria expands I keep adding more and more conditions which looks and feels unpleasant/repetitive. How can I refactor this pattern? One idea I have is to create a column in every table that is "searchable" which could be a computed column that concatenates all the data from the different columns (SQL Server 2008). So instead of having movie genre and title it would be something like.               if (!String.IsNullOrEmpty(searchString))     {         movies = movies.Where(s => s.SearchColumn.Contains(searchString));     }      What are the performance/design/architecture implications of doing this? I have also tried using procedures that use dynamic queries but then I have just moved the ugliness to the database. E.g.               CREATE PROCEDURE [dbo].[search_music]          @title as varchar(50),         @genre as varchar(50)     AS          -- set the variables to null if they are empty     IF @title = '' SET @title = null     IF @genre = '' SET @genre = null          SELECT m.*     FROM view_Music as m      WHERE          (title = @title OR @title IS NULL)         AND (genre LIKE '%' +  @genre + '%' OR @genre IS NULL)     ORDER BY Id desc     OPTION (RECOMPILE)      Any suggestions? Tips?


Cross "Machine" Code?

Some languages (mostly ones made in the last 2 decades or so) can now not only run (after some compilation step or directly) on several platforms, but also can be compiled to run on several virtual machines. For example, take Scala. Pure Scala code can be either interpreted , compiled to run on the JVM (Java Virtual Machine) or can be compiled to run using the .NET Framework. The benefits of platform-independence put aside, what exactly are the benefits of writing code that can compile on several virtual machines and runtimes?


We are moving an Access based corporate front-end into a Web-based App

We have an enterprise application with a front end written in Microsoft Access 2003 that has evolved over the past 6 years. The back end data, and a fair amount of back-end logic is contained within several Microsoft SQL Server databases. This front end app consists of around 180 forms, and over 120,000 lines of code, and interacts with VB.Net DLLs that support various critical functions used by our sales force. The current system makes use of 3 monitors to display various information; the Access app uses COM+ to control Microsoft Outlook and Internet Explorer for various purposes. The Access front end sometimes occupies 2 screens, automatically resizing itself based on Windows API-reported screen dimensions. The app also uses a Google map to present data to our agents, and allows two-way interactivity with the map through COM+ connectivity to JavaScript contained in the Google map. At the urging of senior management, we are looking to completely rewrite this application using some web-based technology, such as ASP.Net or perhaps a LAMP stack (the thinking with the LAMP stack thing is "free" is pretty cheap). We want to move to a web-based app so we can eliminate the dependency on our physical location for hiring new sales force members. Currently, our main office is full to capacity, and we need to continue growing the company. Does anyone have any thoughts on what would be the best technology to use for a web-based app of this magnitude? Keeping in mind the app is dependent on back-end services on our existing infrastructure. The app handles financial data and personal customer data, among other things. [I've looked at Best practices for moving large MS Access application towards .Net? and read the answers, and most of the comments. Interesting reading, and has some valid points, but our C.O.O. and contracted Software Architect are pushing for a full web-based app, not a .Net Windows App]


Should I learn java for mobile application development or will C# just do?

I'm looking forward to delving into the .NET framework but most mobile applications seem to be developed in Java. I'll most probably be targeting the less pricier phones like Nokia and motorolla not android or iphone OS. Can I do these stuffs in C#?


At the end of my rope

I am a contractor to a big company. Currently, there are three developers on the project, myself included. The problem is the other 2 developers don't really get it. By "it" i mean the following:   * They don't understand the best practices for the technology we are using. After 6 months of me and others giving them examples there are terrible anti-patterns being used.   * They are "copy and paste" programmers that produce primarily spaghetti code.   * They _constantly_ break things, implementing changes but not doing a basic smoke test to see if all is good   * They refuse/rarely to ask for code-reviews.    * They refuse/rarely even do basic things like formatting code.   * No documentation on any classes (jsdocs)    * Afraid to delete code that doesn't do anything   * Leave commented code blocks everywhere even though we have version control. I find myself getting more and more frustrated as I format others code, fix bugs, discover functionality that is broken, and create abstractions to remove the spaghetti. I really don't know what to do. I try not to get to frustrated, but it's just a mess. I like these people as people, but I feel like the coding situation is so bad that I could move faster if they simply browsed the web all day. Would it be out of line to ask our manager to review the others svn commit access; commits can only be done after a review by someone who is knowledgeable in what we are doing? As a contractor, I'm not sure if that's the best move. Is there a subtle/not so subtle way of making it clear how many things I am fixing?


Is programming too easy if compared to other fields?

I have been programming since some years and I won't say its a piece of cake but in this field, you know how to do things. You can always google up resources, tutorials. There are tons of already written code to help you with - frameworks, libraries but if you compare it to other innovation fields like "Electronics". Its not too easy to get started with, the community might not be too large on the internet, getting the things right plus lets not forget there is nothing to tell you where the error might be. I have wanted many times but not be able to get into, like, building some kind of robot because I don't know how to start. So my question is that, does programming tends to be easy compared rest of the fields or is it just my interest that makes it easy?


What are good mathematical formulas to know for programming?

What are some somewhat common math formulas you learned that helped you write better algorithms and become a better programmer? Example: I learned about the ecludian distance formula: `sqrt((x1-x2)^2+(y1-y2)^2)` which helped me understand how to find like objects by comparing 2 factors.


Right license(s) for a freemium offer

I am currently working on a solution written in JavaScript. I plan to release two versions:   * For free: the lite one with base options, which is plug and play (it just works when loaded in the page)   * For a subscription fee: the full version that has more options and requires support I am wondering which license(s) would work for me. Here are my thoughts so far, feel free to correct me:   * MIT: I am concerned that somebody else might release new features on top of my solution, under a commercial license. It means that I wouldn't be able to add these same features to my own solution in the future.   * GPL: doesn't seem to work in my case, if I release the lite version under GPL then it means that I also need to release the full version for free.   * Dual licensing: I see that some frameworks or libraries offer dual licensing, but I am not sure how it works.


Best monitor for programming (eyes concerned)?

I currently need to buy a new monitor (my old one broke and I'm stuck with my laptops screen). What's a good choice for a monitor these days? I've been quite out of the loop. I'm mostly concerned with my eyes of course, and I need something that is good for reading text (programming obviously). With that said I don't really care about gaming and beautiful picture display... just text. Any studies done on this? What's the best monitor for reading text? I would prefer a brand name if possible.


Are Python sockets suitable for file synchronization?

I'm working in an organisation with limited funds. They can't afford a business account on Dropbox. However, they would find it useful to have all their files synchronized on local machines. I've recently looked at Python Sockets and it looks as though a custom script could achieve what they're looking for. I'm concerned that it may be too low- level because a library may exist that provides a lot of functionality and it would be a waste of resources to start from scratch. Is there a Python library/module that would provide what I'm looking for?


What is the equivalent of Entity Framework in the world of Oracle shops?

Within the world of developers/firms specializing in building/deploying solutions built around software built/sold by Oracle (aka "Oracle houses"), **what ORM middleware is considered as the "industry standard"** (if any), based on your experience? We have limited experience on Oracle's stack, so would appreciate insights from folks who have more experience in it. This might impact our product roadmap.


Does it matter to you that a software is "available source" but not "open source"

You probably know the list of open source licenses officially approved by the OSI. Most notably I guess would be the GPL, MIT, [insert your favorite license here]. I recently ran into a project which although was open source (the creator made all source code available), was not officially open source under one of those official licenses.   * It released the source, but made no promise to release the source in the future.    * It allowed modification suggestions, but made no promises to accept patches and disallowed external distribution of externally-patched versions.    * It allowed the use of the software in commercial or paid projects, but disallowed the sale of the software itself.  I suppose it could be called "available source" not open source as we like to think of it. I can see why the management team of a company wouldn't want to do business with this software. They can't fork it, they can't sell it, they can't create their own version of the software and distribute it or sell it. But would it matter to you as part of a software engineering team who's just using this software? I can still get my work done with it, I can use it in a project for which I'm paid (but I can't sell the software itself, which I'm not in the business of doing anyway), and I can make changes to the code to make it behave differently for my needs (but I can't make those modifications public), and if I do want those modifications officially made available to others, the approval is up to the project itself and they choose whether to incorporate them in an official release or not. So we know that a company that wants to base its business on this "available source" software can't do that, but as someone from the software engineering team, would those differences matter to you or do they seem less relevant? Curious what others think of this.


Which language came first with parallel assignment?

When I discovered that python has parallel assignment I thought is pretty cool. Recently I discovered parallel assignment works also in ruby. For people that don't know it: `x,y = y,x` in ruby, python this swaps x and y values . Which language came first with parallel assignment, python? or was it other language?


What do programmers have to know about business/management?

As I've implied through my other posts, I'm still fairly new to the workforce. During team meetings, I tend to be able to keep up with technical discussion, but when my project manager starts talking about how we've won a new contract, or we're involved in a new proposal bid, or... anything that's business rather than technical, really... I can get lost pretty quickly. What is the bare minimum all developers need to know about project management/business to function?


Should validation rules be tested?

If I have a method taking input and giving output, it's a no-brainer that tests should be written. But what about things like validation rules? For example, I add a validation rule that a certain property must be at least 5 characters long. Should I then write a UI test to check for an error message when the form field is empty? Assume that the validation library itself works fine, **the only thing I do is add a one-liner to specify this rule**. I'm leaning towards no, because I'd only be duplicating the validation rules, and if the rules itself are set up incorrectly, the test will probably also be incorrect. However, I'd very much like to hear people's opinion and experience on this.


Estimating file transfer time over network?

I am transferring file from one server to another. So, to estimate the time it would take to transfer some GB's of file over the network, I am pinging to that IP and taking the average time. For ex: i ping to 172.26.26.36 I get the average round trip time to be x ms, since ping send 32 bytes of data each time. I estimate speed of network to be 2*32*8(bits)/x = y Mbps --> multiplication with 2 because its average round trip time. So transferring 5GB of data will take 5000/y seconds Am I correct in my method of estimating time. If you find any mistake or any other good method please share.


What code lays behind C++ exception?

In C and C++ you can return a single variable inside a function. Now in the case that variable is returning data, and not an error code, you can use exceptions. But how is that possible? If you data being returned is the data you tell your function to return, then there is practically no way for the function calling it to know it's success (because the return is used for data, and not an error code). Also, the ability for a exception to literally stop the function in the middle of the code to return the error. How do C++ compilers achieve this?


Microchip XC8: How to pack code against an upper limit?

I have a project for a PIC16F1454 that needs some custom linking. Basically, I've separated my code into two parts that can be downloaded separately in the field and thus update (almost) all of the flash memory, including the bootloader. As part of the plan to avoid bricking itself, I have this structure:   * Lower, protected by hardware, not field-updateable:      * Startup and image-copy code, written in assembly   * Middle:      * Application space     * Also used to download new images   * Upper:      * Bootloader space And there's some code in various places that enforces that structure. The bootloader includes a USB stack, a main loop, and some helper functions that add up to slightly more than one page of flash, which causes some problems for the linker. For example, the help file says that this option is supposed to concatenate the entire list and put it against the specified upper limit (note the negative address):   * -L-pUSBCode=-1FFEh,USBConst,BootloaderCode,BootloaderConst But when I do that, all four psects overlap, with the usual, unintended consequences. I did this:   * -L-aBootloader=1400h-17FFh,1800h-1FFDh -L-dBootloader=2 -L-pUSBCode=Bootloader -L-pUSBConst=Bootloader -L-pBootloaderCode=Bootloader -L-pBootloaderConst=Bootloader which defines a class with 2-byte elements that crosses a page boundary at 1800h and puts all four psects in that class. While they didn't overlap, I got a big hole next to the page boundary, big enough for several of the helper functions to fit in. I could assign functions more granularly to more than four psects, and that would probably make things fit better, but I'd rather not make it any more complicated than I have to. Someone else (could be me after a few months) is probably going to modify it later, and I don't expect him to be intimately familiar with the details. How can I pack the entire bootloader section as tightly as possible into upper memory, accounting for the springboard to main() at 1FFEh-1FFFh, without requiring a future developer to change anything outside of the C source files?


Learning computer architecture as a programmer

I typically run across gurus at SO and other places (instructors, book authors etc.) that would say something along the lines `"This will cause alignment issues"` or other low level tidbits. I want to learn about all these tidbits that are `relevant` to programming. Now usually when I see low level books (computer architecture books for example) they are too low level and geared towards people whose primary area of interest is computer architecture and not software design. Do you have recommendations for books that go through low-level stuff that is relevant to programmers?


Do we need to install intel x86 Atom system image for all API levels?

I am new to Android development and just installed the new Android sdk with Eclipse and ADT bundle. From this question, I knew about installing Intel X86 system image. But, I have one confusion about installing intel x86 for which I couldn't find any solution on internet. In SDK manager, Intel x86 system image installation options are shown for each API level as in the picture. image is here (Since I have no privileges. Hope someone will correct it) So, my question is that, do we need to have intel x86 system image for all API levels? (I am making an application which will support from Android ICs to kitkat.)


How to track session replication?

I am working on a huge web application designed long back. I have to configure it so as to make it work on a cluster. I have configured a tomcat cluster for this purpose. Now I know I need to make the objects being added to the session serializable. For that I want to know what is being stored in my sessions, when I log in. Additionally how do I know (log maybe) that session state is being replicated among the tomcat workers?


Designing a simple file manager

I've been trying to come up with the best way to design my file manager for a project. I need to work with many file implementations and I have a File class made of 2 classes inside: Data and Descriptor. ![enter image description here](http://i.stack.imgur.com/iHuyC.jpg) As you can see, I have many different implementations of the Data class, one for each file organization. All of the implementations use records to organize their information but the fields for each kind of file (users, transactions, etc...) have to be stored as metadata inside their respective descriptor file. So basically my problem is trying to access and updating the descriptor of each file. For example, while trying to search() inside the Users file from the Stacked class, I need the fields (username, name, last name, etc...) which are inside the Users Descriptor file, but I cant come up with a nice design for it. The only way I can think of is passing the Descriptor reference to each method (search, write, etc...) but I have a feeling that my solution would be bad design. Please note that I still have to keep adding more file organizations for different files, so I want to plan ahead and have a nice file manager to handle all the requests the best way possible, but currently this is what I've come up with.


Can Foswiki be used as a distributed Redmine replacement?

I am quite familiar with and love using `git`, among other reasons due to its distributed nature. Now I'd like to set up some similarly _distributed_ (FOSS) Project Management software with features similar to what Redmine offers, such as   * Issue & time tracking, milestones   * Gantt charts, calendar   * git integration, maybe some automatic linking of commits and issues   * Wiki (preferably with Mathjax support)   * Forum, news, notifications   * Multiple Projects However, I am looking for a solution that does not require a permanently accesible server, i.e. like in git, each user should have their own copy which can be easily synchronized with others. However it should be possible to not have a copy of every Project on every machine. Since trac uses multiple instances for multiple projects anyway, I was considering using that, but I neither know how well it adapts to simply `git`ing the database itself (which would be be easiest way to handle the distribution due to git being used anyway), nor does it include all of Redmine's feature. After checking http://www.wikimatrix.org for Wikis with integrated tracking system and RCS support, and filtering out seemingly stale project, the choices basically boil down to Foswiki, TWiki and Ikiwiki. The latter doesn't seem to offer as many usability features, and in the TWiki vs Foswiki issue I tend to the latter. Finally, there is Fossil, which starts from the other end by attempting to replace git entirely and tracking itself. I am however not too comfortable with the thought of replacing git, and Fossil's non-SCM features don't seem to be as developed. Are there crucial features of Project Management software like Redmine that Foswiki does not provide even with all the extensions available?


How do I translate user input into a fictitious language?

For experimental reasons, I am trying to convert user input into a fictitious language. All of the translation can be 1:1. I would prefer if I could accomplish this with PHP. Should I use gettext and poedit? The fictitious language is not very large, I imagine I can do most of the translation 1:1 I have scoured the googles, but have only found dated code and localization.


Best way to break down overwhelming code into manageable chunks?

I'm continually becoming overwhelmed by large projects, once they reach a certain level of complexity. Once I reach a certain point in a project, my progress slows to a crawl and I find myself constantly retracing my steps and sorting out all kinds of confusion. I've gotten really good at refactoring due to this weakness of mine. And I always try to decompose my objects into smaller, more manageable ones. This weakness has also probably caused me to pay too much attention to designing things properly. I know if I can break my problems down into smaller ones, I'll be able to accomplish smoothly. One strategy that comes to mind is test-driven development. What else can I do?


Algorithm Analysis: Frequencies of Execution

I am currently reading the Analysis of Algorithms section in Algorithms, 4th Edition and I'm trying to understand how the author calculated **(N^2)/2** and **(N^3)/6** _frequencies of execution_ in the code snippet below (here is the full code):               public class ThreeSum     {         public static int count(int[] a) {                 int N = a.length;                 int cnt = 0;                 for (int i = 0; i < N; i++) { // <---------------- 1                     for (int j = i+1; j < N; j++) { // <---------- N                         for (int k = j+1; k < N; k++) { // <------ N^2/2                             if (a[i] + a[j] + a[k] == 0) { // <--- N^3/6                                 cnt++;  // <---------------------- x                             }                         }                     }                 }                 return cnt;             }      }      Why divide N^2 by 2? Why divide N^3 by 6?


If it was for you to chose Game Development vs Application Development, which will you chose?

Today I was asked if I want to do Game development or Application Development. I never thought to that I will ever do Games for a living. I will try it for a couple of weeks maybe but what are your thoughts on this topic? P.S. the apps or games will be for mobile devices.


Should Professional Development occur on company time?

As a first-time part-time software developer at a small consulting company, I'm struggling to organise time to further my own software development knowledge - whether that's reading a book, keeping up with the popular questions on StackOverflow, researching a technology we're using in-depth, or following the front page of Hacker News. I can see results borne from my self- allocated study time, but listing and demonstrating the skills and knowledge gained through Professional Development is difficult. The company does not have any defined PD policy, and there's a lot of pressure to get something deliverable done _now!_ when working for consultants. I've checked what my coworkers do, and they don't appear to allocate any time to self-improvement; they just work at the problems they're given, looking up specific MSDN references, code samples, and the like as they need them. I realise that PD policy is going to vary across companies of different size and culture, and a company like my own is probably a bit of an edge case. I'd love to hear views and experiences from more seasoned developers; especially those who have to make the PD policy choices in their team or company. I'd also like to learn about the more radical approaches to PD, even if they're completely out there; it's always interesting to see what other people are trying. Not quite a summary, but what I'm trying to ask:   * Is it common or recommended for companies to allocate PD time?   * Whose responsibility is it to ensure a developer's knowledge and skills are up to date?   * Should a part-time work schedule inspire a lower ratio of PD time : work?   * How can a developer show non-developer coworkers that reading blogs and books is net productive?    * Is reading blogs and books actually net productive? (references welcomed)   * Is writing blogs effective as a way of PD? (a recent theme on Hacker News) This is sort of a broad question because I don't know exactly which questions I need to ask here, so any thoughts on relevant issues I haven't addressed are very welcome.


Forgetting stuff I've done before and how do you fix this

I'm not sure if it's just me or if this is common in our field. The past year has been a bit intense for me. I've been learning a few different technologies to get some tasks done and sometimes I've had to completely focus on that one new technology I'm learning. What I noticed though when I go back to using everything together in the full project is that I forgot how to do things that I already knew how to do before I started focusing on learning that other new technology. Sometimes I find that I forget even simple things like the syntax for selecting a div in jquery, that I have to go back to old files to get a quick peek. Sometimes I could be coding something that I recognize I did before in another project, but can't quite remember which project it was for, so I have to go through several projects and look through the code to try and remember where I did that. What ways have you invented to prevent yourself from forgetting things you've done before, or to easily access code you've written in the past?


Is it always wrong to optimize before profiling?

I see the mantra of "profiling before optimization" repeated again and again here, on SO, and elsewhere. Although I certainly use profiling tools, I'm only occasionally surprised by the results. It seems like, as often as not, the profiler is just giving the same information that you could reasonably deduce by knowing the likely execution path of your program, understanding how your architecture works, and having a good idea of what optimization techniques the compiler can employ for you. Because of this, I generally find that when I'm developing, I see areas of the code that I can sense are going to be bottlenecks (often times when writing the code I will think to myself "hey, this is going to be a critical part of the code, and needs to be fast, but I will use a slower implementation first to prove the concept, then optimize it later") and I just go ahead and optimize these areas before I bother doing much profiling. Is this really such a bad practice, or is it just the natural result of gaining experience doing optimization? **Edit** I just wanted to point out that I _do_ use profilers, I'm just wondering how bad it's considered to be to pick off the low hanging fruit first, rather than waiting for the profiler to prove something is slow. **Edit 2** Thanks for the insights so far everyone. People have posted a lot of good comments. I have to say that I still have mixed feelings about some of the advice here, but it's given me a lot of insight into why people make the statement.


How to deal with a Team Lead who dislikes Extreme Programming?

From http://en.wikipedia.org/wiki/Extreme_programming Extreme Programming is a software development methodology which is intended to improve software quality and responsiveness to changing customer requirements. My Team Lead dislikes Extreme Programming as   * May take more time to complete the project.   * Increases initial cost (20% or more).   * Constant interaction is tiresome.   * Unit tests is hard for database, distributed and GUI. Is there any evidence to support these claims about Extreme Programming or are these fabrications? What arguments can be made where Extreme Programming can actually be harmful to a team or project?


Is there a way to update a client's database without seeing all his sensitive data?

A client has asked me to update his web app. At the last minute, he has expressed some concern about allowing me access to his database (and thus to sensitive client information), because this is the first time we have worked together and he doesn't know me. As far as I know, there is no way for me to work on this project without having full access to his database. I need to make updates to the database for one thing (adding columns, creating new tables etc). And I need to test the live app when I've updated it and I would be concerned not to have full database access. Is there a way I can work on his project without having access to his sensitive info? Many thanks


What is the best way to work with DAL and BLL?

I'm currently refactoring my DLL and BLL and I need some advice on what is the best way to work with DAL and BLL. My current solution is like this:               // DAL class only consists of SQL queries and returns SQL result     class DAL {            public function isBrandInList($brand)       {         $sql ="SELECT id FROM sl_label  WHERE name = '$brand'";             $this->query($sql);           return $this->query_result;        }          }          // BLL will process data from DAL and return data to whatever function called the BLL function.     class BLL extends DAL {            public function isBrandInList($name)       {         $result = parent::isBrandInList($name);              if(mysql_num_rows($result) > 0) {              while ($row = mysql_fetch_array($result)) {             return $row['status'];           }         } else {            return false;         }       }     }      I don't think this is the best way to work and my DAL file is getting over 1000 lines of code and has over 50 different classes. It's getting messy. My plan is to improve this and start using `MySQLi` / `PDO` and prepared statements. Can anyone tell me how I can improve the way I write my DAL and BLL? Should I create sub class in the DAL, e.g. one subclass for Person and one sub class for Brand? I've googled and looked at diffrent design patterns. Most of them are for .NET and they don't have any good examples. And maybe som links to some good articles? The ones I've found hasn't been the best. **UPDATE**   This is an example on how I do it today. The code below is just snippets and not the entire code.               //search.php       require_once('classes/search.class.php');         $search = new Search($_GET);       $result = $search->search();       echo $result;                //search.class.php     include('classes/bll.class.php');          class Search extends BLL {       private $store_term;            public function __construct($term) {         parent::__construct();         $this->get_search_term($term);           }          private function get_search_term($term) {}          public function search() {       if(!empty($this->store_term))         $result = $this->search_store();              return $result;     }          private function search_store() {        $result = parent::getStoresBySearch($this->store_term);       $html = 'Code for building html search result list here';       return $html;     }               //bll.class.php     class BLL extends DAL     {            public function __construct() {        parent::__construct();       }            public function getBrandsBySearch($term) {         $result = parent::getBrandsBySearch(mysql_real_escape_string($term));         return $result;       }     }          // dal.class.php     class DAL extends pdo {       public function __construct($cfg_file = 'sl.config') {         parent::__construct($this->dsn, $this->user, $this->pass);       }            public function getStoresBySearch($term)       {         $term = $term.'%';         $sql = "SELECT bla bla bla";         $sth = parent::prepare($sql);         $sth->setFetchMode(PDO::FETCH_ASSOC);         $sth->execute(array(':term'=>$term));         $result = $sth->fetchAll();             return $result;       }       }      I have a fealing that this might not be the best way to code?


xpath vs DOM API

I just came up on xpath recently while writing a greasemonkey script and immediately fell in love. I haven't done any benchmarking yet (coming soon), but according to a couple sources that I read, xpath is faster than using the DOM API. After checking out the internals of a couple of libraries (Swizzle and jQuery), I noticed that neither use xpath, but use the DOM API. My question is: Is there something here that I'm not seeing as to why these libraries haven't changed to use xpath (or were first written using xpath rather than the DOM API), or is it just that xpath just hasn't quite caught on yet?


wrap mysql API for gui use

Some time ago now, I've written a command-line tool, that connects to MySQL, and through a series of commands, does all sorts of good stuff. It was originally intended to be used by myself and, perhaps, by other developers.   Now, however, it's likely that non-devs will at some point be using this same tool, or at least a part of it. Given that many people sort of get nervous the moment you speak the forbidden words of death _terminal_ or _CLI_ , I've set about writing a rudimentary GUI using GTK+. For obvious reasons, I kept things nicely separated, and only made those functions that the GUI tool needs to support visible.   But here, I ran into trouble. My code uses an unknown number of prepared statements. So far, I have been passing those around from function to function. I don't want to do this in my GUI code, of course. (I know, it's bad enough that I am doing this in the CLI version, and I do want to re-write chunks of that code, too).   So far, I've come up with 3 ways of fixing this. Effectively, I find myself having to write a wrapper-API around those bits and bolts of the MySQL API that need to be exposed. But which is the best? What are the down/up-sides of each approach? Am I missing the obvious fourth approach? Here are the options I'm currently considering:   * write a simple header with typedefs, and some macro's (`MAKE_STMT("My query")` sort of things, and prefix all types relating to the MySQL API with `DB_` or something.   I don't fancy this, simple because the GTK+ API is quite similar, and it tends to make code look, to my eye at least, a tad messy. It also doesn't really solve the issue, but rather masks it.   * Use a global hash table, or simple array in the mysql code, and allocate memory for each prepared statement I need, and return its offset/hash. I can then pass that around in my CLI/GUI code, and use a function like `execute_stmt(int offset, struct param_list *params);` which can then use the `offset`.   This is the approach that I'm likely going to use ATM, simply because this has to be the most straightforward way to keep db-related data out of the front- end code   * use `void *` in front-end code and macro's that cast & call the right functions at the right time. I'd hate to use this approach, but at least I can check for `NULL` pointers, and not leave error reporting/handling to the DB code, which doesn't know if the program is running in CLI or GUI mode (and I'd like to handle errors differently in both cases).   * Perhaps a last alternative, and this is what I'm currently doing, given I've not set about reworking the CLI code, is using separate .h files. Possibly expanding this further into 3 .c files: 1 for common functions, 1 for CLI specific code, and 1 for GUI code.   I'm probably bound to end up with something like this, but then the question remains: what is the best way to keep MySQL-related code as far away as possible from the UI code?


How can I transition from being a freelance PHP developer to working for a company?

I've been a freelance web developer for about three years, mostly dealing with non-framework based PHP projects. I'm thinking of moving on to an employer-based job, but I'm not sure what will be expected of me or how to prepare for the transition. What technologies, concepts, and patterns should I be focusing on to ensure I don't crash and burn once I leave the life of freelancing? What can I do to prepare myself for developing as part of a team?


Is SOA as a concept intended to function within code or between machines over a network?

As the question states: When implementing "SOA", is it a concept intended for communication between systems over a network or is it intended as a concept that operates within the language as a pattern?


How much documentation is enough?

How much technical (for future developers) documentation is _enough_? Is there a ratio between hours coding and hours documenting that's appropriate? Papadimoulis argues that you should > produce the least amount of documentation needed to facilitate the most > understanding, Is that a good guideline, or are there specific things I should be creating?


Is there any design pattern except MVC for web?

I want to know are there any design patterns for web besides MVC? I know there are design patterns as: Registry, Observer, Factory, ActiveRecord ,... and MVC a set of other design patterns and folder structure. Is there design pattern like MVC is a set of other design patterns? Edit : my programming language is PHP.


How do you make slides for programming talks?

I've given a few talks recently and I have not found a good way to make slides. Here are a few desirable characteristics for programming slides:   * They're slides. A standard emacs buffer won't do it.   * They have syntax highlighting for code.   * They support _basic_ formatting, like font size and color and bullets.   * No fancy animations needed. The only animation I desire is one-by-one appearance of bullets.   * EDIT: It should be easy to alt-tab back and forth from the terminal to the slides without destroying the presentation sequence/position. So far I have considered:   * Microsoft Office - out of the question for Linux users.   * OpenOffice.org - too much for my needs, code formatting/highlighting needs to be done externally and pasted in. On the plus side supports bullets, bullet-by-bullet animation, and font formatting. To my knowledge there's no way around the fact that alt-tab to the terminal destroys presentation mode and position.   * Emacs - Supports all the code formatting but I haven't found a _slides_ mode that lets me transition from one chunk to another.   * HTML5 - I once made slides using html5rocks as a template. It supports everything, but is too hard and time-consuming to "throw together" a few slides before a minor talk. Also the html5-only features may not work on the podium computer's installed browser. Any suggestions for programs/techniques for making code-centric presentations? EDIT: I think S5 and Latex are most in the spirit of what I'm looking for, but that's not to say the other suggestions (including not using slides at all) are "wrong".


How to convince my boss to switch to OOP PHP?

We have been trying for months to convince my boss to switch to OOP php, but each time, he takes out his previous experience with programming and convinces us other wise. i need to talk like a boss to him, tell me how do i convince him? I need to make him understand the long term benefits and also financial benefits. One arguments he used today was that it was not optimum for performance, like each time you need to make a conection to the database, you need to create a new object each time. Please help me.


How much should I know before looking for an internship? (self-taught with math background)

The only formal education I received is 2.5 years as a major in pure maths with computer applications (sounds like an oxymoron, but basically it's pure maths with some courses on algorithms, discrete maths with some CS applications, and a little cryptography with number theory). I dropped out (due to personal, not academic reasons). I'm not even sure if an incomplete BS. Degree is worth mentioning in a resume. Since leaving school this year, I've been focusing on learning back-end web development (PHP, MySQL, CSS/HTML; I've only played with js). I spend all day waiting for the moment I can sit back at my computer and do what I love... whatever the pay, I'd jump at the opportunity of leaving my job and doing something related to web programming. My only concern is that, lacking a formal education / advisor, I've no idea what is expected of an intern. I've worked through all your basic "standard" tutorials (forms, building a MySQL database, queries, etc.). I'm now reading Code Complete, relational algebra, Wordpress code, learning the essentials of a low-level language (C, understanding pointers, memory, and so forth). I'm building my own WP theme framework from scratch (with reuse and readability in mind)... but watching the people here at SE, it's clear that I know very little. It's pretty intimidating. **Just how much is one supposed to know before considering a first internship? At what level should I be and how will I know when I'm there?** For what it's worth, judging by the "Programmers' Competency Matrix", this is where I'm at in the following categories:   * Computer Science: I know all level 0's and one level 1.   * Software Engineering: two level ones and one zero (well, sort of: I only know git, and not a whole lot).    * Programming: five level 1's, four level 2's, three level 3's, three 0's.   * Experience: three 0's, one level 1.   * Knowledge: five level 1's, one 0, one 3. So basically mostly `1`'s and `0`'s... low level indeed.


Have you ever found a bug you can't solve? What do you do in that case?

We're developing a hosted CMS, something like WordPress.com. When we were creating the **Image Gallery module** , we examined many jQuery libraries like **easySlider** , **jCarousel** , and **Nivo Slider**. But each of them had some kind'of weird bug across browsers. We almost put 2 days into finding where the bug was from. But we couldn't find the problem source. The most important reason could be that our system is now is complex. Here are the problems:   1. easySlider sliding were not transitional and was abrupt.   2. jCarousel were sliding images half to their width in IE.   3. Nivo Slider didn't hide the last-shown image, thus was not suitable for and image gallery with heterogeneous images. We just concluded that we need to find a library which can work without bug, and we searched and found one. But my question is, is it normal for large projects that the source of a bug cannot be found and instead, it's located with trial-and-error and you simply flee from the bug? Do you have such an experience?


C++ to friend or not to friend

I have an object oriented programming with c++ course this semester at college and we were learning about friend functions. I instinctively dislike them for their ability to bypass the security that Encapsulation and Data hiding provide, I read a few articles on the internet and some people thought that it was a good idea with some legitimate uses. What would an OOPs expert say about friend fucntions in C++? Should I just skim over it or should I learn more about it?


Is PHP suitable for downloading large amounts of data?

Is PHP suitable for downloading large amounts of data, usually via cron? Should I worry about the memory footprint when I am using PHP for downloading multiple zip files?