答:
Generally speaking, more normalization is good for several reasons:

Less duplication of data, leading to a smaller physical database size.

Better data integrity - you can use foreign keys to enforce certain requirements.

Simpler update code, which you've identified.

More indexable access routes to subsets of data.

Disadvantages (described well here) include:

Normalization saves space, but space is cheap.

Normalization simplifies updates, but reads are more common.

Performance is generally better with less-normalized schemas.

I would suggest starting with a more normalized design, and only consider denormalizing if you run into performance problems.

Title: When accessing/manipulating complex data, is it better to store it in many small pieces or one large chunk?

Body:
I am building a web app that manipulates fairly complex data: guitar tabs.

```<code>    As a reference, guitar tabs look like this:
Eb|-------------------------------------------------------------------------|
Bb|-------------------------------------------------------------------------|
Gb|--5-5-5-5----------------------------------------------------------------|
Db|--5-5-5-5--3-3-3-3--7-7-7-7--5-5-5-5--2-2-2-2--3-3-3-3--2-2-2-2--5-5-5-5-|
Ab|--3-3-3-3--3-3-3-3--7-7-7-7--5-5-5-5--2-2-2-2--3-3-3-3--2-2-2-2--5-5-5-5-|
Eb|-----------1-1-1-1--5-5-5-5--3-3-3-3--0-0-0-0--1-1-1-1--0-0-0-0--3-3-3-3-|
</code>```

Would it be more efficient for performance to store this data as a large chunk, or to break it up and store it on a "note by note" basis?

```<code>As a use case:
User changes first chord from:       to:
                         Eb|---   Eb|---
                         Bb|---   Bb|---
                         Gb|--5   Gb|--4
                         Db|--5   Db|--4
                         Ab|--3   Ab|--2
                         Eb|---   Eb|---
</code>```

If I store it as a block, the code to manipulate the tabs would have to be much more complex. If I store it note by note, the database will have to be accessed a lot more. Which method is more efficient? Potentially, a lot of users will be modifying the data. I want the best performing web app. I will be using MySQL if that affects the answer at all.


问:
Where do you draw the line between quantity and quality?
My manager has talked with me and says that the quality of my work is excellent, but I need to step up the quantity of how much I crank out. I've only been working for a couple of years, so I still feel like I have a lot to learn. Which route do I take (or is there another?):

Quantity: If they want crap, I can give them lots of it.

Quality: Ignore the request, and hope that my productivity will increase with experience.

答:
Quality code will, in the long run, cost you less time to maintain.  Also, in theory, you should be reducing the time your QA team needs to test your code because there will be less bugs for them to document.  Finding ways to reuse components you've already coded or are in the process of coding will speed up your apparent quantity.

I would stick with quality if given the choice.  I'd rather be known for high quality code then for being able to spew out a lot of junk.

ContentLicense: CC BY-SA 2.5


问:
What is Global Delivery Model?
Many software companies preach in their Website Banners: "Global Delivery Model". Has it anything to do with Deployment?</p>

答:
"Global Delivery Model" has nothing to do with software "Deployment".

Theory:

The term Global Delivery Model is typically associated with companies engaged in IT consulting and services delivery business and using a model of executing a technology project using a team that is distributed globally.

Practice:

Actually this is a marketing term is used by software services companies(mostly offshore companies) who have their team distributed globally to provide 24/7 support, less cost etc to attract clients when bidding on a project.

more details @ http://en.wikipedia.org/wiki/Global_delivery_model

ContentLicense: CC BY-SA 3.0

Title: What is Global Delivery Model?


问:
When accessing/manipulating complex data, is it better to store it in many small pieces or one large chunk?
I am building a web app that manipulates fairly complex data: guitar tabs.

```<code>    As a reference, guitar tabs look like this:
Eb|-------------------------------------------------------------------------|
Bb|-------------------------------------------------------------------------|
Gb|--5-5-5-5----------------------------------------------------------------|
Db|--5-5-5-5--3-3-3-3--7-7-7-7--5-5-5-5--2-2-2-2--3-3-3-3--2-2-2-2--5-5-5-5-|
Ab|--3-3-3-3--3-3-3-3--7-7-7-7--5-5-5-5--2-2-2-2--3-3-3-3--2-2-2-2--5-5-5-5-|
Eb|-----------1-1-1-1--5-5-5-5--3-3-3-3--0-0-0-0--1-1-1-1--0-0-0-0--3-3-3-3-|
</code>```

Would it be more efficient for performance to store this data as a large chunk, or to break it up and store it on a "note by note" basis?

```<code>As a use case:
User changes first chord from:       to:
                         Eb|---   Eb|---
                         Bb|---   Bb|---
                         Gb|--5   Gb|--4
                         Db|--5   Db|--4
                         Ab|--3   Ab|--2
                         Eb|---   Eb|---
</code>```

If I store it as a block, the code to manipulate the tabs would have to be much more complex. If I store it note by note, the database will have to be accessed a lot more. Which method is more efficient? Potentially, a lot of users will be modifying the data. I want the best performing web app. I will be using MySQL if that affects the answer at all.

答:
Make your storage easiest to work with, and hard enough to screw up. Go with a reasonably normalized schema. Go with a schema that does not preclude usages other than you will need in your first release, if possible.

If all you need is to show tabs for a particular song, you could store lots of 6-tuples in a document-oriented DB (like MongoDB), fetching them as one document.

In an RDBMS, I'd store it similarly, in a table like this:

```<code>table tab_column (
  song_id integer not null foreign key references song(id),
  ordinal integer not null, -- position in the tabulature
  s1 number(2), -- position on 1st string
  ...
  s6 number(2),
  primary key(song_id, ordinal)
)
</code>```

RDBMSes are good at simple queries like the one needed to show a song:

```<code>select * from tab_column
where song_id = :song_id
order by ordinal;
</code>```

Using limit and offset, you can show parts of a song.

Later it will be easy to link tab_column to a table that lists named chords, if you can recognize a chord.

This is probably the simplest schema possible; I'd start with it.

Body:
Make your storage easiest to work with, and hard enough to screw up. Go with a reasonably normalized schema. Go with a schema that does not preclude usages other than you will need in your first release, if possible.

If all you need is to show tabs for a particular song, you could store lots of 6-tuples in a document-oriented DB (like MongoDB), fetching them as one document.

In an RDBMS, I'd store it similarly, in a table like this:

table tab_column (
  song_id integer not null foreign key references song(id),
  ordinal integer not null, -- position in the tabulature
  s1 number(2), -- position on 1st string
  ...
  s6 number(2),
  primary key(song_id, ordinal)
)

RDBMSes are good at simple queries like the one needed to show a song:

select * from tab_column
where song_id = :song_id
order by ordinal;

Using limit and offset, you can show parts of a song.

Later it will be easy to link tab_column to a table that lists named chords, if you can recognize a chord.

This is probably the simplest schema possible; I'd start with it.


问:
Trying to grasp the idea of DI/Unity and possibly apply it to our simple application
Our app basically is a few forms that are filled out by people.. Then these forms are validated and reviewed and reports are created..

So I was thinking about DI and messing with a simple example of Unity + MVC

http://netmvc.blogspot.com/2012/04/dependency-injection-in-aspnet-mvc-4.html

So could it be useful for something or overkill ?  It seems to me the idea behind DI is to dynamically grab objects of a different type.. So in my case maybe those can be a set of rules for validation of a form... Something like SyntaxRules1.dll, BusinessRules1.dll, CalculationRules1.dll...  So then as time goes by maybe additional sets of rules would be created so I can drop another DLL like BusinessRules2.dll in a folder and DI would pick it up in the boot strapper..

But then again if it changes very little then using DI might be pointless and just be a layer of abstraction that is not needed..

Do I have the right idea? Is there any other ideas how DI could be useful for this type of app  ? Could I make the entire view/controller/model or each form its own DLL ?  That make sense ?

I just read alot of theory and struggling to find some concrete examples of what DI can do.

答:
It seems to me the idea behind DI is to dynamically grab objects of a different type

No, it isn't. DI stands for Dependency Injection. The idea is that instead of classes instantiating the classes/services that they need in order to operate, these are passed in to them (i.e. injected) - this is normally done either on the constructor or through public properties.

Writing classes in such a way allows you do have a more modular structure to your code and means that the user of a class (the calling code) needs to pass in the dependencies.

This concept is that of Inversion of Control (IoC), which uses DI to achieve this goal.

Where an IoC container like Unity comes into play is that it allows you to determine in configuration (which can be strongly typed fluent code configuration) how to provide a class with its dependencies.

Now, I would argue that DI is a useful technique in any application. It allows you to write more testable code and allows you to test your code in isolation (meaning without having to draw in the dependencies). Mocking frameworks help in this respect.

An IoC container, on the other hand, is probably overkill for a small and simple application. It is handy in cases where you have chains of dependencies or many dependencies in the codebase.

The example you have given - picking up rules dynamically sounds like something that would be better achieved using a plugin architecture, possibly using MEF. It is not something directly related to DI or IoC.


答:
I have done what you're talking about using Unity with a slight change in your perception of Dependency Injection (DI). All dependency injection means is that you pass in an instantiated class type into your class's constructor rather than having your class instantiate that type.

As one previous poster stated, this is good for testing purposes as you can write test code for your class and pass in different instantiated types to test your class functionality.

However, to do what you're asking in regards of passing in BLL, you would use DI but instead of passing in your BLL class, you would pass in a service/controller object that would return an appropriate BLL. That service object would internally know which BLL to return based on functionality that you created. That service object could be an Interface type with a function like getBLL(myCustomerNumber);

The dynamic part comes in as Inversion of Control (IOC). So, in terms of IOC, you would register your service (the class that knows which BLL to return) to that interface type. Therefore, every time that service is referenced in a class constructor, unity would use the service (class) that was registered to pass into the constructor.

Please take note: With unity, you can register/create a class/service with/without a life time manager. This is important to research because if you don't have a LifeTimeManager, the registered class will be created every time it is referenced. With a LifeTimeManager, it will be created once in the system and used throughout the system. You may want this in certain circumstances and others you may not.

Title: Trying to grasp the idea of DI/Unity and possibly apply it to our simple application

Body:
Our app basically is a few forms that are filled out by people.. Then these forms are validated and reviewed and reports are created..

So I was thinking about DI and messing with a simple example of Unity + MVC

http://netmvc.blogspot.com/2012/04/dependency-injection-in-aspnet-mvc-4.html

So could it be useful for something or overkill ?  It seems to me the idea behind DI is to dynamically grab objects of a different type.. So in my case maybe those can be a set of rules for validation of a form... Something like SyntaxRules1.dll, BusinessRules1.dll, CalculationRules1.dll...  So then as time goes by maybe additional sets of rules would be created so I can drop another DLL like BusinessRules2.dll in a folder and DI would pick it up in the boot strapper..

But then again if it changes very little then using DI might be pointless and just be a layer of abstraction that is not needed..

Do I have the right idea? Is there any other ideas how DI could be useful for this type of app  ? Could I make the entire view/controller/model or each form its own DLL ?  That make sense ?

I just read alot of theory and struggling to find some concrete examples of what DI can do.


问:
How to manage contextual objects without IoC container (session or passing around objects)?
I'm using asp.net (c#). I have a factory that uses a dictionary of keys that are mapped to objects types. I originally used a static variable to track the dictionary but realized it would be shared among all sessions. Then I'm left with the idea of passing the object map around everywhere, which seems messy.

Should object maps or other contextual items get passed around, stored in the session, or should I just create a new instance each time I need one (in the case of non-contextual items)? I'm not using an IoC container. An example of a non-contextual item in my case would be mapping text commands that come in from the client to objects.

In general it seems there is no good way to deal with contextual data without at least having a static object that pulls the values from a session. Otherwise I am stuck with passing tons of context objects around everywhere they are needed. Surely there is a good pattern for handling contexts, object maps, etc. without using session to store everything?

答:
static variable to track the dictionary but realized it would be shared among all sessions. Then I'm left with the idea of passing the object map around everywhere, which seems messy.

Generally : cache data, but recreate objects on each request

Storing too much in the session is a terrible mistake; static variables tend to be even worse (especially with ObjectContext and DBContext)

Creating objects is not nearly as expensive as an IO operation and therefore isn't considered a spot you'd want to try optimizing by storing objects in the session.  Although it is a good idea to make your object initialization do as little processing as possible.  Look into Lazy to see the preferred way of delayed initialization.


问:
What's your favourite quote about programming?
What's your favourite quote about programming?

One quote per answer, and please check for duplicates before posting!

答:
As formulated by Eric S. Raymond:

Linus's Law

Given a large enough beta-tester and co-developer base, almost every problem will be characterized quickly and the fix obvious to someone.

Or, less formally,

Given enough eyeballs, all bugs are shallow.

LastEditorDisplayName: Roger Pate


答:
It is a matter of how you define quantity?

Number of lines?
-- Bad metric

Use cases addressed
-- Good Metric

To me it is a matter of perspective.  If I write 10k lines of code to solve a problem and another needs merely 200 lines of code along with an open source library which is more productive?  A matter of opinion.

However, when it comes down to it your manager is the one making these opinions so you need to understand how he places metrics of developers productivity and how does he explicitly quantify quantity for you to better understand.

Title: Where do you draw the line between quantity and quality?

Body:
My manager has talked with me and says that the quality of my work is excellent, but I need to step up the quantity of how much I crank out. I've only been working for a couple of years, so I still feel like I have a lot to learn. Which route do I take (or is there another?):

Quantity: If they want crap, I can give them lots of it.

Quality: Ignore the request, and hope that my productivity will increase with experience.


问:
What is the alternative to an enterprise portal strategy in the Java space?
Disillusionment with the Portal Space

I'm seeing a disturbing number of large, enterprise clients who have become disillusioned with their enterprise Portal experience, especially those in the WebSphere Portal Server (WPS) space. Millions have been invested, yet the promise of personalized content with aggregation and integrated collaborative tools has never come to fruition. The move to WPS 7.x is a big rip and replace move, and clients are wondering if they should move somewhere else completely.

Portal Software: A horrible option, but what's the alternative

There are loads of Portal haters out there, and sometimes a portal solution is indeed overkill, but when you're talking about large, multi-national corporations, how would one recommend they architect a global solution without a portal server?

Portals aren't always as fun to work with as Tomcat or JBoss AS, but when it comes to integrating multiple applications, managing content, updating individual applications that are deployed as individual war files, managing security down to the portlet level, proving a certain amount of personalization to users, and help with the overwhelming task of managing the thousands of pages large scale enterprises have as part of their internal and external websites, is there a better technology out there?

Garnering community insight and feedback

I've been trying to garner as much insight as possible. I wrote a little article on TSS about the issue:

Which other alternatives to portal exists on market?

I'm also resurrecting a thread at the CodeRanch to see if I can get any insight from that handsome crew.

Updated Thread Asking for an Alternative to a Portal Software Stragety. Circa 2012

I'm also looking for some insight from the twitterati (@potemcam).

It's not so much a cross-posting as much as it is an attempt to really gather some keen insight from the community. If I can get some solid responses and experiences, I'd like to aggregate them into an advice article over at TSS.

What is the right alternative to an enterprise Portal in the Java space?

By the way, I'll be cross-linking to this question from the other sites as well so people with the same questions will be able to bounce back and forth and see what the community is saying on this topic.

答:
First, you need to consider what problems Portal was designed to solve.  Is it, as Wikipedia suggest, to bring together information from diverse sources in a unified way?  If so, what other ways do we now have to do this?

Well, first, how do you bring together information from diverse sources?  The obvious answer is to call a variety of (web) services.  This introduces issues of contracts and network latency, blah blah blah, but these are things poorly solved by portal, so it's your call.  Suppose the services are RESTful?  Does that make managing contracts easier?  Possibly.

Then, how do you unify the information?  One of the issues that Portal solved was how to bring these disparate items onto one page, and have them load independently.  AJAX has grown up since then, and the same effect can potentially be handled using XMLHttpRequest calls to the various (RESTful?) services to get your data, and then using a shared set of style sheets.

Will this work?  It can and does.  Is it more manageable than JSR286 portal servers?  Probably.  Are there still a ton of issues to overcome?  Definitely.  But it's a viable alternative.


答:
I don't agree with Matthew, none of the issues with enterprise portals are caused directly by the technology. The problem is almost always a lack of clear focus and direction.

What is the problem you are trying to solve? Try and nail it down to some specifics. I can probably guess that move information out of email in-boxes on to some searchable content solution will come fairly high. As will finding information that lives on shared network drives. Then there's probably a question around workflow.

Beyond that it starts to get a bit nebulous and that's where the solutions fail. If anyone tries to sell you a portal with a demo showing an unrelated team searching for information on his problem and finding another team has already solved that problem isn't recognising how people work.

I don't want this to turn into a long waffle, so I'll ask one question. Does your portal solution allow you to share information with your peers as easily as your email client? Specifically, my application crashed and I want to send you a screen shot. I can paste that straight into my email, that won't work with web based solutions. Does it integrate with Office? Who is going to get all the existing information onto the portal?

Focus on the people, their interactions and their needs and forget the technical first. Second, moderate the people's expectations and wishes with a dose of reality.

Title: What is the alternative to an enterprise portal strategy in the Java space?

Body:
Disillusionment with the Portal Space

I'm seeing a disturbing number of large, enterprise clients who have become disillusioned with their enterprise Portal experience, especially those in the WebSphere Portal Server (WPS) space. Millions have been invested, yet the promise of personalized content with aggregation and integrated collaborative tools has never come to fruition. The move to WPS 7.x is a big rip and replace move, and clients are wondering if they should move somewhere else completely.

Portal Software: A horrible option, but what's the alternative

There are loads of Portal haters out there, and sometimes a portal solution is indeed overkill, but when you're talking about large, multi-national corporations, how would one recommend they architect a global solution without a portal server?

Portals aren't always as fun to work with as Tomcat or JBoss AS, but when it comes to integrating multiple applications, managing content, updating individual applications that are deployed as individual war files, managing security down to the portlet level, proving a certain amount of personalization to users, and help with the overwhelming task of managing the thousands of pages large scale enterprises have as part of their internal and external websites, is there a better technology out there?

Garnering community insight and feedback

I've been trying to garner as much insight as possible. I wrote a little article on TSS about the issue:

Which other alternatives to portal exists on market?

I'm also resurrecting a thread at the CodeRanch to see if I can get any insight from that handsome crew.

Updated Thread Asking for an Alternative to a Portal Software Stragety. Circa 2012

I'm also looking for some insight from the twitterati (@potemcam).

It's not so much a cross-posting as much as it is an attempt to really gather some keen insight from the community. If I can get some solid responses and experiences, I'd like to aggregate them into an advice article over at TSS.

What is the right alternative to an enterprise Portal in the Java space?

By the way, I'll be cross-linking to this question from the other sites as well so people with the same questions will be able to bounce back and forth and see what the community is saying on this topic.


问:
Is it inefficient to concatenate strings one at a time?
I recall back from my days of programming in C that when two strings are joined, the OS must allocate memory for the joined string, then the program can copy all the string text over to the new area in memory, then the old memory must manually be released. So if this is done multiple times as in the case of joining a list, the OS has to constantly allocate more and more memory, just to have it released after the next concatenation. A much better way to do this in C would be to determine the total size of the combined strings and allocate the necessary memory for the entire joined list of strings.

Now in modern programming languages (C# for instance), I commonly see the contents of collections being joined together by iterating through the collection and adding all the strings, one at a time, to a single string reference. Is this not inefficient, even with modern computing power?

答:
Strictly speaking it is less efficient use of CPU cycles, so you are correct. But what about developer time, maintenance costs etc. If you add the cost of time to the equation, it is almost always more efficient to do whats easiest, then if needed, profile and optimize the slow bits.

"The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet."


答:
It is not efficient, roughly for the reasons you described. Strings in C# and Java are immutable. Operations on strings return a separate instance instead of modifying the original one, unlike it was in C. When concatenating multiple strings, a separate instance is created at each step. Allocating and later garbage collecting those unused instances can cause a performance hit. Only this time memory management is handled for you by the garbage collector.

Both C# and Java introduce a StringBuilder class as a mutable string specifically for this type of tasks. An equivalent in C would be using a linked list of concatenated strings instead of joining them in an array. C# also offers a convenient Join method on strings for joining a collection of strings.

Title: Is it inefficient to concatenate strings one at a time?

Body:
I recall back from my days of programming in C that when two strings are joined, the OS must allocate memory for the joined string, then the program can copy all the string text over to the new area in memory, then the old memory must manually be released. So if this is done multiple times as in the case of joining a list, the OS has to constantly allocate more and more memory, just to have it released after the next concatenation. A much better way to do this in C would be to determine the total size of the combined strings and allocate the necessary memory for the entire joined list of strings.

Now in modern programming languages (C# for instance), I commonly see the contents of collections being joined together by iterating through the collection and adding all the strings, one at a time, to a single string reference. Is this not inefficient, even with modern computing power?


答:
Your explanation why it is inefficient is accurate, in at least the languages I am familiar with (C, Java, C#), though I would disagree that it is universally common to perform massive amounts of string concatenation.  In the C# code I work on, there is copious usage of StringBuilder, String.Format, etc. which are all memory saving techiniques to avoid over-reallocation.

So to get to the answer for your question, we must ask another question:  if it's never really an issue to concatenate strings, why would classes like StringBuilder and StringBuffer exist?  Why is the use of such classes included in even semi-beginner programming books and classes?  Why would seemingly pre-mature optimization advice be so prominent?

If most string-concatenating developers were to base their answer purely on experience, most would say it never makes a difference and would shun the use of such tools in favor of the "more readable" for (int i=0; i<1000; i++) { strA += strB; }.  But they never measured it.

The real answer to this question could be found in this SO answer, which reveals that in one instance, when concatenating 50,000 strings (which depending on your application, may be a common occurence), even small ones, resulted in a 1000x performance hit.

If performance literally doesn't mean anything at all, by all means concatenate away.  But I would disagree that using alternatives (StringBuilder) is difficult or less readable, and therefore would be a reasonable programming practice that shouldn't invoke the "premature optimization" defense.

UPDATE:

I think what this comes down to, is know your platform and follow its best practices, which are sadly not universal.  Two examples from two different "modern languages":

In another SO answer, the exact opposite performance characteristics (array.join vs +=) were found to be sometimes true in JavaScript. In some browsers, string concatenation appears to be optimized automatically, and in other cases it isn't.  So the recommendation (at least in that SO question), is to just concatenate and not worry about it.

In another case, a Java compiler can automatically replace concatenation with a more efficient construct such as StringBuilder. However, as others have pointed out, this is indeterministic, not guaranteed, and using StringBuilder doesn't hurt readability. In this particular case, I would tend to recommend against the use of concatenation for large collections or relying on an indeterministic Java compiler behavior.  Similarly, in .NET, no optimization of the sort is performed, ever.

It's not exactly a cardinal sin to not know every nuance of every platform right away, but ignoring important platform issues like this would almost be like moving from Java to C++ and not caring about deallocating memory.


问:
A single language to learn to develop desktop and mobile phone applications?
Is there a language that is capable of developing apps to cross platform OSs (win,*nix) and mobile apps (IOS, android) ..
I'm a pro web developer but want to explore more environment to deploy my code into...

Python ? Ruby ?

答:
You should learn python in that case, because python is used in wide number of areas like desktop applications, game scripting, android apps, web frameworks.

top companies using python:

Google

youtube

Facebook

Dropbox

Quora

and many more... the list is huge


问:
How does agile estimate the time required for a "research phase"?
According to canonical agile development, what is the appropriate amount of learning that an engineer should engage in before implementing a solution to a problem?

If an engineer knows she is too ignorant of a given topic (say, compression) to start implementing, she goes and learns what she thinks she needs to know, and then implements a solution.

Clearly a deeper understanding of said topic could result in a better implementation, but at the cost of agility. On the flip side if an engineer learns too little about a topic, there is a danger she will implement a significantly insufficient / broken implementation that negatively affects customers in the immediate or near future. In some cases, not a lot of research is required, and in some cases developers are faced with a topic even the senior-most developer knows little to nothing about, so the answer to this question includes an element of scalability to meet both situations.

Towards which end of this scale, if any, do guiding principles of agile lead an engineer? Or does agile leave this as a sliding scale, where the answer may be different in any given situation?

In other words, I'm looking to understand not when/how inside agile development research happens, but moreover how to estimate a "good" amount of time to spend learning a topic in the research phase before moving on to implementing a solution.

答:
Just because you're agile doesn't change the implementation process, it just shrinks it into 2 week chunks. Include research/prototyping into your estimates, and note the added risk due to unfamiliarity.

You might tend towards less research since ideally refactoring is more common/easier, but it depends on your environment.

edit: After doing some research based on the first comment, it appears as though it varies. Some teams do not make stories available until they're designed, which likely involves research/prototyping. Slightly related question.

Personally, I've always seen/used the view that tasks are 'the steps needed to complete the story' and thus research should be spelled out there (or at least included in estimates if expected to be short).


答:
An agile team may consider a research spike when learning is required.

But that team should respect a lead developer's judgement when considering the length of time that the research should take. Indeed, the research spike's duration is entirely dependent upon the complexity of the targeted user story and the skill level of the team.

Title: How does agile estimate the time required for a "research phase"?

Body:
According to canonical agile development, what is the appropriate amount of learning that an engineer should engage in before implementing a solution to a problem?

If an engineer knows she is too ignorant of a given topic (say, compression) to start implementing, she goes and learns what she thinks she needs to know, and then implements a solution.

Clearly a deeper understanding of said topic could result in a better implementation, but at the cost of agility. On the flip side if an engineer learns too little about a topic, there is a danger she will implement a significantly insufficient / broken implementation that negatively affects customers in the immediate or near future. In some cases, not a lot of research is required, and in some cases developers are faced with a topic even the senior-most developer knows little to nothing about, so the answer to this question includes an element of scalability to meet both situations.

Towards which end of this scale, if any, do guiding principles of agile lead an engineer? Or does agile leave this as a sliding scale, where the answer may be different in any given situation?

In other words, I'm looking to understand not when/how inside agile development research happens, but moreover how to estimate a "good" amount of time to spend learning a topic in the research phase before moving on to implementing a solution.


问:
Determining if an Algorithm is O (log n)
I'm refreshing my CS Theory, and I want to know how to identify that an algorithm O (log n) complexity.  Specifically, is there an easy way to identify it?

I know with O(n), you usually have a single loop; O(n^2) is a double loop; O(n^3) is a triple loop, etc.  How about O (log n)?

答:
The typical examples are ones that deal with binary search. For example, a binary search algorithm is usually O(log n).

If you have a binary search tree, lookup, insert and delete are all O(log n) complexity.

Any situation where you continually partition the space will often involve a log n component. This is why many sorting algorithms have O(nlog n) complexity, because they often partition a set and sort as they go.


答:
It's very hard to say anything about performance without a practical test. Recently I was very surprised to find out that in JavaScript a naïve string concatenation was usually faster than the recommended "make list and join" solution (test here, compare t1 with t4). I'm still puzzled about why that happens.

A few questions you might ask when reasoning about performance (especially concerning memory usage) are: 1) how big is my input? 2) how smart is my compiler? 3) how does my runtime manage memory? This is not exhaustive, but it's a starting point.

How big is my input?

A complex solution will often have a fixed overhead, maybe in the form of extra operations to be performed, or maybe in extra memory needed. Since those solutions are designed to handle big cases, the implementors will usually have no problem introducing that extra cost, since the net gain is more important that micro-optimizing the code. So, if your input is sufficiently small, a naïve solution may well have a better performance than the complex one, if only for avoiding this overhead. (determining what is "sufficiently small" is the hard part though)

How smart is my compiler?

Many compilers are smart enough to "optimize away" variables that are written to, but never read. Likewise, a good compiler might also be able to convert a naïve string concatenation to a (core) library use and, if many of them are made without any reads, there's no need to convert it back to a string between those operations (even if your source code seems to do just that). I can't tell whether or not any compilers out there do that, or to what extent that is done (AFAIK Java at least replace several concats in the same expression to a sequence of StringBuffer operations), but it's a possibility.

How does my runtime manage memory?

In modern CPUs the bottleneck is usually not the processor, but the cache; if your code accesses many "distant" memory addresses in a short time, the time it takes to move all that memory between the cache levels outweights most optimizations in the instructions used. That's of particular importance in runtimes with generational garbage collectors, since the most recently created variables (inside the same function scope, for instance) will usually be in contiguous memory addresses. Those runtimes also routinely move memory back and forth between method calls.

One way it can affect string concatenation (disclaimer: this is a wild guess, I'm not knowledgeable enough to say for sure) would be if the memory for the naïve one were allocated close to the rest of the code that uses it (even if it allocates and releases it multiple times), while the memory for the library object were allocated far from it (so the many context changes while your code computes, the library consumes, your code computes more, etc would generate many cache misses). Of course for big inputs OTOH the cache misses will happen anyway, so the problem of multiple allocations becomes more pronounced.

That said, I'm not advocating the use of this or that method, only that testing and profiling and benchmarking should precede any theoretical analysis about performance, since most systems nowadays are just too complex to fully understand without a deep expertise in the subject.


答:
The idea is that an algorithm is O(log n) if instead of scrolling through a structure 1 by 1, you divide the structure in half over and over again and do a constant number of operations for each split.  Search algorithms where the answer space keeps getting split are O(log n).  An example of this is binary search, where you keep splitting an ordered array in half over and over again until you find the number.

Note: You don't necessarily need to be splitting in even halves.

Title: Determining if an Algorithm is O (log n)

Body:
I'm refreshing my CS Theory, and I want to know how to identify that an algorithm O (log n) complexity.  Specifically, is there an easy way to identify it?

I know with O(n), you usually have a single loop; O(n^2) is a double loop; O(n^3) is a triple loop, etc.  How about O (log n)?


答:
Is it inefficient to concatenate strings one at a time?

No.

Have you read 'The Sad Tragedy of Micro-Optimization Theater'?


答:
A single language to learn to develop desktop and mobile phone applications?

The answer is HTML5/Javascript, because of:

PhoneGap's ability to support 7 platforms.

Node.js/Topcube's ability to let you develop a desktop application.

Body:
Is there a language that is capable of developing apps to cross platform OSs (win,*nix) and mobile apps (IOS, android) ..
I'm a pro web developer but want to explore more environment to deploy my code into...

Python ? Ruby ?


答: C++, C and any other portable native language (that can talk to C) meet your needs. You'll always have a platform-specific part in you app that you'll have to change for each platform (if you don't use an engine that does the work for you) but the application itself can be written independently.</p>

Title: A single language to learn to develop desktop and mobile phone applications?


答: You could try using Java. Eclipse is made using Java and it runs on the desktop, and I'm sure you've heard of Android already for mobile devices. Java is used everywhere and is definitely cross-platform.</p>


答:
C#.

It works on Windows (either with Mono or regular .NET framework), on Linux and Mac (with Mono).

Xamarin Monotouch can be used to build apps for Android, iOS, and Windows Phone 7, though there are specific UI bits that are unique to each platform.

Playstation Suite SDK currently only supports the use of C# (and is backed by Mono), and can be used to build apps/games for the Playstation Vita and Playstation-certified devices (currently only a handful of Sony-made Android phones and tablets).

Unity Game Engine can be used to build games for web browsers (with special plugin), iOS devices, Android devices, and if you have lots and lots of money and credentials, for consoles as well.

And some apps that are written with C#:

MonoDevelop - Desktop IDE for writing C# in

Tumbledrop - iOS game written with Unity engine


问:
When is 'cloning', rather than reusing, a module acceptable design solution?
For this question, I'll give an example module to facilitate the discussion, Let's say the module is a calculation engine, It currently servers its purpose for its current audience. The requirement is to clone the same engine but with some tweaking for an entirely new audience. Given that, these are Considerations/Factors that will affect the design solution:

User expects that the current engine will remain unchanged, because its not part of the requirement (note the new engine is for some new audience, and does not affect the users of the current engine).

In addition to #1, the expectation is no regression testing for the code base of the current engine since no changes are introduced.

Just to drive the point, refactoring the current engine to make it flexible to address both current and new engines, will not be an option given that will not satisfy the 2 points above.

We can expect in the future that there will be exclusive changes for each engine, ie. change is applicable only to the new engine hence should not affect the current.

Tight deadline.

However, I am still conflicted, since:

It will inherently be a copy-paste solution.

Duplicate code.

Maintenance issue for code changes that should be common to both.

Does not address extension issue, ie. a third engine, and so forth could all be possible.

Is the compromise acceptable in this situation, given the user expectations highlighted above? And followup question, is there something I can add to the solution that will address  the conflicting issues but at the same time satisfy the user requirements?

答: This sounds like one of those business issues that sometimes you just have to deal with and accommodate. For example, we have customers in the pharmaceutical industry and once they validate a version of our software for their production line, they can't change versions without a significant amount of paperwork and re-validation. We maintain custom branches of our code base for these customers where we "guarantee" (as a matter of policy) that the only changes present are bug fixes that have been deemed relevant to their process and are provided only at their request.</p>


答:
Global Delivery Model usually implies one of two things:

1)  Uses cheaper resources from overseas.

2)  These resources can work around the clock, so you can finish a day of development in one region, and have it tested overnight in another.

To answer your question, I find it only nominally about deployment.  (I like the answer @java_mouse gives, though I'm not quite as extreme)  An organization that is located around the globe can provide deployment support 24X7, and can help provide resources close to your customers if you need.  But this is ancillary to points 1 & 2.

Title: What is Global Delivery Model?

Body: Many software companies preach in their Website Banners: "Global Delivery Model". Has it anything to do with Deployment?</p>


答:
I know with O(n), you usually have a single loop; O(n^2) is a double
  loop; O(n^3) is a triple loop, etc. How about O (log n)?

You're really going about it the wrong way here. You're trying to memorize which big-O expression goes with a given algorithmic structure, but you should really just count up the number of operations that the algorithm requires and compare that to the size of the input. An algorithm that loops over its entire input has O(n) performance because it runs the loop n times, not because it has a single loop. Here's a single loop with O(log n) performance:

```<code>for (i = 0; i < log2(input.count); i++) {
    doSomething(...);
}
</code>```

So, any algorithm where the number of required operations is on the order of the logarithm of the size of the input is O(log n). The important thing that big-O analysis tells you is how the execution time of an algorithm changes relative to the size of the input: if you double the size of the input, does the algorithm take 1 more step (O(log n)), twice as many steps (O(n)), four times as many steps (O(n^2)), etc.

Does it help to know from experience that algorithms that repeatedly partition their input typically have 'log n' as a component of their performance? Sure. But don't look for the partitioning and jump to the conclusion that the algorithm's performance is O(log n) -- it might be something like O(n log n), which is quite different.

Body:
I know with O(n), you usually have a single loop; O(n^2) is a double
  loop; O(n^3) is a triple loop, etc. How about O (log n)?

You're really going about it the wrong way here. You're trying to memorize which big-O expression goes with a given algorithmic structure, but you should really just count up the number of operations that the algorithm requires and compare that to the size of the input. An algorithm that loops over its entire input has O(n) performance because it runs the loop n times, not because it has a single loop. Here's a single loop with O(log n) performance:

for (i = 0; i < log2(input.count); i++) {
    doSomething(...);
}

So, any algorithm where the number of required operations is on the order of the logarithm of the size of the input is O(log n). The important thing that big-O analysis tells you is how the execution time of an algorithm changes relative to the size of the input: if you double the size of the input, does the algorithm take 1 more step (O(log n)), twice as many steps (O(n)), four times as many steps (O(n^2)), etc.

Does it help to know from experience that algorithms that repeatedly partition their input typically have 'log n' as a component of their performance? Sure. But don't look for the partitioning and jump to the conclusion that the algorithm's performance is O(log n) -- it might be something like O(n log n), which is quite different.


答:
It sounds to me like you want to be considering branching your code, which is basically going to clone your code-base for development and support of your two projects, while allowing you the flexibility to merge changes as needed.  Thus you end up with a new branch in your version control system, and you decide whether to continue support for the original version in the branch or the mainline.

If you are considering phasing out your initial version, then you may wish to throw support into a branch, and have your second version continue on the mainline. In both cases however, maintenance could result in a change that is useful in both old and new version, so you would want to manage your branching/merging such that you could take advantages of changes without needing to edit two individual projects.

I have perhaps oversimplified my answer here, however it is really to point out that you will run into serious management overheads and scheduling bottlenecks if you choose to maintain two separate products when you could have otherwise shared much of the code base between the two products.

The other alternative might be to break the product down into smaller modules. A common base layer where all of the unchanged common code can reside, and a pair of unique and dependant products as a higher layer to the base. This too can have it's problems, yet can be a relatively simple thing to manage if supported with a good automated build/release process.

Title: When is 'cloning', rather than reusing, a module acceptable design solution?

Body:
For this question, I'll give an example module to facilitate the discussion, Let's say the module is a calculation engine, It currently servers its purpose for its current audience. The requirement is to clone the same engine but with some tweaking for an entirely new audience. Given that, these are Considerations/Factors that will affect the design solution:

User expects that the current engine will remain unchanged, because its not part of the requirement (note the new engine is for some new audience, and does not affect the users of the current engine).

In addition to #1, the expectation is no regression testing for the code base of the current engine since no changes are introduced.

Just to drive the point, refactoring the current engine to make it flexible to address both current and new engines, will not be an option given that will not satisfy the 2 points above.

We can expect in the future that there will be exclusive changes for each engine, ie. change is applicable only to the new engine hence should not affect the current.

Tight deadline.

However, I am still conflicted, since:

It will inherently be a copy-paste solution.

Duplicate code.

Maintenance issue for code changes that should be common to both.

Does not address extension issue, ie. a third engine, and so forth could all be possible.

Is the compromise acceptable in this situation, given the user expectations highlighted above? And followup question, is there something I can add to the solution that will address  the conflicting issues but at the same time satisfy the user requirements?


答:
A basic theme running through Agile is the concept that the team should do just enough of 'x' to feel comfortable and responsible moving forward, but not more. This applies to many aspects of the software development life cycle such as design, documentation, testing, and research.

Putting an arbitrary and rigid time box around any of these ("spend up to four hours coding this functionality, but no more") is not very Agile. What if, after four hours, you don't feel comfortable that the functionality is complete? It would be irresponsible to move on to the next feature.

Likewise, consider research time ("spend up to four hours researching this functionality, but no more"). What if, after four hours, you don't feel comfortable making a design decision? It would be irresponsible to commit to a design the team doesn't feel comfortable with.

Clearly, however, one doesn't need to master all features of a given technology to be comfortable enough with it. The researcher should spend just enough time to feel like a good, responsible decision can be made; no more, no less.


问:
Store HighRes photos in Database or as File?
I run a site which has a couple of million photos and gets over 1000 photos uploaded each day. Up to now, we haven't kept the original file that was uploaded to conserve on space. However, we are getting to a point that we are starting to see a need to have high-res original versions. I was wondering if its better to store these in the filesystem as an actual file or if its better to store them in a database (ie: mysql). The highres images would be rarely referenced but may be used when someone decides to download it or we decide to use it for rare processes like making a new set of thumbnails sizes/etc.</p>

答: Yep, as everyone has noted, store the large images in a filesystem (and possibly thumbnails as well). You can hash or UUID them or something to get a reasonable location/unique name, then you can store this (as well as the matching thumbnail or other resolutions if required) location in the database. Then the DB does the search/match/join work for you, and the filesystem does what it's good at: storing files.</p>


问:
MySQL with mutiple threads and processes
I'm developing a telecom messaging platform in C, and I'm going to need multiple processes to be working with MySQL DB.

How can I make two processes read/write to/from a Mysql DB and, if/when one of them goes down, get the other to seamlessly take over the work until the dead process gets back to work? I was thinking/googling some options and am stuck in place where I don't know which one to choose.

What I think so far is that table lock is not the best option to go for, as it will stall the other process until the table is unlocked. The other option is to use row-level locks or manual locks, but I can't find the best way to do it.

答: MySQL should automatically unlock the tables (and if you're using a transactional table type it'll do something with the transaction - either roll back or commit depending on options etc)  when the second process dies (since the connection will drop.) If your question is about having two processes for reliability working on a single work queue, that info may help?</p>


问:
Best solution for getting referral information in PHP
I am currently redoing some link structuring on a website. In the past we have used specific php files on the last step to direct the user to the proper place.

Example:

```<code>www.example.com/action/go-to-blue.php
</code>```

or

```<code>www.example.com/action/short/go-to-red.php

www.example.com/action/tall/go-to-red.php
</code>```

We are now restructuring to eliminate the /short/ or /tall/ directory. What this means is now go-to-blue.php will be doing some extra processing to make sure it sends the visitor to the proper place.

The static method of the past was quite effective, because, well, if they left from that page we knew we had it right. Now since we are 301 redirecting action/short/go-to-red.php
to just action/go-to-red.php it is quite important on go-to-red.php that we realize a user may have been redirected from /short/ or /tall/.

So right now I am using HTTP_REFERRER and of course in my testing that works fine, but after a lot of reading it is clear that this is not a solid solution, so I was starting to brainstorm on other ways to check and make sure we get the proper referral information.

If we could check HTTP_REFERRER plus some other test, I would feel confident we have a pretty good system in place to send the visitor to the right place.

Some questions/comments:

Could I use a session variable or a cookie to accomplish this goal?

If so, would that be maintained through the 301 redirect? I don't see why it wouldn't be..

Passing the url in the url is not an option in this case.

答:
Yeah, at the end of the day HTTP is basically stateless, so you're relying on the users browser to give you accurate information to help you add state on the top of it. REFERRER and cookies are basically the two ways to achieve this (SESSION just uses a cookie for you, and almost everything else effectively folds back up into cookies or cookie-like-mechanisms.) At the end of the day though, you're at the mercy of the browsers giving you accurate REFERRER or COOKIE information.

One other thing to think about: if the redirect inside apache itself is the thing that's causing you to worry about the REFERRER tag, you could try using mod_rewrite to set the get request into an environment variable and then chain to a static script that sets a cookie and issues a LOCATION header (to do a redirect) yourself. Or if you don't trust cookies you could set a temporary portion of the GET request header and then make the target script check for that extra bit, use it, and then redirect to itself without the extra bit (so it's hidden from the users.)


答:
Given those constraints, then I think the best option is to fork the code into two branches. One normally does this in the version control system, not a simple file system copy. When you branch in the version control system, common history is perserved, and integrating bug fixes from the new branch to the legacy branch can be performed at best automatically and at worst manually with machine assistance. I would not put this in the category of copy-paste programming, which I generally look down upon.

This development pattern is actually quite common. When you make a major release of some software, call it version 1.0, you basically want to keep it unchanged as you charge off and begin version 2.0. Around the time of release, you create a branch off the main trunk called 1.0 (or just a tag/label) to clearly mark what got shipped. As you work on 2.0, or as people use your software, bugs are encountered and fixes are found.

Now you really want to apply those fixes on both the 1.0 branch and the main trunk, so you do so. There are several approaches to this. One is to simply apply the same edits to the same files on both the 1.0 and main branches. This can be the easiest but is a little error prone.

Another is to apply the fix on one branch and then integrate the changed files from one branch to the other. In large projects this can often be done automatically, as the files on both branches may not have changed since release and are identical. The version control system knows the history of both branches, so applying the fixes on 1.0 and integrating from 1.0 to main is probably the better choice, as the version control system will generally not be confused by new development made on the post-1.0 files and can apply the fixes automatically. Going the other way around is not recommended because the version conrol system can't tell the differences between changes on the post-1.0 file that are new development and those that are bug fixes. This could lead to inappropriate code being introduced to the 1.0 branch.

Sometimes, the post-1.0 files on the main branch are so different from what shipped as to make automatic integration impossible. In this case, either the fix does not need to be applied in the new code, or you simply must be careful and apply it manually in both. Whatever path you choose, always carefully look over your changes before checking them in.


问:
In ASP.NET MVC3 controllers, where do you instantiate your DataContext?
In your ASP.NET MVC 3 applications that use a DataContext or DbContext, where do you instantiate your data access object?

Here is a non-exhaustive list of where I've seen it done:

Individually within each method of the controller

In the controller's constructor

As a property (lazy-initialized) of the controller

In an ActionFilter, shoved into ViewBag

In Global.asax Application_BeginRequest

In an HttpModule

I can't identify a clear front-runner amongst all of those. What's worse, whenever I start a brand-new project, I tend to change it up, just because.

Does anyone have any battle-tested advice?

答:
For smaller projects I Basically, store it in HttpContext.Items.  However, I love lazying loading, so I'm not a fan of spinning up a DBContext on literally every HttpApplication Request.  So instead I wrote the following:

```<code>public static class ControllerExtensions
{
    public static MyDBContext MyDBContext(this Controller instance)
    {
        MyDBContext result =
          instance.HttpContext.Items[typeof(MyDBContext).Name] as MyDBContext ;

        if (result == null)
        {
            result = new MyDBContext ();
            instance.HttpContext.Items[typeof(MyDBContext).Name] = result;
        }

        if (result == null)
        {
            throw new InvalidOperationException("No DBContext in HttpContext.");
        }

        return result;
    }
</code>```

This means I have a Strongly-Typed, Lazy loaded, Single DBContext per Request, MyDBContext available for any controller to use.

```<code>public HomeController
{
  public ActionResult Index()
  {
    List<string> model = this.MyDBContext().Cars
                                           .Select(x => x.Name)
                                           .ToList();

    this.View(model);
  }
}
</code>```

Body:
For smaller projects I Basically, store it in HttpContext.Items.  However, I love lazying loading, so I'm not a fan of spinning up a DBContext on literally every HttpApplication Request.  So instead I wrote the following:

public static class ControllerExtensions
{
    public static MyDBContext MyDBContext(this Controller instance)
    {
        MyDBContext result =
          instance.HttpContext.Items[typeof(MyDBContext).Name] as MyDBContext ;

        if (result == null)
        {
            result = new MyDBContext ();
            instance.HttpContext.Items[typeof(MyDBContext).Name] = result;
        }

        if (result == null)
        {
            throw new InvalidOperationException("No DBContext in HttpContext.");
        }

        return result;
    }

This means I have a Strongly-Typed, Lazy loaded, Single DBContext per Request, MyDBContext available for any controller to use.

public HomeController
{
  public ActionResult Index()
  {
    List<string> model = this.MyDBContext().Cars
                                           .Select(x => x.Name)
                                           .ToList();

    this.View(model);
  }
}


问:
How to handle bugs that I think I fixed, but I'm not entirely sure
There are some types of bugs which are very hard to reproduce, happen very rarely and seemingly by random. It can happen, that I find a possible cause, fix it, test the program, and can't reproduce the bug. However, as it was impossible to reliably reproduce the bug and it happened so rarely, how can I indicate this in a bugtracker? What is the common way of doing it?

If I set the status to fixed, and the solution to fixed, it would mean something completely fixed, wouldn't it?

Is it common practice to set the status to fixed and the solution to open, to indicate to the testers, that "it's probably fixed, but needs more attention to make sure" ?

Edit: most (if not all) bugtrackers have two properties for the status of a bug, maybe the names are not the same. By status I mean new, assigned, fixed, closed, etc., and by solution I mean open (new), fixed, unsolvable, not reproducible, duplicate, not a bug, etc.

答: The test team will decide if the issue has been resolved and if it can closed. If there are any more regressions, side effects of the fix, or if the fix itself is not effective in another scenario, the issue will be reopened. But if you have done enough developer testing, then better to mark it as fixed.</p>


答: If you want it as simple as "single loop -> O(n), double loop -> O(n^2)", than the answer is probably "Tree -> O(log n)". More accurately traversing a tree from root to one (not all!) leaf or the other way round. However, these are all oversimplifications. </p>


答:
Is it common practice to set the status to fixed and the solution to open, to indicate to the testers, that "it's probably fixed, but needs more attention to make sure"?

Common or not, this is the right thing to do anyway, and you laid out why yourself: no matter how, it is a good approach to

indicate to the testers, that "it's probably fixed, but needs more attention to make sure"

Side note even if particular bug tracker does not have field like one you describe as solution, developer can at least add a free-form comment explaining above.

...and if bug tracker does not allow to add comments to the issue then it must be replaced with one that does. Ability to add free-form clarifications is a critically important feature since issues vary too much to fit into some pre-defined form.

Title: How to handle bugs that I think I fixed, but I'm not entirely sure

Body:
There are some types of bugs which are very hard to reproduce, happen very rarely and seemingly by random. It can happen, that I find a possible cause, fix it, test the program, and can't reproduce the bug. However, as it was impossible to reliably reproduce the bug and it happened so rarely, how can I indicate this in a bugtracker? What is the common way of doing it?

If I set the status to fixed, and the solution to fixed, it would mean something completely fixed, wouldn't it?

Is it common practice to set the status to fixed and the solution to open, to indicate to the testers, that "it's probably fixed, but needs more attention to make sure" ?

Edit: most (if not all) bugtrackers have two properties for the status of a bug, maybe the names are not the same. By status I mean new, assigned, fixed, closed, etc., and by solution I mean open (new), fixed, unsolvable, not reproducible, duplicate, not a bug, etc.


问:
Find a "hole" in a list of numbers
What is the fastest way to find the first (smallest) integer that doesn't exist in a given list of unsorted integers (and that is greater than the list's smallest value)?

My primitive approach is sorting them and stepping through the list, is there a better way?

答:
Most ideas here are no more than just sorting. The bitvector version is plain Bucketsort. Heap sort was also mentioned.
It basically boils down to chosing the right sorting algorithm which depends on time/space requirements and also on the range and number of elements.

In my view, using a heap structure is probably the most general solution (a heap basically gives you the smallest elements efficiently without a complete sort).

You could also analyze approaches which find the smallest numbers first and then scan for each integer larger than that. Or you find the 5 smallest numbers hoping the will have a gap.

All of these algorithms have their strength depending on the input characteristics and program requirements.

Title: Find a "hole" in a list of numbers


问:
Handling and organizing data from save file?
I'm working on a webapp (python/javascript) to modify a game's save file. The file has certain bytes representing player information, such as the gun, the equipment, etc. The idea is to show an interface representing the information in the file, allow the user to make changes, send the data back to the server, which modifies the file, and allows the user to download it.

My problem is that I don't know which functions should be handled in javascript, and which in Python. I need python for reading the file, but does that mean I should use it to handle the data? If I read the information into relevant variables to send back with JSON, is it redundant because I'm not doing anything with the information in Python other than sending it back?

I've currently been indecisive about two possible ways to go about it. One, and this is the way I currently have it set up, is to handle the file with Python; figure where certain things are, read them into dictionaries, turn it into json, send that to javascript, and then parse the json and update the gui. As I said before, this feels like the wrong way to do it.

The other thing I was considering was to just read the entire file and send that back to javascript to work with. This also seems really incorrect. Javascript (at least as it's implemented in browsers) isn't meant to handle files, and packing/unpacking functions would have to be custom - one of the things I'm seeing as a red flag about this method.

The files are only about 1-2kb, so that wouldn't be a reason not to send it back to the page. In fact, the json I'm sending back is larger than just the contents of the file would be. Still though, I don't much like the idea.

So what do I do? I'm also having trouble organizing the actual code. I know it's bad practice to stick a lot of code into a single function, but dividing into many other functions has made it hard to keep track of things. Is there a good language-agnostic book that will help me with this?

答:
There is no 'one right way' to handle save files, or any other data. The right way to proceed is largely shaped by the particular pressures that apply in your situation.

For instance, you say that both the packed and the expanded version of the save information is small, so it doesn't cost much to send the data to the browser either way; therefore, access speed is not a consideration for where to locate your code. However, unpacking and parsing seems to be a pressure: you have preexisting libraries or methods to do it in Python, but not in Javascript. This is a clear indicator that you should do much of the processing on the server. Other pressures that might apply are security, responsiveness, etc.

You also say that using parsing, sending and then displaying the data this 'feels wrong' to you; this is harder to judge, but if there are real concerns that would make this solution harder to work with in the future - for you or others - then it can be a pressure that outweighs the other considerations. A prototype implementation of just one feature might help you to judge whether this is the case.


问:
A modern review of Java
I've been programming for a few years and I began in Java, and in my time I've found many different sources claiming Java to be an inferior language in some way or another. I'm well aware that each language has it's strengths and weaknesses, but a lot of things I've read about Java seem to be dated.

The most often cited reason for Java being inferior is that it is much slower than other natively compiled languages, like C++ for example. Many people criticize the game designer Notch (who developed Minecraft) for using Java because of its apparent lack in the performance department. I know Java was much slower back in the day, but there have been many improvements since, especially JIT compilation.

I would like to get some objective opinions of Java as a language today. So my question has 4 parts.

Performance.

a. How does Java's speed today compare to C++?

b. Would it be possible to create a modern AAA title using Java?

c. In what areas specifically is Java slower than C++, if at all? (i.e. Number-crunching, graphics, or just all around)

Is Java now considered a compiled language or interpreted language?

What are some major shortcomings of Java that have been addressed since the early days?

What are some major shortcomings of Java that have yet to be addressed?

Edit:

Just for clarification purposes I'm not making this Java vs C++, obviously on average c++ will be a little faster than Java. I simply need something to compare Java to in terms of maturity as a language at this point in time. Since c++ has been around forever I thought I would be a good point of comparison.

答:
I sort of reacted to this question because it will give misleading and largely irrelevant answers:

b. Would it be possible to create a modern AAA title using Java?

Everyone can agree that AAA titles would be difficult to produce using Java and that there are no actual examples that I'm aware of. However given the nature of AAA that would assume a lot of things (since it really is a confusing term coming from marketing) so it's better to ask the following instead:

Is it possible to create a modern title with reasonable success using Java?

The answer is "Yes, you can.". However the actual success part of the equation is more based on your persistence and luck (or adherence to zeitgeist) but that is outside the scope this site.

Title: A modern review of Java


问:
API design and versioning using EJB
I have an API that is EJB based (i.e. there are remote interfaces defined) that most of the clients use.  As the client base grows there are issues with updates to the API and forcing clients to have to update to the latest version and interface definition.

I would like to possibly look at having a couple versions of the API deployed at a time (i.e. have multiple EAR files deployed with different versions of the API) to support not forcing the clients to update as frequently.  I am not concerned about the actual deployment of this, but instead am looking for thoughts and experiences that others have on using EJB's as an API client.

How do you support updating versions, are clients required to update?

Does anyone run multiple versions in a production environment?  Are there pro's cons?

Any other experiences or thoughts on this approach, and having an EJB centric API?

答:
It can be quite common to host multiple versions of an API (I'd only recommend having 2 at Max BTW). Typically you would host each API on a different shard/server/whatever and work with your clients to help them upgrade to the new API in an x time-frame.

An EJB centric API might suit your business needs now (which is fine) but there is an industry trend to move towards higher level (more abstract) API layers such as RESTful HTTP based APIs which can support a wider range of clients.

Title: API design and versioning using EJB


答:
There are types of bugs which are very hard to reproduce, happen very rarely and seemingly by random. It can happen, that I find a possible cause, fix it, test the program, and can't reproduce the bug.

Actually, if I there is no reproducible test scenario, I would not even try to fix such a bug beforehand. If you want tester to take more attention on it, give them a chance to create a reproducible scenario.

For example, let's say you change the program, and a tester invests 1 hour on trying to reproduce the bug, and the bug does not pop up - was one hour enough? Or is testing further a waste of time because the bug was already fixed?

On the other hand, when you don't change the program, and the bug does not pop up in 1 hour, most probably the tester should invest another hour in trying different things. And when the tester invest one day and cannot reproduce the bug any more - is it really worth trying to fix it then?

Said that, you can think about how you model that process in your bug tracking system: not trying to fix it and handing it over to the testers may be a bug status like "open". If the testers cannot reproduce it, it is obviously "not reproducible". Hopefully, this does not happen, they find a reproducible scenario, you can find the root cause of your bug, fix it and set the status to "fixed". Try to avoid getting into something like "don't know if it's fixed".


问:
Steps for moving towards continuous delivery?
Say you have a traditional dev > test > production process say on a monthly release cycle.

What are some of the steps you need to take and put into place to move towards a model of continuous delivery with frequent releases per day.

Please make one suggestion per response.  I would be interested in using voting to indicate which steps the community feel are most important.

答:
Setup version control (if not already) and define a branching model/strategy to follow.

The shorter your release cycles are, the more important branching will become and every developer must rely on certain branches to be in defined states.


答:
I'll kick this off to get us started....

Automated Testing

Having automated unit tests, integration tests and acceptance tests are vitally important if we're going to allow everything to flow straight through to production.

Even the best and most thorough manual testing process in the world would simply take too long if the application has any degree of complexity.

Title: Steps for moving towards continuous delivery?

Body:
Say you have a traditional dev > test > production process say on a monthly release cycle.

What are some of the steps you need to take and put into place to move towards a model of continuous delivery with frequent releases per day.

Please make one suggestion per response.  I would be interested in using voting to indicate which steps the community feel are most important.


答:
I would suggest to have communication transparency between your

 Development team <-> Testing team <-> Clients.

Cause most of the problems arise because of miscommunication.

Probably setup a sharepoint site to display the current status of development so everyone is aware of whats going on.

Update: Try also to plan a project status review meeting (every week possibly).


问:
Architecture guidelines for a "single page web-app"
I'm going to start a side project to build a "single page" web application. The application needs to be real-time, sending updates to the clients as changes happen.

Are there any good resources for best-practice approaches wrt the architecture for these kinds of applications. The best resource I've found so far is the trello architecture article here: http://blog.fogcreek.com/the-trello-tech-stack/

To me, this architecture, although very sexy, is probably over-engineered for my specific needs - although I do have similar requirements. I'm wondering if I need to bother with a sub/pub at the server side, could I not just push updates from the server when something happens (e.g. when the client sends an update to the server, write the update to the db, and then send an update to the clients).

Tech-wise, I'm probably looking to build this out in Node.JS or maybe Ruby, although the architecture guidelines should to some extent apply to any underlying server technologies.

答:
I would probably go with a MV* javascript framework for the front end.  I myself am building a single page web application and after investigating a number of solutions, I ended up going with Backbone.js.  I found while this solution did not provide the most out of the box functionality, it did provide me with a core foundation to start with and is a lot more flexible than other solutions I looked at (which was important to me).

Other popular solutions are Ember.js and Knockout.js which do provide more out of the box functionality however you have to follow their conventions to make use of thT functionality (which may or may not work for you).


问:
How does Google crawl frequently updated webpages?
I'm trying to build a very small, niche search engine, using Nutch to crawl specific sites. Some of the sites are news/blog sites. If I crawl, say, techcrunch.com, and store and index their frontpage, then within hours my index for that page will be out of date.

Does a large search engine such as Google have an algorithm to re-crawl frequently updated pages very frequently, hourly even? Or does it just score frequently updated pages very low so they don't get returned?

Also, how can I handle this in my own index?

答:
Yes, Google does manage the frequency of how much time it's crawlers are visiting a site.
For example all the news site which are registered on Google News get more frequent visits than other sites, also some live-score showing websites get crawler's vistit every second(realtime search).
So, it means they are using some kind of algorithm so that those bots prioritise their visits to such sites. </p>


问:
Does Agile force developers to spend more time actually working?
Looking at common Agile practices it seems to me that they (intentionally or unintentionally?)  force developers to spend more time actually working as opposed to reading blogs/articles, chatting, coffee breaks and just plain procrastinating.

In particular:

1) Pair programming - the biggest work-forcer, just because it is inconvenient to do all that procrastination when there are two of you sitting together.

2) Short stories - when you have a HUGE chunk of work that must be done in e.g. a month, it is pretty common to slack off in the first three weeks and switch to OMG DEADLINE mode for the last one.

And with the little chunks (that must be done in a day or less) it is exact opposite - you feel that time is tight, there is no space for maneuvering, and you will be held accountable for the task pretty soon, so you start working immediately.

3) Team communication and cohesion - when you underperform in a slow, distanced and silent environment it may feel ok, but when at the end of the day at Scrum meeting everyone boasts what they have accomplished and you have nothing to say you may actually feel ashamed.

4) Testing and feedback - again, it prevents you from keeping tasks "99% ready" (when it's actually around 20%) until the deadline suddenly happens.

Do you feel that under Agile you work more than under "conventional" methodologies? Is this pressure compensated by the more comfortable environment and by the feeling of actually getting right things done quickly?

答:
Phrasing the question 'forcing developers to work more' comes across a little negative, but surely it's positive if we actually get more done and procrastinate less?

That said, it's a good point.  I've been feeling a bit jaded with agile this year but this is a huge unwritten benefit which I hadn't been acknowledging.

I would agree that agile can lead to developers being more productive.  Your points about visibility, accountability, and tendency to procrastinate less are all very true.

But agile can and should also lead to developers working harder for positive reasons - the carrot vs the stick.  Done well, agile will give developers more interaction with users, less beuracracy, more control over their work, all of which can lead to getting more from your team.


答:
Sounds like what you're looking at is Apache 2.2 with PHP or Tomcat application server with a simple servlet which handles requests.  It's the carpenter's equivalent of hammer and nails.  Nothing complicated but it gets the job done.  If you ever needed to expand functionality, you could always do so since Tomcat can support jsp and jsf if you ever needed it to.  </p>

<p>For what concerns the front end, I'd be comfortable simply using jQuery ($.post, $.load, $.ajax) since it's quite handy doubling as a means to add functionality to your page in combination with jQuery UI  </p>

Title: Architecture guidelines for a "single page web-app"

Body:
I'm going to start a side project to build a "single page" web application. The application needs to be real-time, sending updates to the clients as changes happen.

Are there any good resources for best-practice approaches wrt the architecture for these kinds of applications. The best resource I've found so far is the trello architecture article here: http://blog.fogcreek.com/the-trello-tech-stack/

To me, this architecture, although very sexy, is probably over-engineered for my specific needs - although I do have similar requirements. I'm wondering if I need to bother with a sub/pub at the server side, could I not just push updates from the server when something happens (e.g. when the client sends an update to the server, write the update to the db, and then send an update to the clients).

Tech-wise, I'm probably looking to build this out in Node.JS or maybe Ruby, although the architecture guidelines should to some extent apply to any underlying server technologies.

Body:
Sounds like what you're looking at is Apache 2.2 with PHP or Tomcat application server with a simple servlet which handles requests.  It's the carpenter's equivalent of hammer and nails.  Nothing complicated but it gets the job done.  If you ever needed to expand functionality, you could always do so since Tomcat can support jsp and jsf if you ever needed it to.

For what concerns the front end, I'd be comfortable simply using jQuery ($.post, $.load, $.ajax) since it's quite handy doubling as a means to add functionality to your page in combination with jQuery UI


答:
You need to automate the complete delivery cycle, so one feature you will need is

automatic deployment

For web applications, this often seems to be trivial, for desktop applications this depends a lot on how your production environment looks like and may be far from trivial.


答:
I would definetly look towards client side MVC for this such as Backbone.js.  It's very lightweight but will give your application some much needed structure.  I highly recommend the Peepcode screencast as the fastest way of learning more about Backbone.

A nice architectural benefit of client side MVC like this is the fact that you can more easily move towards exchanging data with your server side e.g. structured JSON over REST.

Backbone.js supports this out of the box - you can serialise your models between the client and server as JSON, which can free us from thinking in terms of request/response.

Something like Node.js on the server side appeals under this model where you will possibly have a lot of short lived potentially asynchronous requests to push and pull data.

One alternative....  A model like Comet can be a simple way to achieve web pub/sub and there are some server side frameworks that support this.


答:
Rollbacks

A fast and reliable rollback is going to be massively important if you are going to open the gates to continuous delivery.

In the case of issues, you want to be able to switch back to the previous known version of the software at the first sign of problems.

Closely related to this would be good monitoring tools that quickly alert you to odd states or errors that are occuring in your application.


问:
Language that can statically ensure a map's fields are present
If data is simple and objects are complex, I'm curious if there are any existing statically typed languages that would be able to augment(?) a map type into a type with guaranteed fields. I realize that at runtime, in any language this type of check is pretty doable. But in theory I also believe this should be possible to check with a compiler. To do everything below in Java, would be an explosion of interfaces (HasComplete, HasTitle, HasTitleAndComplete)

So has anyone done it? If not, how come? If so, how was it implemented?

This would allow you to read in data but then manipulate it with at least some type safety:

```<code>// User input is often simply converted to a Map
function parse(json) -> Map {...}

// result still has all user input fields,
// but this would be a runtime exception
// if specified fields are missing
function cast(Map, Map<fields...>) -> Map<fields...> { ... }

input = "{title:'do it', complete: false, rank: 5, subtitle: 'now'}"

// Would throw class cast exception if complete or title were missing
todo = cast(parse(input), Map<title:str, complete:bool>)

// Runtime introspection
todo instanceOf Map -> true
todo instanceOf Map<title:str, complete:bool> -> true
todo instanceOf Map<title:str> -> true
todo instanceOf Map<complete:bool> -> true
todo instanceOf Map<complete:date> -> false
todo instanceOf Map<rank:int> -> false because cast() did not specify rank
todo instanceOf Map<title:str, complete:bool, author:str> -> false

// Typed methods based on map with certain fields
function capitalize_title(Map<title:str>) {...}
function finish_task(Map<complete:bool>) {...}
function finish_and_rename(Map<title:str, complete:bool>, newTitle) {...}
function increase_rank(Map<rank:int>) {...}

// Static Check compile pass
todo = capitalize_title(todo)
todo = finish_task(todo)
todo = finish_and_rename(todo, "[complete]")

// Static Check Compile Fail because cast() did not specify rank
increase_rank(todo)

// Methods could return a type with added (or removed) fields
function add_uuid(Map) -> Map<+id:int> {...}
todo_with_id = add_uuid(todo)
todo_with_id instanceOf Map<title:str, complete:bool, id:int> // true
</code>```

答:
There are so called dependently typed languages (Agda, Coq ...). These are very powerful and allow you to express a lot of information in the type system. Classical example is the type for a sorted list, allowing functions like (in imaginary concrete syntax):

```<code>sort :: List of a -> Sorted List of a
</code>```

Of course this means that you have to convince your compiler, that your sorting algorithm is correct (and terminates) and you have to define what sorted means.

Somewhat less is expressible in languages like Haskell (maybe Scala, if you're looking for JVM executable language). You can define a type of list including that length of the list in the type. An obvious application is writing a function retrieving the first element of a list that cannot be accidentally called with an empty list. However, this is not what Haskell is intended for and comes with a price. Usually the drawbacks (mind boggling higher order type definitions and so on) outweigh the benefits if the language is not designed to handle these things.

This extends to maps. But parsing JSON data still might produce maps that are not defined for the fields you wish. There is no control over IO for the compiler/type checker. Thus you would either have to come up with default values or change the parse function type to result in an optional value, efficiently making it a partial function. Then you would have to disambiguate on this result (the compiler would force you to - good thing). But this is not so different from defining a type in a classic system (e.g. Java) that by contract requires the fields to be present and checks for this at runtime. The classical version is of course not as modular, you have seen that yourself.

Body:
There are so called dependently typed languages (Agda, Coq ...). These are very powerful and allow you to express a lot of information in the type system. Classical example is the type for a sorted list, allowing functions like (in imaginary concrete syntax):

sort :: List of a -> Sorted List of a

Of course this means that you have to convince your compiler, that your sorting algorithm is correct (and terminates) and you have to define what sorted means.

Somewhat less is expressible in languages like Haskell (maybe Scala, if you're looking for JVM executable language). You can define a type of list including that length of the list in the type. An obvious application is writing a function retrieving the first element of a list that cannot be accidentally called with an empty list. However, this is not what Haskell is intended for and comes with a price. Usually the drawbacks (mind boggling higher order type definitions and so on) outweigh the benefits if the language is not designed to handle these things.

This extends to maps. But parsing JSON data still might produce maps that are not defined for the fields you wish. There is no control over IO for the compiler/type checker. Thus you would either have to come up with default values or change the parse function type to result in an optional value, efficiently making it a partial function. Then you would have to disambiguate on this result (the compiler would force you to - good thing). But this is not so different from defining a type in a classic system (e.g. Java) that by contract requires the fields to be present and checks for this at runtime. The classical version is of course not as modular, you have seen that yourself.


问:
How do you organize your projects folders?
Good afternoon

I would like to know how do you guys organize your project folders?

I had once a boss that suggest me to organize by Customers.

```<code>Projects
|
|----Customer 1
     |---- A Cool Solution 1
           |---- source
                 |---- version1.0
                 |---- version1.1
           |---- docs
                 |---- analysis
                 |---- meetings
                 |---- manuals
|----Customer 2
|----Customer 3
</code>```

A friend of mine told me to organize tem by Technology

```<code>Projects
|
|----.NET
     |---- C#
          |---- Customer 1
                |---- A Cool Solution 1
                      |---- source
                            |---- version1.0
                            |---- version1.1
                      |---- docs
                            |---- analysis
                            |---- meetings
                            |---- manuals
|----Ruby
|----PHP
</code>```

And you? Do you have a clever way to organize your project folders?

答:
This is what we've been using:

```<code>Projects
|
|----Customer A
     |---- Project 1
     |     |---- BuildControl       (CI/nAnt/Make/MSBuild files and config, etc)
     |     |---- Documentation      (In XML format so we can 'build' them)
     |     |---- Source
     |     |     |---- Component X
     |     |     |---- Component X.tests
     |     |     |---- Component Y
     |     |     |---- Component Y.tests
     |     |---- Testing
     |     Project 1.sln      (Has folders as per project on-disk structure)
     |---- Project 2
     |---- Shared/Common components
|----Customer B
|----Customer C
|----<Our Company>
     |---- Internal Project A
     |---- Internal Library B
</code>```

We've been using this structure for multiple projects with many different customers for years now and it works very well.

It's very similar to your initial suggestion, but we use version control to manage the versioning. The server repositories are named as "Customer X - Project Y", rather than anything else. This allows us to have external contractors working on some projects but not able to access others as we can set permissions at the version control root.

Everyone checks out their working copies to wherever they want on their (Windows) dev machine and uses the SUBST command to map a drive letter to that location. That way we can have hard-coded relative paths in build files, etc, that work across everyones' setup. So, for example, we can have links to shared libraries, if we so wish. We usually use version control links/aliases to achieve this tho.

One big benefit of this structure is that you can isolate customers' code from each other. This is useful if you need to (a) send them regular updates of the source for integration purposes, (b) have external contractors working on selected parts of the code.

Your second suggestion won't work so well with a complex project which uses more than one technology.

Body:
This is what we've been using:

Projects
|
|----Customer A
     |---- Project 1
     |     |---- BuildControl       (CI/nAnt/Make/MSBuild files and config, etc)
     |     |---- Documentation      (In XML format so we can 'build' them)
     |     |---- Source
     |     |     |---- Component X
     |     |     |---- Component X.tests
     |     |     |---- Component Y
     |     |     |---- Component Y.tests
     |     |---- Testing
     |     Project 1.sln      (Has folders as per project on-disk structure)
     |---- Project 2
     |---- Shared/Common components
|----Customer B
|----Customer C
|----<Our Company>
     |---- Internal Project A
     |---- Internal Library B

We've been using this structure for multiple projects with many different customers for years now and it works very well.

It's very similar to your initial suggestion, but we use version control to manage the versioning. The server repositories are named as "Customer X - Project Y", rather than anything else. This allows us to have external contractors working on some projects but not able to access others as we can set permissions at the version control root.

Everyone checks out their working copies to wherever they want on their (Windows) dev machine and uses the SUBST command to map a drive letter to that location. That way we can have hard-coded relative paths in build files, etc, that work across everyones' setup. So, for example, we can have links to shared libraries, if we so wish. We usually use version control links/aliases to achieve this tho.

One big benefit of this structure is that you can isolate customers' code from each other. This is useful if you need to (a) send them regular updates of the source for integration purposes, (b) have external contractors working on selected parts of the code.

Your second suggestion won't work so well with a complex project which uses more than one technology.


问:
Should we quit trying to do agile if QA takes 12 weeks?
Someone in my company recently proposed changes to our core product that our managers feel should trigger what I guess my company considers a full QA cycle (i.e. testing the entire product suite from the ground up). Apparently our QA takes 12 weeks to do a full QA cycle for our product. My problem with this is that we are trying to do Agile (although mostly half-assed in my opinion) development. We will do a whole set of sprints and then do a release, which QA will take forever to go through I guess. The question is really, if our QA is going to take 12 weeks to do their job, shouldn't we just give up trying to do Agile? What the hell is the point of trying to do Agile in a situation like this?</p>

答:
What are the QA people doing while you're executing multiple sprints? Sounds like they feel the need to test everything after every change (Which is why they wait for a whole bunch of changes.).

The development team is agile, but the rest of the company is not.

Whoever is in charge of QA either doesn't know what he/she is doing or they have performed a Jedi Mind Trick on upper management and are allowed to take their sweet time. How can QA take longer than development?


答: I find that the quickest and biggest improvement to get folks moving down the path is to set up a build machine and integrate it to kick off builds when code is checked in to version control. Even if the boss doesn't let us move any further down the CI/CD path, having builds ready all the time saves on stress and eliminates the "only Bob has the right stuff on his machine to make the build and he went home hours ago" stress. </p>