答:
The overall description of the architecture doesn't suggest 'bad'.  I don't think it that something like that is even uncommon to have separate schemas/databases for each business function (accounting being separate from sales/marketing) as it respects certain data ownership principals and responsibilities.

The problem it sounds like you are having is that the ecomm site is too disconnected from the mapping-sync that coordinates with the accnt system.

Is the mapping-sync developed using shared/reused code, or is it completely divergent, perhaps produced in a different language and running in a different operating context/environment (eg main ecomm in Php, while mapping-sync is in Perl?

Likely the mapping-sync isn't making decisions about the data, but merely transforming and transmitting it.  It is possible to keep this process better aligned with the ecomm side by parsing the relevant ecomm bits that describe the data structures and constraints, and generating the pluggable bits for the mapping-sync side, such that any changes to the ecomm side will almost automatically be reflected in the mapping-sync.

Title: Storing data in 2 different systems/database structures

Body:
My company is an online retailer, and we use an homebrew ecommerce platform. In the last year or so, we've partnered with a accounting software vendor, as our homebrew solution was unable to produce reports as needed, or otherwise satisfy the requests of banks and investors.

We're off to a rocky start with the software, but I'm wondering if it's our approach. Currently, we store a complete set of data in the database connected to our ecommerce platform. Nightly, we send the necessary API calls to sync our entities in the accounting software (orders, POs, invoices, etc), and each morning, I've created scripts that validate that the data is correct between the two systems. This collective system has been a nightmare, as any minor chages to the ecommerce platform cascade in violent and horrible ways to system B. It's resulting in a TON of work on my part to make corrections on a daily basis.

Is there a correct way to approach this problem? Or does the problem really lie upstream, in our decision to duplicate the data between the two systems. Has anybody successfully done something similar?

It has been a non-stop fire drill for 3 months now, and any advice would be greatly appreciated.


问:
Any tools/suggestions on how to refute code coverage quality argument
Now I know people could consider this question duplicate or asked many times, in which case I would appreciate a link to relevant questions with answer to my question.

I have been recently in disagreement with some folks about code coverage. I have a group of people who want our team to drop looking at code coverage altogether based on the argument that 100% coverage does not mean good quality tests and thus good quality code.

I have been able to push back by selling the argument that Code Coverage tells me what has not been tested for sure and help us focus on those areas.

(The above has been discussed in a similar fashion in other SO questions like this one - https://stackoverflow.com/questions/695811/pitfalls-of-code-coverage)

The argument from these folks is - then team would react by quickly creating low quality tests and thus waste time while adding no significant quality.

While I understand their point of view, I am searching for a way to make a more robust case for code coverage by introducing more robust tools/frameworks that take care of more coverage criteria (Functional, Statement,Decision, Branch, Condition, State, LCSAJ, path, jump path, entry/exit, Loop, Parameter Value etc).

What I am looking for is suggestion for a combination of such code coverage tools and practices/processes to go with them which can help me counter such arguments while feeling comfortable about my recommendation.

I would also welcome any accompanying comments/suggestions based on your experience/knowledge on how to counter such an argument, because while subjective, code coverage has helped my team be more conscious of code quality and value of testing.

Edit: To reduce any confusion about my understanding of weakness of typical code coverage, I want to point out that I am not referring to Statement Coverage(or lines of code executed) tools(there are plenty). In fact here is a good article on everything that is wrong with it: http://www.bullseye.com/statementCoverage.html

I was looking for more than just statement or line coverage, going more into multiple coverage criteria and levels.

See: http://en.wikipedia.org/wiki/Code_coverage#Coverage_criteria

The idea is that if a tool can tell us our coverage based on multiple criteria then that becomes a reasonable automated assessment of test quality. I by no means am trying to say that line coverage is a good assessment. In fact that's the premise of my question.

Edit:

Ok, maybe I projected it a bit too dramatically, but you get the point. The problem is about setting processes/policies in general across all teams in a homogeneous/consistent fashion. And the fear is general that how do you ensure quality of tests, how do you allocate guaranteed time without having any measure to it. Thus I like having a measurable feature that when backed up with appropriate processes and the right tools would allow us to improve code quality while knowing that time is not being force spent in wasteful processes.

EDIT: So far what I have from the answers:

Code reviews should cover tests to ensure quality of tests

Test First strategy helps avoid tests that are written after the fact to simply increase coverage %

Exploring alternative tools that cover test criteria other than simply Statement/Line

Analysis of covered code/number of bugs found would help appreciate the importance of coverage and make a better case

Most importantly trust the Team's input to do the right thing and fight for their beliefs

Blocks Covered/# of tests - Debatable but holds some value

Thanks for the awesome answers so far. I really appreciate them. This thread is better than hours of brainstorm with the powers that be.

答:
Here are my 2 cents.

There are many practices that have received a lot of attention recently because they can bring benefits to software development. However, some developers apply those practices blindly: they are convinced that applying a methodology is like executing an algorithm and that after performing the correct steps one should get the wanted result.

Some examples:

Write unit tests with 100% code coverage and you will get better code quality.

Apply TDD systematically and you will get better design.

Do pair programming and you will improve code quality and reduce development time.

I think the basic problem with the above statements is that humans are not computers and writing software is not like executing an algorithm.

So, the above statements contain some truth but simplify things a bit too much, e.g.:

Unit tests catch lots of errors and code coverage indicates which parts of the code are tested, but testing trivial things is useless. For example, if by clicking on a button the corresponding dialog opens up, the whole logic sending the button event to the component that opens the dialog can be tested by a simple manual test (click on the button): does it pay off to unit test this logic?

While TDD is a good design tool, it does not work well if the developer has a poor understanding of the problem domain (see e.g. this famous post).

Pair programming is effective if two developers can work together, otherwise it is a disaster. Also, experienced developers may prefer to briefly discuss the most important issues and then code separately: spending many hours discussing lots of details that they both already know can be both boring and a big waste of time.

Going back to code coverage.

I have been able to push back by selling the argument that Code
  Coverage tells me what has not been tested for sure and help us focus
  on those areas.

I think you have to judge from case to case if it is worthwhile to have 100% coverage for a certain module.

Does the module perform some very important and complicated computation? Then I would like to test every single line of code but also write meaningful unit tests (unit tests that make sense in that domain).

Does the module perform some important but simple task like opening a help window when clicking on a button? A manual test will probably be more effective.

The argument from these folks is - then team would react by quickly
  creating low quality tests and thus waste time while adding no
  significant quality.

In my opinion they are right: you cannot enforce code quality by only requiring 100% code coverage. Adding more tools to compute the coverage and make statistics will also not help. Rather, you should discuss which parts of the code are more sensitive and should be tested extensively and which ones are less error-prone (in the sense that an error can be discovered and fixed much more easily without using unit tests).

If you push 100% code coverage onto the developers, some will start to write silly unit tests to fulfill their obligations instead of trying to write sensible tests.

how do you allocate guaranteed time without having any measure to it

Maybe it is an illusion that you can measure human intelligence and judgment.
If you have competent colleagues and you trust their judgment, you can
accept when they tell you "for this module, increasing the code coverage will bring very little benefit. so let's not spend any time on it" or, "for this module we need as much coverage as we can get, we need one extra week to implement sensible unit tests.".

So (again, these are my 2 cents): do not try to find a process and set parameters like code coverage that must fit all teams, for all projects and for all modules. Finding such a general process is an illusion and I believe that when you have found one it will suboptimal.

ContentLicense: CC BY-SA 3.0


问:
What's with the aversion to documentation in the industry?
There seems to be an aversion to writing even the most basic documentation. Our project READMEs are relatively bare. There aren't even updated lists of dependencies in the docs.

Is there something I'm unaware of in the industry that makes programmers dislike writing documentation? I can type out paragraphs of docs if needed, so why are others so averse to it?

More importantly, how do I convince them that writing docs will save us time and frustration in the future?

答:
Many of the other responses gloss over the point that there are at least two types of documentation: one set for other developers, and a different set for end users. Depending on your environment, you may also need additional documentation for system administrators, installers, and help desk personnel. Each target audience has different needs and levels of understanding.

Consider the (stereo-)typical developer: He is a coder by choice. He has chosen a career out of the public eye and spends long hours behind a keyboard communicating primarily with himself. The process of documentation is a form of communication and the skill set required to produce good documentation is antithetical to the skills required to produce good code.

A good documentation writer can communicate in multiple languages: the language of users, the language of management, the language of support staff, the language of developers. It is the job of a documentation writer to understand what a coder communicates and to translate that into a form that all of the other groups can understand.

When you expect coders to develop the skill necessary to become good communicators (written or otherwise) the amount of time spent honing the primary skill set (coding!) is decreased. The farther he gets from his comfort zone (coding and communicating with other coders), the more time and energy will be required to perform the task well. You can reasonably expect a professional coder to desire to focus primarily on his core competencies, at the expense of all others.

For this reason, documentation (with the exception of inline code comments) is best left to communicators, not coders.


问:
Finally block for methods - is it a bad idea?
The finally block for a try-catch structure is well known, and gives a really easy and elegant way to deal with some must-be-done code.

Therefore, I can see no reason why It shouldn't be good for methods too. For instance, lets say I'm writing some very complicated logic in a method, and I expect to end up with a bunch of boolean flags that will in turn lead to some decisions. Many times in such kind of methods I have branches of code where I would want to "break" the flow and just perform the "real stuff" that I called this method for, with the satisfying information I gathered so far.

So, Why isn't there such pattern? Or is there?

答:
The first thing is:

Don't have too complex functions doing too complicated things.

If you can't avoid complex functions, there are various other tools to handle the situation.

In C and other languages people often use goto for the reason.

void func() {
    /* .. code .. */
    if (condition()) goto end;
    /* ... more code ...*/
end:
    cleanup();
}
```
<p>Now some people dislike <code>goto</code> even in such cases, so they emulate <code>goto</code> using a <code>do { ... } while(0)</code> loop:</p>
<pre class="lang-c prettyprint-override"><code>void func() {
    do {
        /* .. code .. */
        if (condition()) break;
        /* ... more code ...*/
    } while(0);
    cleanup();
}
</code>```

Some languages, for instance PHP, allow giving a parameter to the break-keyword to jump multiple levels out:

function func() {
    do {
        /* .. code .. */
        if(something() {
            /* some code */
            if (condition()) break 2;
            /* ... */
        }
    /* ... more code ...*/
    } while(0);
    cleanup();
}
```
<p>But there are languages with higher-level constructs. C++ for instance has destructors, there people use the RAII pattern:</p>
<pre class="lang-cpp prettyprint-override"><code>struct cleanup {
    ~cleanup() {
        /* .. do cleanup ... */
    }
}

void func() {
    cleanup cleaner; // this stack object will be destroyed on
        // scope exit by calling the destructor
    if (condition()) return;
    /* ... more code ...*/
}
</code>```

Some other languages have neither goto, nor nested break, nor destructors. Thus Java programmers have to live with nested if's, abuse exceptions, ... or make the code simpler.

public static void func() {
    try {
        /* .. code .. */
        if(something() {
            /* some code */
            if (condition()) throw new ControlFlowException();
            /* ... */
        }
        /* ... more code ...*/
    } catch (ControlFlowException e) {
        /* ignore */
    } finally {
        cleanup();
    }
}
```

So yes, alternative concepts exist and differ by language.

Body:
The first thing is:

Don't have too complex functions doing too complicated things.

If you can't avoid complex functions, there are various other tools to handle the situation.

In C and other languages people often use goto for the reason.

void func() {
    /* .. code .. */
    if (condition()) goto end;
    /* ... more code ...*/
end:
    cleanup();
}

Now some people dislike goto even in such cases, so they emulate goto using a do { ... } while(0) loop:

void func() {
    do {
        /* .. code .. */
        if (condition()) break;
        /* ... more code ...*/
    } while(0);
    cleanup();
}

Some languages, for instance PHP, allow giving a parameter to the break-keyword to jump multiple levels out:

function func() {
    do {
        /* .. code .. */
        if(something() {
            /* some code */
            if (condition()) break 2;
            /* ... */
        }
    /* ... more code ...*/
    } while(0);
    cleanup();
}

But there are languages with higher-level constructs. C++ for instance has destructors, there people use the RAII pattern:

struct cleanup {
    ~cleanup() {
        /* .. do cleanup ... */
    }
}

void func() {
    cleanup cleaner; // this stack object will be destroyed on
        // scope exit by calling the destructor
    if (condition()) return;
    /* ... more code ...*/
}

Some other languages have neither goto, nor nested break, nor destructors. Thus Java programmers have to live with nested if's, abuse exceptions, ... or make the code simpler.

public static void func() {
    try {
        /* .. code .. */
        if(something() {
            /* some code */
            if (condition()) throw new ControlFlowException();
            /* ... */
        }
        /* ... more code ...*/
    } catch (ControlFlowException e) {
        /* ignore */
    } finally {
        cleanup();
    }
}

So yes, alternative concepts exist and differ by language.

ContentLicense: CC BY-SA 4.0


问:
What should every programmer know about programming?
Please, stay on technical issues, avoid behavior, cultural, career or political issues.

答: That whatever programs do, more than telling a machine how to do a work, they are a most unambiguous way of showing fellow human beings how to do a work.</p>

ContentLicense: CC BY-SA 2.5


答:
My guess is that there isn't a huge need for that sort of feature for two reasons:

Most languages already give you pretty explicit flow control with looping and branching constructs.

One of the most common uses of finally is to ensure resources are safely disposed. If your method is so complicated that you need this, you should probably refactor it into more manageable pieces.

Title: Finally block for methods - is it a bad idea?

Body:
The finally block for a try-catch structure is well known, and gives a really easy and elegant way to deal with some must-be-done code.

Therefore, I can see no reason why It shouldn't be good for methods too. For instance, lets say I'm writing some very complicated logic in a method, and I expect to end up with a bunch of boolean flags that will in turn lead to some decisions. Many times in such kind of methods I have branches of code where I would want to "break" the flow and just perform the "real stuff" that I called this method for, with the satisfying information I gathered so far.

So, Why isn't there such pattern? Or is there?


答:
I would say that the main reason is a lack of will and a lack of understanding of the function of documentation. There are a number of classes of documentation to consider:

Product/Release Documentation

This is anything that goes out with your 'finished' product. This is more than just manuals, this is READMEs, Change Logs, HOW-TOs and the like. In theory, you can get away with not writing these, but you end up with a product that people don't want to use, or a support burden that is unnecessarily expensive.

API Documentation

This describes something that should be relatively static. Since numerous consumers may be coding to your API, it should be sufficiently stable enough that some prose describing how to use it has value. Describing what parameters are supported, what the return value can be and what errors may be thrown will allow other users the ability to understand your API at the right level of abstraction - the interface (not the implementation).

Code Comments

The industry opinion on comments seems to be in flux, at the moment. When I first started coding professionally, comments were a sine qua non when it came to writing code. Now, the fashion is to write code that is so clear, comments are unnecessary. I'd hazard a guess that this is, in part, due to the fact that many modern languages are written at a much higher level and it's way easier to write legible code in Java, JavaScript, Ruby, etc. than it was in assembler, C, FORTRAN, etc. Thus, comments had a much greater value.

I still believe that there is value in comments that describe the intention of a section of code, or some details about why a certain algorithm was chosen over a more obvious one (to avoid over-zealous refactoring fiends from 'fixing' code that doesn't actually need to be fixed).

Unfortunately, there's a lot of selfishness, rationalization and self-delusion involved in programmers' decisions not to document. The reality is that, like code, the primary audience for documentation is other people. Thus, the decisions to write (or not write) documentation, at any level, is one that should be made at the team level. For the higher levels of abstraction, it may make more sense to have someone, other than developers, to do it. As for documentation at the comment level, reaching an agreement on the purpose and intent of comments should be agreed upon together, especially in mixed ability and experience teams. It's no good having senior developers writing code that junior developers can't approach. Some well placed and well written documentation can allow a team to operate much more effectively

Title: What's with the aversion to documentation in the industry?

Body:
There seems to be an aversion to writing even the most basic documentation. Our project READMEs are relatively bare. There aren't even updated lists of dependencies in the docs.

Is there something I'm unaware of in the industry that makes programmers dislike writing documentation? I can type out paragraphs of docs if needed, so why are others so averse to it?

More importantly, how do I convince them that writing docs will save us time and frustration in the future?


答:
First off, people do advocate 100% coverage:

Most developers view ... "100% statement coverage" as adequate.  This is a good start, but hardly sufficient.  A better coverage standard id to meet what's called "100% branch coverage," ...

Steve McConnell, Code Complete, Chapter 22: Developer Testing.

As you and others have mentioned, code coverage for the sake of coverage alone isn't likely to accomplish much.  But if you can't make a line of code execute, why is it written?

I'd suggest resolving the argument by gathering and analyzing data on your own projects.

To gather the data, I personally use the following tools:

JaCoCo and the associated Eclipse plugin EclEmma for measuring code coverage.

Ant scripts for automated building, testing, and reporting.

Jenkins for continuous builds - any change in source control triggers an automatic build

JaCoCo Plugin for Jenkins - captures coverage metrics for each build, and graphs trends.  Also allows definitions of per-project coverage thresholds that affect the health of the build.

Bugzilla for tracking bugs.

Once you have that (or something similar) in place, you can start to look at your own data more closely:

are more bugs found in poorly covered projects?

are more bugs found in poorly covered classes/methods?

etc.

I'd expect that your data will support your position on code coverage; that has certainly been my experience.  If it doesn't, however, then maybe your organization can succeed with lower code coverage standards than you'd like.  Or maybe your tests aren't very good.  The task will hopefully focus effort on producing software with fewer defects, regardless of the resolution of the code coverage disagreement.

Title: Any tools/suggestions on how to refute code coverage quality argument

Body:
Now I know people could consider this question duplicate or asked many times, in which case I would appreciate a link to relevant questions with answer to my question.

I have been recently in disagreement with some folks about code coverage. I have a group of people who want our team to drop looking at code coverage altogether based on the argument that 100% coverage does not mean good quality tests and thus good quality code.

I have been able to push back by selling the argument that Code Coverage tells me what has not been tested for sure and help us focus on those areas.

(The above has been discussed in a similar fashion in other SO questions like this one - https://stackoverflow.com/questions/695811/pitfalls-of-code-coverage)

The argument from these folks is - then team would react by quickly creating low quality tests and thus waste time while adding no significant quality.

While I understand their point of view, I am searching for a way to make a more robust case for code coverage by introducing more robust tools/frameworks that take care of more coverage criteria (Functional, Statement,Decision, Branch, Condition, State, LCSAJ, path, jump path, entry/exit, Loop, Parameter Value etc).

What I am looking for is suggestion for a combination of such code coverage tools and practices/processes to go with them which can help me counter such arguments while feeling comfortable about my recommendation.

I would also welcome any accompanying comments/suggestions based on your experience/knowledge on how to counter such an argument, because while subjective, code coverage has helped my team be more conscious of code quality and value of testing.

Edit: To reduce any confusion about my understanding of weakness of typical code coverage, I want to point out that I am not referring to Statement Coverage(or lines of code executed) tools(there are plenty). In fact here is a good article on everything that is wrong with it: http://www.bullseye.com/statementCoverage.html

I was looking for more than just statement or line coverage, going more into multiple coverage criteria and levels.

See: http://en.wikipedia.org/wiki/Code_coverage#Coverage_criteria

The idea is that if a tool can tell us our coverage based on multiple criteria then that becomes a reasonable automated assessment of test quality. I by no means am trying to say that line coverage is a good assessment. In fact that's the premise of my question.

Edit:

Ok, maybe I projected it a bit too dramatically, but you get the point. The problem is about setting processes/policies in general across all teams in a homogeneous/consistent fashion. And the fear is general that how do you ensure quality of tests, how do you allocate guaranteed time without having any measure to it. Thus I like having a measurable feature that when backed up with appropriate processes and the right tools would allow us to improve code quality while knowing that time is not being force spent in wasteful processes.

EDIT: So far what I have from the answers:

Code reviews should cover tests to ensure quality of tests

Test First strategy helps avoid tests that are written after the fact to simply increase coverage %

Exploring alternative tools that cover test criteria other than simply Statement/Line

Analysis of covered code/number of bugs found would help appreciate the importance of coverage and make a better case

Most importantly trust the Team's input to do the right thing and fight for their beliefs

Blocks Covered/# of tests - Debatable but holds some value

Thanks for the awesome answers so far. I really appreciate them. This thread is better than hours of brainstorm with the powers that be.


问:
Store a tree with near next neighbours
I would to find an efficient structure (speed and volume) to store nodes and their neighbourhood.

My input is build out of stings in the following format

```<code> ./X/Y.log
</code>```

where X ∈ [0,359] and Y ∈ [0,169] and each pair of (X,Y) defined the coordinate of a cell on a grid of the size [170x360].

I would like to find which cells are neighboured (above, below, right and left), maximal 4 possibilities and to store this information (coordinate and direction). The structure, where the information will be stored, should not contain duplicate information (e.g. cell (50,50) is neighboured to cell (51,50) from the left side, but cell (51,50) is as well neighboured to cell (50,50) from the right side. Only one of those likes should be stored).

An additional information, the number of input strings (format ./X/Y.log) is not more then 5% of the total amount of possible cells (360*170 = 61200 possible cells).

Which storage structure should I good to my problem? (The code would be written in C++)

答: I think a graph data structure would solve your problem. Since the connections are non-directional, a tree might be difficult to implement. Also, with a tree, the "child" of one node might be the "child" of another node leading to issues of how to build the tree structure.</p>

Title: Store a tree with near next neighbours


答:
It's worth noting that C# has the using statement which will automatically call Dispose() on the object when it leaves scope.  This includes disposing of it after a return statement, so it acts like a finally in that respect.

Note that this is tied to the object, not tied to the function.  But it does handle the main usecase for a finally in a function.


问:
The 10 minutes technical interview
I must do a quick assessment of dozens of fresh students very quickly. I have 30 minutes meeting with each of them (in two or three days). I want to use most of the time to discuss non technical aspects. So I plan to use 10 minutes for technical questions. The same questions for all of them.

They are all hired already (they are students), what I need to know is the average level in order to prepare a training.

Ideally, the difficulty must be progressive in order to set a level for each. Level I will average, and I'll do an average on each question too.

If you had only 10 minutes and 10 questions to ask to a candidate, what would be your top 10 ?

答:
Start from the lowest levels of the software stack and up.

What is BIOS?

What is the role of the operating system?

What is multi-tasking? What is dynamic linking?

Describe how source code is transformed to a working program for the student's language of choice (example answer for C: preprocessor -> compiler -> a bunch of object files -> linker -> executable)

What is a cache? Estimate relative access times to L1 cache, L2 cache, RAM, rotational disk (i.e., not SSD).

Enumerate data structures that you could implement without looking up details in the literature.

What is the most complex program you wrote? What made it complex?

Explain recursion on an example of own choice.

Why do programs crash?

Explain what is a critical section and give an example where it would be used.

Title: The 10 minutes technical interview


问:
Displaying items with a countdown timer
I am creating a widget for rotating topics. The functionality is as follows:

Each topic is displayed one by one on the homepage and has a duration of 30 seconds.

A countdown timer is displayed on the page. When it reaches zero the current topic gets marked as "shown" and the next topic is displayed.

Users can choose to "like" topics, in which case the topic gets an additional 5 seconds duration (the countdown timer needs to update itself at this point).

The countdown timer always needs to display the current allocated duration for the topic, so for example if a user "likes" a topic then people accessing the site should instantly see the updated duration for that topic. Basically everything needs to be shown in "realtime".
The topics are stored in a MySQL database. I am having trouble with the last two points in the above.

The way I have tried to do it so far is to have an AJAX request which is sent every second to deduct 1 second from the current topic duration. The request response is the current topic duration.

The problem with this is that it will only work so long as somebody is accessing the site. I know I can probably create a CRON script to run this process in the background, but for it to run every second would be a bit crazy. There has got to a be a much simpler solution to this problem. What would be the most efficient way to go about this?

答:
I don't like long-polling in general, but I have to admit that this would be a perfect application for http://en.wikipedia.org/wiki/Comet_%28programming%29.  Just make a request, keep it open, consume data as it is sent.

You will have fewer requests on your webserver, and users will get updates with much less latency than you currently have.

Title: Displaying items with a countdown timer


问:
Representation of data in application versus database
I'm going to make an application that will be given data to put in a database. The data will for the most part be the same, but the way it is formatted will vary a lot (could be in anything from text files to .xls to .doc).

I'm not a very experienced developer, but I can see some potential issues and I want to minimize them.

First off I have decided to use the DAO pattern, so that I can easily support new file formats or file suddenly formatted in different ways.

What I really wonder about though, is how I should manage the data itself within my application. I'm thinking that the database DAO should have models representing each table of the database with the same relations between them, to make the uploading process easy. But should the filesystem DAO's have to use the same models? I can imaging that when the database changes, the change will suddenly propagate throughout the entire system, all DAOs and models alike. And that is obviously a bad thing.

I'm a little bit tired and out of time. Will update with what ever questions you have.

Thanks!

答:
Are you intending to manipulate the data in the database?  If the answer is not an immediate yes, then store files as a binary blob.

If the answer is still a yes, then you may still want to store the original files as a blob.  But also try to break out an appropriate data structure for your analysis, and try to automate extraction of that from the original file.  Keep track of when automation had trouble, and what trouble it had.  Because you always have the original, when you figure out how to address that problem, you can reanalyze that file properly.


问:
Is there a standard for Error Codes?
I've created a gateway which receives a POST from cUrl on one system which is a well-formed XML string. After processing the gateway sends back a response XML. All the fields in the XML are required and while the system sending the data constructs the XML itself I'm running some validation to make sure that every value that's being stored in the Request Class is actually.

One thing my gateway does is that the response can also indicate an error and sends a message and response code which is then displaced on the system as the following message:

An unknown error occurred while processing.
  Code: #
  Message: ERROR_MESSAGE

The original code just sends Code as 0 if there was no error or 1 if there was. I'm thinking of giving Code another value depending on the error since displaying Code in the error message is kinda useless if it's only ever going to be 1 (since you'll never see 0). So I'm wondering if there is a standard for creating error codes, particularly with PHP and XML.

答:
I am not aware of any specific standard that could help you.

However, there are standard protocols to pass data on the web.

SOAP has a concept of soap fault

The SOAP Fault Element

The optional SOAP Fault element is used to indicate error messages.

REST generally uses HTTP error codes. Here is an example list to show you how it could be done.

I would strongly advise you to adopt an open standards for your gateway and conform to known patterns. After all, gateways are meant to be shared resources...

Title: Is there a standard for Error Codes?


问:
Do I go by ID or by Label while programming?
Suppose I have a table "Progress" with two columns.
One column is ID which is identity.
Another column is Progress_Label

ID    Progress_Label

1     Submitted

2     Approved by user

3     Rejected by leadership

4     Cancelled

5     Completed

What is the best programming practice, should I go by ID or by label? In my stored procedures, functions, or in programming code methods etc should I search records by the ID = 3 for example or should I type "Where progress_lable is Rejected by leadership" ?

If somebody would want to edit the labels, all the code would stop working if I go by the label?

At the same type if I type the label, code looks more understandable since it says right in the code what is it we are looking for?

Are there any articles regarding this?

答:
Create a method called
GetProgressIdByLabel so you can do something like

```<code>int progressId = GetProgressIdByLabel("Submitted")
</code>```

This reads nicely, your method should throw an exception if someone uses a label that doesn't exist

Body:
Create a method called
GetProgressIdByLabel so you can do something like

int progressId = GetProgressIdByLabel("Submitted")

This reads nicely, your method should throw an exception if someone uses a label that doesn't exist


答:
Use the ID.

The label does change, sometimes, and for human-readable code you can just use things like enums:

```<code>enum DocumentProgress
{
    Submitted = 1,
    Approved by user = 2,
    Rejected by leadership = 3,
    Cancelled = 4,
    Completed = 5
}
</code>```

Which might be used like this:

```<code>Item.Progress = DocumentProgress.Submitted;
</code>```

Title: Do I go by ID or by Label while programming?

Body:
Suppose I have a table "Progress" with two columns.
One column is ID which is identity.
Another column is Progress_Label

ID    Progress_Label

1     Submitted

2     Approved by user

3     Rejected by leadership

4     Cancelled

5     Completed

What is the best programming practice, should I go by ID or by label? In my stored procedures, functions, or in programming code methods etc should I search records by the ID = 3 for example or should I type "Where progress_lable is Rejected by leadership" ?

If somebody would want to edit the labels, all the code would stop working if I go by the label?

At the same type if I type the label, code looks more understandable since it says right in the code what is it we are looking for?

Are there any articles regarding this?

Body:
Use the ID.

The label does change, sometimes, and for human-readable code you can just use things like enums:

enum DocumentProgress
{
    Submitted = 1,
    Approved by user = 2,
    Rejected by leadership = 3,
    Cancelled = 4,
    Completed = 5
}

Which might be used like this:

Item.Progress = DocumentProgress.Submitted;


问:
Which are the significant algorithms for humankind in past decades?
Which world most important algorithms have contributed most to humankind in past decades?

I thought this is a good general knowledge for a developer to know about.

Update:

If possible, please keep the answer to a specific programming algorithm.

I would like to get a list of the most important ones, only one algorithm per answer.

Please consider to state why the algorithm is significant and important...

答:
Smith-Waterman (and Needleman-Wunsch)

This may be too far fetched so please comment.

Smith-Waterman: The Sequence Alignment Algorithm

I think one of such examples is the Smith-Waterman and Needleman-Wunsch algorithms and their approximations. All of them are essentially doing the same thing: they align two or more strings (sequences). There is a significance in Biology. When DNA or Protein sequences are aligned - regions of structural, functional and evolutionary similarity are revealed.

BLAST as a descendant of Smith-Waterman

A heuristic that approximates Smith-Waterman is BLAST. It allows searching sequences of large databases for Biological similarity. The popularity of BLAST is really great - it's very likely the most widely used algorithm in Biology. The newer areas in Bioinformatics and Genomics have newer and better approximations of Smith-Waterman/Needleman-Wunsch algorithms that are more accurate than BLAST.

Genome Assembly as a descendant of Smith-Waterman

High-throughput approximations of Smith-Waterman and Needleman-Wunsch that are faster than BLAST are used to assemble Genomes from shotgun sequencing - where the product of the sequencer machine is a huge amount DNA reads (billions) from arbitrary parts of the Genome that are very short (50 to 100 nucleotides). The approach was used to complete the Human Genome Project. All modern sequencing is done this way.

Multiple Sequence Alignment an extension of Smith-Waterman

Numerous Multiple Sequence Alignment algorithms exist - they are approximating a multi-sequence version of the Smith-Waterman/Needleman-Wunsch. Multiple sequences are aligned as a group simultaneously to each other.  It's a much harder problem than it's pairwise counterpart, but the solutions provide much more insight into Biological function, structure, and evolutionary history of related sequences.


答:
I don't think it's helpful to speculate on the motivations of people who aren't adopting something you think is good practice or who are continuing to do something you see as bad practice. In this business, the people who fall into one or both of those categories will far outnumber the ones who you'll see eye-to-eye with, so stop making yourself crazy.

Instead, focus on the problem and possible resolutions.

1. Write Good Documentation Yourself

It may not be realistic to expect that everyone on your team will direct their efforts to the things you see as a problem. This is especially true if you're a relative newcomer to the team. I'd venture to guess that you are, because if you were a founding member of the team, it seems quite likely you'd have already resolved this issue early on.

Consider, instead, working toward the goal of writing good documentation yourself and getting people to use it. For example, if someone on my team asks me where the source code for Project A is or what special configuration Project A needs, I point them to the Project A wiki page.

If someone asks me how to write a new implementation of Factory F to customize a thing for Client C, I tell them it's on page 10 of the developer guide.

Most developers hate asking questions that could make them look like they can't just "read the code" even more than they hate reading documentation, so after enough replies of this nature, they will go to the docs first.

2. Prove the Value of Your Documentation

Make sure that you take every opportunity to point out where the documentation is proving its value (or would have, if used). Try to be subtle and avoid "I told you so," but it's perfectly legitimate to say things like

For future reference, the wiki page of this project has information about the branch of the core code that was created for ongoing support of release 2.1, so in future we can avoid having to do a full regression test if people who are maintaining released versions check the wiki before checking out the code.

or

I am so glad I wrote down the steps for doing Task T. I don't really care if no one else ever uses it--it's already saved me more time than what I spent writing it.

3. Get Management on Board

After a few incidents where having documentation is provably saving time/money, you'll probably notice a distinct "thaw" toward documentation.  This is the time to press the point by starting to include documentation time in your estimates (though honestly I usually update/create docs while long processes are running, such as compiles or check-ins). Especially if this is a recent hire, it's possible this won't be questioned, but instead viewed as a new practice you're bringing in from a previous workplace (which it may well be).

Word of caution: Most bosses don't like to make people do anything, especially things not directly tied to a billable task, so don't expect this support to be in the form of a mandate. Instead, it's more likely to give you relatively free rein to write more docs.

4. Encourage Documentation When You See It

Maybe part of the reason people don't write docs as often as they should is they feel no one is reading it. So, when you see something you like, make sure to at least mention that you were glad it was available.

If your team does code reviews, this is a time where you can drop in a subtle word or two to encourage good comments.

Thank you for documenting the workaround for bug B in Framework G. I didn't know about that, and I don't think I could have understood what you were doing without that in there.

If you have someone on the team who's actually enthusiastic about documentation, it doesn't hurt to cultivate that person through going to lunch or coffee and making sure to offer a little validation to counteract the discouragement they may get from seeing the rest of the team doesn't value the documentation as much.

Beyond that, it's really not your problem unless you're in a lead or management position. You can lead a horse to water, but you can't make it drink. If it's not your horse, you might not be happy that it's thirsty, but all you can do is fill the trough.


问:
What are the pros and cons of HTML5, native and hybrid mobile app approaches?
I want to develop a mobile application. I recently read an article on Telerik Forum, which compares among three types of mobile application and I don't know which one should I select to begin with. Here is an image describing the pros and cons of different mobile design choices

To decide between these design choices, I would like to better understand the pros and cons of each architecture choice listed in the diagram.  What are the pros and cons of each architecture approach?

答:
With the below, my current stance on this debacle is that hybrid is good to start with, to explore your app, quickly iterate on customer feedback and stabilize the feature set. Then, to rewrite the app to native according to the spec, to enhance the experience.

I've left Mobile Web out, because it serves a completely different purpose. If you want to be in the app stores, Native/Hybrid is the way to go. If you want to simplify deployment and willing to sacrifice experience and technical ability, go for Mobile Web.

Pro/Cons Native:

Pro: It fits with the rest of the device experience, no uncanny valley issues.

Pro: It mostly provides a smooth consistent UI experience, no delays, no stutters.

Pro: Few technical limitations, you can fully utilize the device.

Pro: Native tools provide compliance with app stores validation.

Pro: Native frameworks include tweaks per platform version, less time spent on fine-tuning.

Con: It's build to last, and therefore takes more time to build.

Con: Requires polyglot-developers which are hard to find, expensive.

Con: Need to familiarize each device platform API's (iOS/Android/etc).

Con: Steep learning curve.

Con: Different toolset per platform.

Pro/Cons Hybrid:

Pro: Single codebase to target multiple device platforms.

Pro: Quick development cycles, great fexibility in layout, perfect for prototyping and MVP's.

Pro: Comfortable learning curve, lots of documentation, frameworks to help you out.

Pro: Single development toolset. Chrome debugger tools are excellent.

Pro: One codebase to target multiple device platforms.

Pro: Lots of developers available, easy to learn.

Con: Requires decent UI framework to adapt UI for every different platform to be consistent with the device experience. There are solutions like Kendo UI, Sencha Touch.

Con: Need to be very conscious about memory and compute usage, some CSS, javascript loops can seriously slow down the app. Not very good tools available on-device to debug.

Con: Not matured yet, things can suddenly change, tools are getting better though.


答:
For rapid access and efficient storage of the data you want, you can store a pair of std::set objects whose entries are the coordinates of cells.  The first is the set of cells with a neighbour to the right, the second the set of those with a neighbour below it.

If efficiency producing this structure matters to you, then I would recommend building a set of all coordinates of cells, then iterating over it and for each cell finding out whether its neighbours to the right and bottom are in the set.  (Both lookups are fast.)

If you need to consider more distant neighbours, then use a std::map to store the coordinates of the cell as the key, and the coordinates of the neighbour as a value.  To find those neighbours, you can use a http://en.wikipedia.org/wiki/Quadtree.

Title: Store a tree with near next neighbours

Body:
I would to find an efficient structure (speed and volume) to store nodes and their neighbourhood.

My input is build out of stings in the following format

```<code> ./X/Y.log
</code>```

where X ∈ [0,359] and Y ∈ [0,169] and each pair of (X,Y) defined the coordinate of a cell on a grid of the size [170x360].

I would like to find which cells are neighboured (above, below, right and left), maximal 4 possibilities and to store this information (coordinate and direction). The structure, where the information will be stored, should not contain duplicate information (e.g. cell (50,50) is neighboured to cell (51,50) from the left side, but cell (51,50) is as well neighboured to cell (50,50) from the right side. Only one of those likes should be stored).

An additional information, the number of input strings (format ./X/Y.log) is not more then 5% of the total amount of possible cells (360*170 = 61200 possible cells).

Which storage structure should I good to my problem? (The code would be written in C++)


答:
Here are my two cents.

The Agile Manifesto states "Working software over comprehensive documentation" and not everybody reads on to reach "That is, while there is value in the items on the right, we value the items on the left more."

Sadly it's common to https://en.wikipedia.org/wiki/Code_and_fix and the documentation doesn't work with this model (It gets out of sync).

Software development industry is not regulated well. There is no legal requirement to write documentation.

Self-documenting code is the current trend.

Having said that, I think there is a lot of good documentation out there.


答:
Reading the code shows you how it works.  It cannot explain why: you need comments.

Reading the code shows you the name of a method, and the types of the parameters.  It cannot explain the semantics, or the exact intention of the author: you need comments.

Comments do not replace reading the code, they add to it.


问:
How to compute a signature of a matrix
We know some signature/checksum methods for text, like md5,sha.

Now, I want to compute a checksum for a matrix, to represent the exact matrix. Say, two matrixes with different sizes, or with different values, have different checksum. And slightly different matrixes(same size) result in slightly different checksum. So, both layout and values should be considered.

Although the most intuitive method is  to compare two matrixes directly, however, sometimes it's inconvenient to get the two matrixes in the same environment.

Maybe I should check the md5 algorithm, and adapt a similar method. Just post it here for better advices.

答:
Of the top of my head, it should be fine to convert the martix to a string representation and then do an MD5 of that. The string representation of two matrices with identical dimensions and identical entries would be identical.

For example, despite having identical objects when converted to a single dimension, these two matrices have different string representations.

```<code>"[[1,2],[3,4]]" != "[1,2,3,4]"
</code>```

However you approach this, you'll need to compare dimentionality and contents.

Title: How to compute a signature of a matrix

Body:
Of the top of my head, it should be fine to convert the martix to a string representation and then do an MD5 of that. The string representation of two matrices with identical dimensions and identical entries would be identical.

For example, despite having identical objects when converted to a single dimension, these two matrices have different string representations.

"[[1,2],[3,4]]" != "[1,2,3,4]"

However you approach this, you'll need to compare dimentionality and contents.


答:
Does this really make your code more readable than alternatives?  You could already put a try/finally around the code inside your function or you could put the "Finally" code right after the method is called.

Although it's a reasonable concept, every new feature you place into a language requires many many programmer hours of time to learn and understand--hundreds--thousands...  If there is any way you can use an existing construct instead without causing a lot of duplication, boilerplate or confusion then it would be much better to use the existing mechanism.


问:
Pros/cons between emphasizing client-side or server-side processing
Why would I want to write a web app with lots of processing server-side?

To me, writing the program client-side is a huge advantage because it takes away as much server load as possible because it only has to send data to the client with minimal processing.

I see very little on writing web-apps besides writing it server-side and treating client-side as only a view. Why would I ever want to do this? The only advantage I see is that I can write in whatever language I want (http://www.paulgraham.com/avg.html).

答:
Client Side Versus Server Side

Client side processing is in line with the more popular REST standards as well as MVC as opposed to page based approaches and SOAP. The emergence of these trends and focus on AJAX and Html-RIA, client side scripting is on the rise and more popular; however, due to security concerns and client capability, client-side scripting has a particular niche and should not be used for everything.

Considerations:

Mobile

If a large segment of your target audience will be mobile users, heavy processing should be left up to the server.

Cross-browser consistency

Web standards have come a long way and this may not be as much of a concern, but every web developer knows that IE 6,7, and 8 and sometimes Safari can act funny on the client side--certain functions may not run because of security restrictions and others because of un-implemented standards. It's also important to note that the end user can configure a browser to have certain restrictions or even completely turn client-side processing off (no javascript!).  If consistency is a requirement for 100% of users (and especially if you're doing something unorthodox) server side is most important.

Security

Any data manipulation that you want to secure needs to be done on the server. Any data that is processed on the client side is absolutely open for manipulation. For example, if you have a javascript function that processes some information that then gets posted back into the system--it would be very easy to manipulate the result just before it is posted back even if you have exemplary back-end security

UI/UX

Client-side processing is left for the user interface and creating rich internet applications (RIAs). It is used to create animations, effects, user interactions, as well as dynamically loading content through AJAX calls instead of re-loading a whole page.


问:
Gathering all data in single iteration vs using functions for readable code
Say I have an array of runners with which I need to find the tallest runner, the fastest runner, and the lightest runner. It seems like the most readable solution would be:

```<code>runners = getRunners();
tallestRunner = getTallestRunner(runners);
fastestRunner = getFastestRunner(runners);
lightestRunner = getLightestRunner(runners);
</code>```

..where each function iterates over the runners and keeps track of the largest height, greatest speed, and lowest weight. Iterating over the array three times, however, doesn't seem like a very good idea. It would instead be better to do:

```<code>int greatestHeght, greatestSpeed, leastWeight;
Runner tallestRunner, fastestRunner, lightestRunner;
for(runner in runners){
    if(runner.height > greatestHeight) { greatestHeight = runner.height; tallestRunner = runner; }
    if(runner.speed > ...
}
</code>```

While this isn't too unreadable, it can get messy when there is more logic for each piece of information being extracted in the iteration.

What's the middle ground here? How can I use only a single iteration while still keeping the code divided into logical units?

答:
You can return all three values in one go. In pseudo code close to Scala:

```<code>val (fastest, tallest, lightest) = runners
  .foldLeft(...)(((tallestSoFar, fastestSoFar, lightestSoFar),runner) =>
   (tallest(runner, tallestSoFar),
    fastest(runner, fastestSoFar),
    lightest(runner, lightestSoFar))
</code>```

That will give you a tuple of the runners you're looking for. You can do the same in other languages. You might have to grab a library like Guava or Underscore to do it, and you might have to wrap the tuple in an object.

Body:
You can return all three values in one go. In pseudo code close to Scala:

val (fastest, tallest, lightest) = runners
  .foldLeft(...)(((tallestSoFar, fastestSoFar, lightestSoFar),runner) =>
   (tallest(runner, tallestSoFar),
    fastest(runner, fastestSoFar),
    lightest(runner, lightestSoFar))

That will give you a tuple of the runners you're looking for. You can do the same in other languages. You might have to grab a library like Guava or Underscore to do it, and you might have to wrap the tuple in an object.


答:
Taskinoor has the right idea, but there's a better way to implement it... provided your language supports passing a function reference around.

For example, here's how I'd do it in C#-ish style:

```<code>// Define three anonymous functions which take two Runners, compare them, and return one.
Func<Runner, Runner, Runner> tallest = (x,y) => x.height > y.height ? x : y;
Func<Runner, Runner, Runner> fastest = (x,y) => x.speed > y.speed ? x : y;
Func<Runner, Runner, Runner> lightest = (x,y) => x.weight < y.weight ? x : y;

// Default everything to the first runner, to keep things simple
Runner tallestRunner = fastestRunner = lightestRunner = runners.First();

// Loop
foreach(runner in runners){
    tallestRunner = tallest(tallestRunner, runner);
    fastestRunner = fastest(fastestRunner, runner);
    lightestRunner = lightest(lightestRunner, runner);
}
</code>```

This is trivial to expand - rather than defining three functions, you can define an array of Func<Runner, Runner, Runner> anonymous functions, and just run them all.  You can even do it with regular functions like Runner pickTallest(Runner x, Runner y), although then you need to explicitly define them. The key, though, is that you don't have to actually track the value for each stat - you just need to know how to compare two Runners and choose the one with the better value.

Title: Gathering all data in single iteration vs using functions for readable code

Body:
Say I have an array of runners with which I need to find the tallest runner, the fastest runner, and the lightest runner. It seems like the most readable solution would be:

```<code>runners = getRunners();
tallestRunner = getTallestRunner(runners);
fastestRunner = getFastestRunner(runners);
lightestRunner = getLightestRunner(runners);
</code>```

..where each function iterates over the runners and keeps track of the largest height, greatest speed, and lowest weight. Iterating over the array three times, however, doesn't seem like a very good idea. It would instead be better to do:

```<code>int greatestHeght, greatestSpeed, leastWeight;
Runner tallestRunner, fastestRunner, lightestRunner;
for(runner in runners){
    if(runner.height > greatestHeight) { greatestHeight = runner.height; tallestRunner = runner; }
    if(runner.speed > ...
}
</code>```

While this isn't too unreadable, it can get messy when there is more logic for each piece of information being extracted in the iteration.

What's the middle ground here? How can I use only a single iteration while still keeping the code divided into logical units?

Body:
Taskinoor has the right idea, but there's a better way to implement it... provided your language supports passing a function reference around.

For example, here's how I'd do it in C#-ish style:

// Define three anonymous functions which take two Runners, compare them, and return one.
Func<Runner, Runner, Runner> tallest = (x,y) => x.height > y.height ? x : y;
Func<Runner, Runner, Runner> fastest = (x,y) => x.speed > y.speed ? x : y;
Func<Runner, Runner, Runner> lightest = (x,y) => x.weight < y.weight ? x : y;

// Default everything to the first runner, to keep things simple
Runner tallestRunner = fastestRunner = lightestRunner = runners.First();

// Loop
foreach(runner in runners){
    tallestRunner = tallest(tallestRunner, runner);
    fastestRunner = fastest(fastestRunner, runner);
    lightestRunner = lightest(lightestRunner, runner);
}

This is trivial to expand - rather than defining three functions, you can define an array of Func<Runner, Runner, Runner> anonymous functions, and just run them all.  You can even do it with regular functions like Runner pickTallest(Runner x, Runner y), although then you need to explicitly define them. The key, though, is that you don't have to actually track the value for each stat - you just need to know how to compare two Runners and choose the one with the better value.


问:
Dependency properties outside the realm of WPF?
Is there a more general concept or name for what WPF calls "dependency properties"? I imagine this is not a WPF-ism and in fact other libraries or frameworks have employed a similar approach? If so, what are these other instances and what are the similarities and differences compared to Microsoft's dependency properties?

I am at a junction where I'm considering adding "dependency properties" to my own type system and object model (unrelated to WPF), as the construction seems appropriate for my design requirements; however, I want to consider what others have created as well, not just WPF's particular implementation.

答:
Dependency Properties are used whenever you need a binding mechanism, i.e. a way to reflect changes to a property onto another one.

This is very useful in XAML, where you can bind attributes in the markup (without using code) and let the DP mechanism handle that.

Since you are familiar with WPF, you already know that. But the additional step is that XAML can be used to represent different object models. Workflows, for example! Take a look at WF3 (the original Workflow Foundation framework, which shipped with .NET 3.0) to see how DP are used there, it shows you how they can work (rather well) outside of the WPF world.

NOTE: look specifically at WF3: as pointed out in the comments, WF4 is quite different (it uses InArguments and OutArguments to pass values between activities, and I have no idea how those are implemented under the cover). Also, note that WF3 is obsolete, it is only good to look at it for didactic purposes - which is what you are looking for, I suppose


问:
clarification about amortized analysis
I was going through an article here

In the section named Aggregate Method ,the author says

Then summing over the entire sequence, all the 1's sum to O(n), and all the di also sum to O(n). That is,

and then gives this

```<code>Σ1≤i≤n ci   ≤   n + Σ0≤j≤m 2j−1
</code>```

I can understand how summing 1's to get n ,
But I am not very clear how the second term becomes Σ0≤j≤m 2j−1 and thereby O(n)

Sorry about the formatting..I am not sure how the math notations are to be printed here.. Will you please see the original article ?

答:
I can understand how summing 1's to get n , But I am not very clear how the second term becomes Σ0≤j≤m 2j−1 and thereby O(n)

That is how the algorithm performances (the big-oh) are estimated. It just shows how the algorithm behaves for large number of iterations.

If you do lots of iterations of an algorithm, which has O(1), then they are summed, and that is what your article tells.

Maybe you can look at the your sum as (f(n)-algorithm big-o value)

```<code>bigo=0;
for ( int i = 0; i < n; ++ i )
   bigo+=f(n);
</code>```

which translates for O(1) into :
    bigo=0;
    for ( int i = 0; i < n; ++ i )
       bigo+=1;

If your f(n) would be O(n), then you would do n*n the iteration loop, and then it would be f(n) :

```<code>bigo=0;
for ( int i = 0; i < n; ++ i )
  for ( int j = 0; j < n; ++ j )
     bigo+=1;
</code>```

HTH

Title: clarification about amortized analysis

Body:
I can understand how summing 1's to get n , But I am not very clear how the second term becomes Σ0≤j≤m 2j−1 and thereby O(n)

That is how the algorithm performances (the big-oh) are estimated. It just shows how the algorithm behaves for large number of iterations.

If you do lots of iterations of an algorithm, which has O(1), then they are summed, and that is what your article tells.

Maybe you can look at the your sum as (f(n)-algorithm big-o value)

bigo=0;
for ( int i = 0; i < n; ++ i )
   bigo+=f(n);

which translates for O(1) into :
    bigo=0;
    for ( int i = 0; i < n; ++ i )
       bigo+=1;

If your f(n) would be O(n), then you would do n*n the iteration loop, and then it would be f(n) :

bigo=0;
for ( int i = 0; i < n; ++ i )
  for ( int j = 0; j < n; ++ j )
     bigo+=1;

HTH


答:
More importantly, how do I convince them that writing docs will save us time and frustration in the future?

Does it do that?

There are two types of documentation:

Useful documentation

Documents how to use a finished product, an API, what IP adresses or URL names our servers have, etc. Basically, everything that is used heavy and on a daily basis. Wrong information will be found out quickly and will be corrected. Needs to be found easy and easy to edit (e.g. online Wiki).

Useless documentation

Documentation which changes often, very few people are interested in it and noone knows where to find it. Like the current state of a feature being implemented. Or requirement documents in a word doc hidden somewhere in SVN, updated 3 years ago. This documentation will take time to write, and time to find out that it is wrong later. You can't rely on this type of documentation. It is useless. It wastes time.

Programmers don't like to write or read useless documentation. But if you can show them documentation which is useful, they will write it. We had gread success with it in my last project when introducing a Wiki where we could write all the information in we need often.


问:
Does understanding history of a programming language help in understanding the language?
Sometimes, the syntax of a language seems weird, I often think, why would someone make something like that, but definitely there is a reason and a history behind every aspect of a programming language.

Apart from being fascinating, It helps me remember the syntax and also the purpose that language solves.

Does knowing the background of languages like HTML & CSS (Okay, these are not programming-languages but still) JavaScript, C++, Objective C and even Java help in understanding the aspects of these languages?

答:
Some things may be interesting to know. The history itself isn't important, but understand the why is. This way, the next time you will use the syntax, you will think about the reasoning behind such syntax rather than trying to simply remember the syntax itself.

It's often easier to remember A and a logical way to go from A to B then from A to C, than remembering what B and C are.


答:
Though history of computing and programming languages can be useful and interesting, I would argue that this is not much helpful, because new versions of a language try to fix old weird syntax. Take for instance how functions are declared in C (source: Function declaration: K&R vs ANSI):

```<code>// K&R syntax
int foo(a, p)
    int a;
    char *p;
{
    return 0;
}

// ANSI syntax
int foo(int a, char *p)
{
    return 0;
}
</code>```

This is even more visible when comparing Fortran 77 and Fortran 90.

Title: Does understanding history of a programming language help in understanding the language?

Body:
Sometimes, the syntax of a language seems weird, I often think, why would someone make something like that, but definitely there is a reason and a history behind every aspect of a programming language.

Apart from being fascinating, It helps me remember the syntax and also the purpose that language solves.

Does knowing the background of languages like HTML & CSS (Okay, these are not programming-languages but still) JavaScript, C++, Objective C and even Java help in understanding the aspects of these languages?

Body:
Though history of computing and programming languages can be useful and interesting, I would argue that this is not much helpful, because new versions of a language try to fix old weird syntax. Take for instance how functions are declared in C (source: Function declaration: K&R vs ANSI):

// K&R syntax
int foo(a, p)
    int a;
    char *p;
{
    return 0;
}

// ANSI syntax
int foo(int a, char *p)
{
    return 0;
}

This is even more visible when comparing Fortran 77 and Fortran 90.


答:
That really depends on your learning style (and whether the language has an interesting history). What history can tell you:

what motivated the initial design of the language, and what influences there were

when newer features were introduced, what shortcomings were being addressed, and how (if at all) they changed idiomatic usage

whether a given framework or library takes advantage of new language features and, conversely, whether it has a stable and long-term adoption base

whether uptake is a result of good technological fit or clever marketing.

What history can't tell you:

whether the designers got it right, either initially or during subsequent changes

whether the current state reflects a language you want to use

whether the current state corresponds to something you should use for your project.

Great examples of languages that have a history (whether or not you refer to it) include C++ and Java. In each case, when features were added to the language is documented, often along with why and whether users were already trying to solve a problem those new parts addressed.

Taking the example of C++ further, you can see that some additions to the standard came from third-party libraries like Boost. Also, Stroustrup's book does a good job of explaining the problems solved by the additions.


问:
Working for free?
I came across this article Work for Free that got me thinking.

The goal of every employer is to gain
  more value from workers than the firm
  pays out in wages; otherwise, there is
  no growth, no advance, and no
  advantage for the employer.
  Conversely, the goal of every employee
  should be to contribute more to the
  firm than he or she receives in wages,
  and thereby provide a solid rationale
  for receiving raises and advancement
  in the firm.

I don't need to tell you that the
  refusenik didn't last long in this
  job.

In contrast, here is a story from last
  week. My phone rang. It was the
  employment division of a major
  university. The man on the phone was
  inquiring about the performance of a
  person who did some site work on
  Mises.org last year. I was able to
  tell him about a remarkable young man
  who swung into action during a crisis,
  and how he worked three 19-hour days,
  three days in a row, how he learned
  new software with diligence, how he
  kept his cool, how he navigated his
  way with grace and expertise amidst
  some 80 different third-party plug-ins
  and databases, how he saw his way
  around the inevitable problems, how he
  assumed responsibility for the
  results, and much more.

What I didn't tell the interviewer was
  that this person did all this without
  asking for any payment. Did that fact
  influence my report on his
  performance? I'm not entirely sure,
  but the interviewer probably sensed in
  my voice my sense of awe toward what
  this person had done for the Mises
  Institute. The interviewer told me
  that he had written down 15 different
  questions to ask me but that I had
  answered them all already in the
  course of my monologue, and that he
  was thrilled to hear all these
  specifics.

The person was offered the job. He had
  done a very wise thing; he had earned
  a devotee for life.

The harder the economic times, the
  more employers need to know what they
  are getting when they hire someone.
  The job applications pour in by the
  buckets, all padded with degrees and
  made to look as impressive as
  possible. It's all just paper. What
  matters today is what a person can do
  for a firm. The resume becomes pro
  forma but not decisive under these
  conditions. But for a former boss or
  manager to rave about you to a
  potential employer? That's worth
  everything.

What do you think? Has anyone here worked for free? If so, has it benefited you in any way? Why should(nt) you work for free (presuming you have the money from other means to keep you going)? Can you share your experience?

Me, I am taking a year out of college and haven't gotten a degree yet so that's probably why most of my job applications are getting ignored. So im thinking about working for free for the experience?

答:
No. Never work for free for anyone but yourself. You'll get more out of good open-source credentials and personal projects, in the way of job-hunting, than you will out of working for some son of a b__ who thinks that your skills aren't worth paying for.

Of course, if no one is willing to pay for your skills, you may need to find another career: software development is wide open right now, so (depending on where you live, of course) it should be possible to get a job where you actually get paid.

Pro bono software development is theft.

Title: Working for free?


问:
Syntax-highlighting color scheme studies
Most programmers have their own personal preferences for syntax-highlighting color schemes, but I've been wondering, has anyone ever done an actual scientific study on what the best color scheme would be? I imagine such a study would look at things like the readability of the code, whether the programmer's eyes are drawn to the most important parts, etc.

Perhaps this was already done for something like the default Visual Studio theme, but I'd like to know if there are any publicly available studies out there, and what they found.

答:
They only moderately recent study that is remotely related to the subject I know of is one from 2004: "The impact of web page text-background colour
combinations on readability, retention, aesthetics
and behavioural intention" by Hall & Hanna. However, it's not for the code but web pages and the only color scheme they consider is foreground and background colors.

I've asked question about studies related color schemes for programmers on Skepics.SE: "Are light-on-dark colour schemes for computer screens better for programmers?". It hasn't been answered in almost 2 years now, while normally that type of question get answered quite quickly there. Which leads me to believe that there are no such scientific studies.


问:
Possible with PHP MVC Framework? A better solution to client 'override' of core functionality?
Background / The Problem

I need to make a (large) application with a certain set of core functionality, and certain functionality for multiple clients within it. Each client has different requirements and while they may share some functionality, I need to separate the code for each client, so a change to one won't affect others. Each client section of the application should also inherit some features from the core application. Ideally I would like to separate the databases for each client too. In terms of a user system, core users should be able to have access to each client's functionality, but client users should only be able to interact with their specific client section of the site.

Current Solution

Each client has its own subdomain and the MVC can override the core's MVC files IF they exist. In a nutshell, my custom MVC's autoloader checks the client directory for the matching M,V, or C file when a subdomain is present in the URL and loads that particular client's file INSTEAD OF the core file. It's an override ability in a sense.

Questions

Am I solving this problem in a way that would be considered good practice in terms of software design?

If I were to use an existing PHP Framework (I would like to), how might I go about setting it up to solve this problem? Specifically I have been looking at Yii and CodeIgniter.

Thanks in advance!

Update:
I have discovered a design pattern called HMVC (Hierarchical MVC) and it seems to be essentially what I have described. I see that Kohana 3 is built using it and that Codeigniter has an extension that allows it.

答:
Working with CakePHP but doable in many different systems which are capable of some plugins concept.

What we do is develop the core functionality in plugins first.So for example: users management feature. That plugin is stored at GitHub as a separate repository.

The we create one general application setup, that is files like index.php, example css file etc. For each client install this basic setup and start loading plugins to get the desired features.

So in GitHub you have:

```<code>Template Application (index.php / example css file / pluginloader)
Plugin 1 (users management)
Plugin 2 (accounting)
etc.
</code>```

The client application can be fully customized and use the features of the plugin as desired.

Then, to go further, you can even override a single view of a plugin. Example of that can be found here:
http://book.cakephp.org/2.0/en/plugins.html#overriding-plugin-views-from-inside-your-application

If you like you can get the copy of the template and then push it as a new repository at GitHub so you get in the end all separate repositories loaded together.:

```<code>Template Application (index.php / example css file / pluginloader)
Plugin 1 (users management)
Plugin 2 (accounting)
Plugin 3 (custom feature for Client 1 - link to their production site)
etc.
Client 1 (you're first copy of template)
Client 2 (the second copy of template)
</code>```

Nice thing is also that you have separate modules which can be tested separately, re-used etc.

Body:
Working with CakePHP but doable in many different systems which are capable of some plugins concept.

What we do is develop the core functionality in plugins first.So for example: users management feature. That plugin is stored at GitHub as a separate repository.

The we create one general application setup, that is files like index.php, example css file etc. For each client install this basic setup and start loading plugins to get the desired features.

So in GitHub you have:

Template Application (index.php / example css file / pluginloader)
Plugin 1 (users management)
Plugin 2 (accounting)
etc.

The client application can be fully customized and use the features of the plugin as desired.

Then, to go further, you can even override a single view of a plugin. Example of that can be found here:
http://book.cakephp.org/2.0/en/plugins.html#overriding-plugin-views-from-inside-your-application

If you like you can get the copy of the template and then push it as a new repository at GitHub so you get in the end all separate repositories loaded together.:

Template Application (index.php / example css file / pluginloader)
Plugin 1 (users management)
Plugin 2 (accounting)
Plugin 3 (custom feature for Client 1 - link to their production site)
etc.
Client 1 (you're first copy of template)
Client 2 (the second copy of template)

Nice thing is also that you have separate modules which can be tested separately, re-used etc.


答:
I'm pretty sure dependency properties are unique for WPF (and derived frameworks like Silverlight and WinRT).

Before WPF, data binding was done mostly though specific interfaces and consumers. Eg. model implemented specific interface and UI control consumed this specific interface.

Also, I hate calling dependency property as "Data Binding". I more prefer calling it "property (or data) synchronization", because it is much precise description what the feature really does.

Title: Dependency properties outside the realm of WPF?

Body:
Is there a more general concept or name for what WPF calls "dependency properties"? I imagine this is not a WPF-ism and in fact other libraries or frameworks have employed a similar approach? If so, what are these other instances and what are the similarities and differences compared to Microsoft's dependency properties?

I am at a junction where I'm considering adding "dependency properties" to my own type system and object model (unrelated to WPF), as the construction seems appropriate for my design requirements; however, I want to consider what others have created as well, not just WPF's particular implementation.


问:
Automated builds, build tools and Embedded systems
I come from an embedded world where we use C/C++ for programming, and use an IDE to generate a binary file, which is then programmed into a Hardware Board, which can then be tested.

With this background, what is a better workflow for automated builds than the current workflow of -build(using IDE)->Flash into the hardware->test. In other words, is there a way I can benefit from the advantages of CI in the domain that I operate in?

答:
For embedded software, Continuous Integration can be helpful

if you have (unit) tests that can be executed in a simulation environment, or

if you have a means to perform unattended updates of the target device and you can automatically trigger the tests (including their required stimuli).

In the first case, you can set-up a CI server that periodically creates a build for the simulation target and executes the tests on that simulated target automatically. In the second case, you would need to hook an actual target to the CI server and then periodically create a build and test it.

The advantage in both cases is that you get automated, unattended, regression tests that will tell you is you accidentally broke something, even if that is in a seemingly unrelated part of the software (which you thus would not have touched with your manual tests).


问:
Storing data in 2 different systems/database structures
My company is an online retailer, and we use an homebrew ecommerce platform. In the last year or so, we've partnered with a accounting software vendor, as our homebrew solution was unable to produce reports as needed, or otherwise satisfy the requests of banks and investors.

We're off to a rocky start with the software, but I'm wondering if it's our approach. Currently, we store a complete set of data in the database connected to our ecommerce platform. Nightly, we send the necessary API calls to sync our entities in the accounting software (orders, POs, invoices, etc), and each morning, I've created scripts that validate that the data is correct between the two systems. This collective system has been a nightmare, as any minor chages to the ecommerce platform cascade in violent and horrible ways to system B. It's resulting in a TON of work on my part to make corrections on a daily basis.

Is there a correct way to approach this problem? Or does the problem really lie upstream, in our decision to duplicate the data between the two systems. Has anybody successfully done something similar?

It has been a non-stop fire drill for 3 months now, and any advice would be greatly appreciated.

答:
You need to change your development and quality assurance procedures.

You have a dependency of accounting on e-commerce. Which is fine. But that means that you are no longer free to make changes to the e-commerce system without considering the accounting system.

Any changes made to the e-commerce system now need to be evaluated and tested for their effect on the sync scripts and the accounting system BEFORE they go into production.


问:
Finally block for methods - is it a bad idea?
The finally block for a try-catch structure is well known, and gives a really easy and elegant way to deal with some must-be-done code.

Therefore, I can see no reason why It shouldn't be good for methods too. For instance, lets say I'm writing some very complicated logic in a method, and I expect to end up with a bunch of boolean flags that will in turn lead to some decisions. Many times in such kind of methods I have branches of code where I would want to "break" the flow and just perform the "real stuff" that I called this method for, with the satisfying information I gathered so far.

So, Why isn't there such pattern? Or is there?

答:
Extract method sounds like a good plan: break up you method into an "initialization" function, a "do your thing" function and a "finalization" function. That way the finalization will always be done regardless of what happens in "do your thing". Except in the case of exceptions of course, but that is where the finally block of your languages comes in. You would then put the "finalization" function in the finally block.

procedure MainFunction;
begin
  InitializationFunction;
  try
    DoYourThingFunction;
  finally
    FinalizationFunction;
  end;
end;
```


问:
Is it correct to fix bugs without adding new features when releasing software for system testing?
This question is to experienced testers or test leads.
This is a scenario from a software project:

Say the dev team have completed the first iteration of 10 features and released it to system testing. The test team has created test cases for these 10 features and estimated 5 days for testing. The dev team of course cannot sit idle for 5 days and they start creating 10 new features for next iteration. During this time the test team found defects and raised some bugs. The bugs are prioritised and some of them have to be fixed before next iteration. The catch is that they would not accept the new release with any new features or changes to existing features until all those bugs fixed. The test team says that's how can we guarantee a stable release for testing if we also introduce new features along with the bug fix. They also cannot do regression tests of all their test cases each iteration. Apparently this is proper testing process according to ISQTB.

This means the dev team has to create a branch of code solely for bug fixing and another branch where they continue development. There is more merging overhead specially with refactoring and architectural changes.

Can you agree if this is a common testing principle. Is the test team's concern valid. Have you encountered this in practice in your project.

答:
That really depends on how closely coupled the new features are with the portions that require bug fixes. E.g. if you add new drag and drop feature to one small portion of the UI, it 'should not' affect the bug that is related to the parsing of the file loaded by the user.

Having say that, it is understandable (not necessarily justified) for testers to want to test the fixes 'Ceteris paribus' (all 'other' things being equal).

There might be some other concerns with the manner of release and end-users expectation. E.g. you might need to release only after one iteration of bug fixes+testing and one more new features+testing because users ONLY want re-installing or upgrade when there are new features. Some might demand fixes as top priority ASAP.


问:
How are dates typically handled with testing?
I am writing an app at the moment that has some pretty extensive business logic based around dates. I have several hundred thousand records to test and testers who want to see how those records are handled, which has worked well so far, however, some edge cases are difficult to replicate. The reason is that most of the logic is related to today's date, in one way or another. What is the best way to handle this with both unit testing and for traditional testing? The only way I can really think of is allowing for today's date to be faked and fixed.</p>

答:
Also depends on what you are testing for. I created a database using JPA once and used the JUnit package. I had "From" and "To" date fields to process and the fields were upto miliseconds as there were some fast sampling involved. What I can recommend testing initially for any date-related things are:

1) Timestamp format (e.g. dd-MM-yyyy HH:MM:SS.sss) validity
2) Timestamp sanity (does "Today" return what the actual i.e. computer date is?)

java.util.date package is a primitive package and I expect them to be tested well in order to cover further sanity checks. The other things I will still keep in mind whilst testing are:

1) Parsing
2) Timezone
3) Validating user Input (if you are accepting dates as user inputs).
4) Type mismatch (are you going to keep numeric or string dates?)

If you are using C++, Boost, QT , may have some ready tests for these. Also check UnitTest++, xUnit to see what they offer in this area.

These are the thing I used for testing and worked fine for me :)


问:
When does SOAP make more sense than REST?
From my understanding of REST, the implicit assumption is that all operations are CRUD operations. Sometimes, you are not doing CRUD operations and are doing some more complex logic. In this case, is not SOAP more suitable? Or is it the case that all operations no matter how complex are a series of CRUD operations so they should be split up into a set of smaller CRUD operations to be called one after the other? But, does this not make the operation you are attempting more cumbersome to write? I am trying to understand when it might make more sense to use SOAP instead of REST.</p>

答:
REST is built around the idea of doing CRUD operations on self-contained objects, or in a worst case, on a tightly coupled object hierarchy.

SOAP is less structured than this, and is therefore more suitable for transactions which have a more fluid structure.  SOAP requests and responses have a defined structure, insofar as they have to conform to their WSDL, but that leaves a lot of room for optional elements, repeating elements, complex elements, and so forth.


答: I would say instead that each release of new features should be on a separate branch. This allows development and releases to be decoupled.</p>

Title: Is it correct to fix bugs without adding new features when releasing software for system testing?

Body:
This question is to experienced testers or test leads.
This is a scenario from a software project:

Say the dev team have completed the first iteration of 10 features and released it to system testing. The test team has created test cases for these 10 features and estimated 5 days for testing. The dev team of course cannot sit idle for 5 days and they start creating 10 new features for next iteration. During this time the test team found defects and raised some bugs. The bugs are prioritised and some of them have to be fixed before next iteration. The catch is that they would not accept the new release with any new features or changes to existing features until all those bugs fixed. The test team says that's how can we guarantee a stable release for testing if we also introduce new features along with the bug fix. They also cannot do regression tests of all their test cases each iteration. Apparently this is proper testing process according to ISQTB.

This means the dev team has to create a branch of code solely for bug fixing and another branch where they continue development. There is more merging overhead specially with refactoring and architectural changes.

Can you agree if this is a common testing principle. Is the test team's concern valid. Have you encountered this in practice in your project.


答:
This is one of those things where you quite often want to operate on a chunk of data, rather than the OO principle of "a single piece of data".

So I'd wrap the entire list in a class which on creation, parses the list and calculates out what you want. You'd also use this class to insert into, and remove from the list, so that the wrapped information is always up to date.

```<code>class Runners
{
    public Runners( RunnerList inputRunners)
    {
        runners = inputRunners;
        Recalculate();
    }

    private Recalculate()
    {
       foreach( Runner runner in runners )
       {
           // comparisons here!
       }
    }

    public Insert(Runner newRunner)
    {
        int index = runners.Add(newRunner);
        if( newRunner.height > runners[highestIndex].height)
        {
            highestIndex = index;
        }
        // and so on.
    }

    public Remove(Runner delRunner)
    {
        runners.Remove(delRunner);
        Recalculate();
    }

    // accessors
    Runner GetHighest() { return runners[highestIndex]; }
    Runner GetFastest() { return runners[fastestIndex]; }
    Runner GetLightest() { return runners[lightestIndex]; }

    RunnerList runners; // list of runners we manage
    int highestIndex;   // index of element in list which is highest.
    int fastestIndex;   // index of element in list which is fastest
    int lightestIndex;  // you get the idea right?

}
</code>```

Thats it. you've now got a self contained block of logic which answers your questions for you with only a single iterate on creation, and when you remove objects.

Body:
This is one of those things where you quite often want to operate on a chunk of data, rather than the OO principle of "a single piece of data".

So I'd wrap the entire list in a class which on creation, parses the list and calculates out what you want. You'd also use this class to insert into, and remove from the list, so that the wrapped information is always up to date.

class Runners
{
    public Runners( RunnerList inputRunners)
    {
        runners = inputRunners;
        Recalculate();
    }

    private Recalculate()
    {
       foreach( Runner runner in runners )
       {
           // comparisons here!
       }
    }

    public Insert(Runner newRunner)
    {
        int index = runners.Add(newRunner);
        if( newRunner.height > runners[highestIndex].height)
        {
            highestIndex = index;
        }
        // and so on.
    }

    public Remove(Runner delRunner)
    {
        runners.Remove(delRunner);
        Recalculate();
    }

    // accessors
    Runner GetHighest() { return runners[highestIndex]; }
    Runner GetFastest() { return runners[fastestIndex]; }
    Runner GetLightest() { return runners[lightestIndex]; }

    RunnerList runners; // list of runners we manage
    int highestIndex;   // index of element in list which is highest.
    int fastestIndex;   // index of element in list which is fastest
    int lightestIndex;  // you get the idea right?

}

Thats it. you've now got a self contained block of logic which answers your questions for you with only a single iterate on creation, and when you remove objects.


答: finally causes a lot of code repetition. If you use a resource Foo in 100 places, and the cleanup of Foo takes 3 lines, then the finally blocks would add 300 lines of code but a destructor adds only 3 lines total.

Body:
The finally block for a try-catch structure is well known, and gives a really easy and elegant way to deal with some must-be-done code.

Therefore, I can see no reason why It shouldn't be good for methods too. For instance, lets say I'm writing some very complicated logic in a method, and I expect to end up with a bunch of boolean flags that will in turn lead to some decisions. Many times in such kind of methods I have branches of code where I would want to "break" the flow and just perform the "real stuff" that I called this method for, with the satisfying information I gathered so far.

So, Why isn't there such pattern? Or is there?


问:
Is there a standard way to structure a website
When I first taught myself how to make websites (html/css) I used exact pixel width and height for all div elements. I've also practiced making websites with nothing but percentage width and height.

I can use either technique fairly easily, but I wanted to know is there a standard technique or structure to building the basic layout of a website?

My recent favorite is to make my main div container an exact pixel width with auto height (centered on the page) and then have all divs inside set to a percentage width and auto height. This works just fine for me, but if there's a widely acknowledged standard to making a website from scratch I would love to know.

答:
As GrandMasterB mentioned, the current trend is to use scaffolding and responsive column-based layouts that make it much easier to write web applications for multiple target environments all at the same time: PCs, tablets, smartphones.

The most used is Twitter's Bootstrap... to the point where you can almost instantly recognize a website using it. To the point where a blog post has been written to stop using it... And as such, a lot of websites with Bootstrap themes (free or/and premium) have popped out of nowhere such as Bootswatch for example.

The other one that I've personnally used is Zurb's Foundation which is also nice and offers the same gric/column based layout. Similarly to Bootstrap, you can customize the CSS and Javascript components included before downloading the source files.

I don't know if this trend is going to stop or if it will fall into "another way of writing web apps", but there are many pros while working with such frameworks:

Part of the responsive design is already done for you (and if you don't do too much complicated stuff, that part is going to be very close to 100%)

It's easy to pick up (for exmaple: most important CSS classes in Bootstrap: row, and spanx where x is a number between 1 and 12)

It's easily customizable with additional fonts, icons, theme colors

It's pretty !

You save a lot of time for more important stuff rather than micro-managing pixel by pixel all your DOM elements (you can still do that, sure, but if you do things well, you should not have to)

They come with JQuery-based components

It's still being worked on, and updated with modern CSS3 and HTML5 features while keeping compatibility with older browsers

It's incredibly easy to integrate Bootstrap to a MVVM framework such as KnockoutJS for example.

And last but not least... Both Bootstrap and Zurb Foundation have excellent documentations

Edit: found a website comparing Bootstrap to Zurb Foundation and to another one that I didn't knew of, Skeleton (still grid/column based): http://responsive.vermilion.com/compare.php