答:
UPDATE:  Attempting to clean up my answer and be more accurate

Big O notation is a way to characterize functions according to there growth rates.  The O stands for order (first order being n second order being n-squared etc).  And if I am not mistaken this would be the worst case scenario for a methods runtime(or storage) given N elements.  The larger the order the worst the method performs.

For instance looking up a record in an array is O(1) (I believe in some implementation of a hash tables that is also the case).  Adding a value to the end of a link list would be O(N) because you have to get to the end of the list before you can add the element etc.

This answer should be slightly more correct than my first attempt :)

Title: What is O in Big O?


问:
ASP.Net MVC ambigious action methods - why the path choosen
Is there someone who could shed a light on why ambiguous methods are not allowed in ASP.Net MVC?
I updated my question just to clarify it (using Carson63000 example from his answer), the question itself remains the same.

So, lets say we have the following action

```<code>/article/list/sport
</code>```

which calls

```<code>public ActionResult List(string category) { }
</code>```

and want to be able to have the following action as well:

```<code>/article/list/sport/20110904
</code>```

which we would like to call accompanying method

```<code>public ActionResult List(string category, DateTime date) { }
</code>```

Currently the framework throws an AmbiguousMatchException since it found two methods called List. That's the only reason for throwing the exception, that more than one method with was found that matches the actions name.

After the framework has figured out what method to use and decided that it is not ambigious, it will then try to map the supplied data from the request to the parameters of the method. Why not do this the other way around? First get all applicable methods, and then try to find the best fit by mapping parameters.

If ambiguous methods where allowed, I think the following is still possible to do.

Given that /article/list/sport uses the route /{controller}/{action}/{category} and that /article/list/sport/20110903 uses the route /{controller}/{action}/{category}/{date}
 it would then still be possible to map data for url /article/list/sport?date=20110903 since it will match the route for just category, but can still map the data for method public ActionResult List(string category, DateTime date) { }.

At the moment I fail to see the reason for not allowing ambiguous methods from a design perspective. The only thing I can think of myself is that it will slow down the framework too much, and therefor the current solution is the more logical one. Or am I missing another point here?

答:
As for getting a list of applicable methods for resolving an action, I don't see any problem with that, it is quite easily doable, as it turned out. Resolving the parameters for each method is also manageable, the only problem that seems to exist is determining the best fit.

But still it should be possible to choose one method over another some way and if there would be some sort of tie, throw the AmbiguousMethodException.

ContentLicense: CC BY-SA 3.0


问:
Should we encourage coding styles in favor of developer's autonomy, or discourage it in favor of consistency?
A developer writes if/else blocks with one-line code statements like:

```<code>if (condition)
   // Do this one-line code
else
   // Do this one-line code
</code>```

Another uses curly braces for all of them:

```<code>if (condition)
{
   // Do this one-line code
}
else
{
   // Do this one-line code
}
</code>```

A developer first instantiates an object, then uses it:

```<code>HelperClass helper = new HelperClass();
helper.DoSomething();
</code>```

Another developer instantiates and uses the object in one line:

```<code>new HelperClass().DoSomething();
</code>```

A developer is more easy with arrays, and for loops:

```<code>string[] ordinals = new string[] {'First', 'Second', 'Third'};
for (i = 0; i < ordinals.Length; i++)
{
    // Do something
}
</code>```

Another writes:

```<code>List<string> ordinals = new List<string>() {'First', 'Second', 'Third'};
foreach (string ordinal in ordinals)
{
    // Do something
}
</code>```

I'm sure that you know what I'm talking about. I call it coding style (cause I don't know what it's called). But whatever we call it, is it good or bad? Does encouraging it have an effect of higher productivity of developers? Should we ask developers to try to write code the way we tell them, so to make the whole system become style-consistent?

答: Neither. I would avoid harsh coding rules to avoid being tedious, nit-picky, micro managerial and worst of all wasting time. Your sense of autonomy is your own issue. If I want you to feel better about yourself, I'll buy you a round of your favorite beverage. Other than that, get something done.</p>


问:
Recursion without factorial, Fibonacci numbers etc
Almost every article I can find about recursion includes the examples of factorial or Fibonacci Numbers, which are:

Math

Useless in real life

Are there some interesting non-math code examples to teach recursion?

I'm thinking divide-and-conquer algorithms but they usually involve complex data structures.

答:
I solved a problem with a knight pattern (on a chessboard) using a recursive program.  You were supposed to move the knight around so that it touched every square except a few marked squares.

You simply:

```<code>mark your "Current" square
gather a list of free squares that are valid moves
are there no valid moves?
    are all squares marked?
        you win!
for each free square
    recurse!
clear the mark on your current square.
return.
</code>```

Many kinds of "think-ahead" scenarios can be worked by testing future possibilities in a tree like this.

Body:
I solved a problem with a knight pattern (on a chessboard) using a recursive program.  You were supposed to move the knight around so that it touched every square except a few marked squares.

You simply:

mark your "Current" square
gather a list of free squares that are valid moves
are there no valid moves?
    are all squares marked?
        you win!
for each free square
    recurse!
clear the mark on your current square.
return.

Many kinds of "think-ahead" scenarios can be worked by testing future possibilities in a tree like this.


问:
How long should a sprint planning meeting last?
In your experience, how long should a Sprint Planning meeting (Scrum) last? 8 hours? Or should it be shorter (succinct) and further discussions should be planned as part of the sprint? Our Sprints are 10 days long.</p>

答: Do not mold your business around the process. The process supports your business. The moment you're doing process for its own sake it's time for the process to get the axe. To that end, there is no "right" way. Meetings should only go as long as you are accomplishing something in them. If it takes you 30 minutes or 4 hours, as long as it works then go with it. Ignore what some book/blog/coach tells you and do what is right for you.</p>


问:
To branch or not to branch?
Till recently my development workflow was the following:

Get the feature from product owner

Make a branch (if feature is more than 1 day)

Implement it in a branch

Merge changes from main branch to my branch (to reduce conflicts during backward merging)

Merge my branch back to main branch

Sometimes there were problems with merging, but in general I liked it.

But recently I see more and more followers of idea to not make branches as it makes more difficult to practice continuous integration, continuous delivery, etc. And it sounds especially funny from people with distributed VCS background who were talking so much about great merging implementations of Git, Mercurial, etc.

So the question is should we use branches nowadays?

答:
What an interesting set of answers.  In 20+ years I have never worked at a company that made more than a trivial use of branching (Generally just to branch releases).

Most places I've worked rely on fairly quick check-ins and rapid detection/resolution of collisions--Agile methodology teaches that you can resolve problems more quickly if you notice them while both parties are actively thinking about that piece of code.

On the other hand, I haven't used git much and perhaps it's the inclusion of the git tag that influenced these answers--I understand that branch/merge is a given with git because it's so easy.

Title: To branch or not to branch?


答:
In a sense, recursion is all about divide and conquer solutions, that is breking the problem space into a smaller one to help find the solution for a simple problem, and then usualy going back reconstructing the original problem to compose the right answer.

Some examples not involving math to teach recursion (at least those problems I remember from my university years):

Towers of Hanoi

Eight queens

These are examples of using Backtracking to solve the problem.

Other problems are classics of Artificial Intelligence domain:
Using Depth First Search, pathfinding, planning.

All those problems involve some kind of "complex" data structure, but if you don't want to teach it with math (numbers) then your choices may be more limited. Yoy may want to start teaching with a basic data structure, like a linked List. For example representing the natural numbers using a List:

0 = empty list
1 = list with one node.
2 = list with 2 nodes.
...

then define the sum of two numbers in terms of this data structure like this:
Empty   + N = N
Node(X) + N = Node(X + N)

Title: Recursion without factorial, Fibonacci numbers etc

Body:
Almost every article I can find about recursion includes the examples of factorial or Fibonacci Numbers, which are:

Math

Useless in real life

Are there some interesting non-math code examples to teach recursion?

I'm thinking divide-and-conquer algorithms but they usually involve complex data structures.


问:
*Code owner* system: is it an efficient way?
There is a new developer in our team. An agile methodology is in use at our company. But the developer has another experience: he considers that particular parts of the code must be assigned to particular developers. So if one developer had created a program procedure or module it would be considered normal that all changes of the procedure/module would be made by him only.

On the plus side, supposedly with the proposed approach we save common development time, because each developer knows his part of the code well and makes fixes fast. The downside is that developers don't know the system entirely.

Do you think the approach will work well for a medium size system (development of a social network site)?

答:
It's an awful idea. It may be quicker in the short term, but it encourages badly documented hard-to-understand code as only the coder who wrote it is responsible for maintaining it. When someone leaves the company or goes on holiday the whole plan becomes mucked up. It also makes it very hard to allocate workloads; what happens when two urgent bugs come up with the code one coder "owns"?

You should code as a team. People will naturally be allocated tasks and focus on certain areas but sharing workload and working together should be encouraged, not discouraged.


问:
When doing up a quote, do I see my client in person, or send it via email?
Client need something done, I need to write up a quote, how do I approach it?  If you have any general strategy on this issue would also be appreciated.  This is to build a website/database for a few grand.</p>

答:
I would call up the client, introduce yourself and ask a couple more questions to get a more detailed picture of their requirments. Even if you dont really need to it gives the impression of a personalised and proffesional service. I would then gauge by their reaction how to proceeded. (email or face to face)

Generally you don't have a client meeting before the quote is accepted but that varies hugely on circumstances.


答:
This depends on the situation and the factors involved.

If its a simple project that won't take much time or cost much money and they aren't down the street - go ahead and email, though I would definitely follow it up with a phone call. This adds a human element to your business and makes them more comfortable with you as a contractor.

However, if this is a substantial project and they aren't unreasonably far away (I drove an hour the other day to meet a potential client), get out of your chair and drive over there! You're trying to establish a business relationship and nothing smacks of a relationship better than meeting them face to face and shaking their hand.

90% of communication is non-verbal. Always remember that.

Title: When doing up a quote, do I see my client in person, or send it via email?

Body: Client need something done, I need to write up a quote, how do I approach it?  If you have any general strategy on this issue would also be appreciated.  This is to build a website/database for a few grand.</p>


答:
Yes, it is slightly more efficient, in the short-term. And there ends the benefits. That doesn't even come close to outweighing the cost.

What happens when he's on holiday, or unexpectedly sick, or leaves, or gets hit by the proverbial bus? What happens when you want to flex resources to get one job through quicker than another? How effective can code-reviews be? How can a manager, particularly one who isn't in the code-base, know if the developer is working hard or pulling the wool over his eyes? Who will notice if the technical debt starts running up?

In my experience, people who like working this way are glory-hunters at best, lazy at worst. They like to be the only person you can go to with a given problem and they like their code to remain private. And they often like to code fast, without regard for readability.

That's not to say that, on a team of 50 developers, everyone should know all the code, but a team of 5-7 should own a module big enough to keep those people working. No individual should own anything.

Title: *Code owner* system: is it an efficient way?

Body:
There is a new developer in our team. An agile methodology is in use at our company. But the developer has another experience: he considers that particular parts of the code must be assigned to particular developers. So if one developer had created a program procedure or module it would be considered normal that all changes of the procedure/module would be made by him only.

On the plus side, supposedly with the proposed approach we save common development time, because each developer knows his part of the code well and makes fixes fast. The downside is that developers don't know the system entirely.

Do you think the approach will work well for a medium size system (development of a social network site)?


答:
It depends on what the domain of the problem is.

If it's general stuff (i.e. simple CRUD actions, etc), then I agree with Tom Squires (anyone should be able to work on it and edit it).

However...

If the solution in question requires domain expertise (lots of time has either been invested in the past or a lot of research needs to be done prior to implementation, as in this is something that you'd list in a job requirement as specialized knowledge that not everyone on the project has), then an owner should definitely be assigned to that part of the code. Having said that, anyone should be able to make modifications to it as needed, but they should always be reviewed by the person owning that area of the project.

You don't want to have your entire team (or a number of people on the team) researching and learning the same subject (wasted cycles). Assign an owner, but have them document their learnings and designs and maybe have them conduct informal (or formal, doesn't really matter) training sessions on the technology.


答: Use of conventions, variable names, class names etc. is good practice. But coding styles like the examples you provide are rather trivial and have no effect on either the readability or efficiency of the code. On the other hand, the overhead from enforcing a given style combined with the developers effort to following it will cause problems.</p>

Title: Should we encourage coding styles in favor of developer's autonomy, or discourage it in favor of consistency?

Body:
A developer writes if/else blocks with one-line code statements like:

```<code>if (condition)
   // Do this one-line code
else
   // Do this one-line code
</code>```

Another uses curly braces for all of them:

```<code>if (condition)
{
   // Do this one-line code
}
else
{
   // Do this one-line code
}
</code>```

A developer first instantiates an object, then uses it:

```<code>HelperClass helper = new HelperClass();
helper.DoSomething();
</code>```

Another developer instantiates and uses the object in one line:

```<code>new HelperClass().DoSomething();
</code>```

A developer is more easy with arrays, and for loops:

```<code>string[] ordinals = new string[] {'First', 'Second', 'Third'};
for (i = 0; i < ordinals.Length; i++)
{
    // Do something
}
</code>```

Another writes:

```<code>List<string> ordinals = new List<string>() {'First', 'Second', 'Third'};
foreach (string ordinal in ordinals)
{
    // Do something
}
</code>```

I'm sure that you know what I'm talking about. I call it coding style (cause I don't know what it's called). But whatever we call it, is it good or bad? Does encouraging it have an effect of higher productivity of developers? Should we ask developers to try to write code the way we tell them, so to make the whole system become style-consistent?


答:
Write up a quote following this pattern:

Always start by introducing yourself, what your company (or yourself) does, and what you can do for your prospective client.

Define a problem, the customers' need to be satisfied.

Propose a solution.

Determine costs.

Define terms: payment, deliverables, whats included, whats not (support, etc.) and be clear about it.

Contact info.

Then send it by email in PDF format. Personal contact for quote delivery is not necessary, unless you are pithcing an idea (client isn't sure of what he wants).


答:
Use an industry standard linting tool (apparently FxCop for C#). While it's not the end-all, be-all, consistency is important in large projects that have a number of people working on them.

If you're just working on your own project or small team, many would argue that it's overkill. I believe otherwise (I use PEP8 for Python, even in my personal single-developer projects).

Most of the examples you gave, however, would most likely not be caught by a linting tool as they simply don't matter.


答: It's a mixture of both.  Just because it's a standard doesn't make it readable and maintainable.  If there is no instilled standard yet, or it there are faulty and unreadable aspects of it, revision is appropriate.</p>


问:
Is anyone doing "real" TDD with Visual-C++, and if yes, how do they do it?
Test Driven Development implies writing the test before the code and following a certain cycle:

Write Test

Check Test (run)

Write Production Code

Check Test (run)

Clean up Production Code

Check test (run)

As far as I'm concerned, this is only possible if your development solution allows you to very quickly switch between the production and test code, and to execute the test for a certain production code part extremely quickly.

Now, while there exist lots of Unit Testing Frameworks for C++ (I'm using Bost.Test atm.) it does seem that there doesn't really exist any decent (for native C++) Visual Studio (Plugin) solution that makes the TDD cycle bearable regardless of framework used.

"Bearable" means that it's a one-click action to run a test for a certain cpp file without having to manually set up a separate testing project etc. "Bearable" also means that a simple test starts (linking!) and runs very quickly.

So, what tools (plugins) and techniques are out there that make the TDD cycle possible for native C++ development with Visual Studio?

Note: I'm fine with free or "commercial" tools.

Please: No framework recommendations. (Unless the framework has a dedicated Visual Studio plugin and you want to recommend the plugin.)

Edit Note: The answers so far have provided links on how to integrate a Unit Testing framework into Visual Studio. The resources more or less describe how to get the UT framework to compile and get your first Tests running. This is not what this question is about. I'm of the opinion that to really work productively, having the Unit Tests in a manually maintained(!), separate vcproj from your production classes will add so much overhead that TDD "isn't possible". As far as I am aware, you do not add extra "projects" to a Java or C# thing to enable Unit Tests and TDD, and for a good reason. This should be possible with C++ given the right tools, but it seems (this question is about) that there are very little tools for TDD/C++/VS.

Googling around, I've found one tool, VisualAssert, that seems to aim in the right direction. However, afaiks, it doesn't seem to be in widespread use (compared to CppUnit, Boost.Test etc.).

Edit: I would like to add a comment to the context for this question. I think it does a good summary of outlining (part of) the problem: (comment by Billy ONeal)

Visual Studio does not use "build scripts" that are reasonably
  editable by the user. One project produces one binary. Moreover, Java
  has the property that Java never builds a complete binary -- the
  binary you build is just a ZIP of the class files. Therefore it's
  possible to compile separately then JAR together manually (using e.g.
  7z). C++ and C# both actually link their binaries, so generally
  speaking you can't write a script like that. The closest you can get
  is to compile everything separately and then do two linkings (one for
  production, one for testing).

答:
Maven is not used widely in C++ (yet, it is mainly used for Java but is language agnostic) but it is a very powerful tool and it allows you to keep everything in the one project (including tests, in fact, that is the recommended approach with Maven). I only suggest it now since from the answers so far it looks like an alternative with a VS plugin may not exist.

Searching for plugins I found:

http://incubator.apache.org/npanday/

but it does not look to be very mature yet. With Maven setup all you would need to do to run the tests is run mvn test in the command line.

If you're interested you can learn about it here and (one of) the C++ supporting plugins here (Maven has a plugin architecture so everything is a plugin).


答:
A coding standards document is useful. It's most useful when it's short enough that anybody can remember the whole thing without too much trouble and when it doesn't cause anybody too much pain.

How you choose to indent code in your organization, or capitalize names, or implement your loops, or comment your code doesn't matter all that much; the helpful part is getting everybody to write code that looks about the same as everybody else's.

It avoids having to spend a minute recalibrating your expectation of where braces should be and such every single time you look at someone else's code.

It avoids having several different styles of code all in the same file.

Perhaps most importantly, having a written standard avoids arguments about coding practices during code reviews.

Again, what the standards are doesn't matter as much as having some sort of simple, straightforward standard. So, put all your developers in a room and let them argue about what the standards should be. This meeting could go on indefinitely, so the rules are:

Anything not decided by the end of the meeting will be decided by the manager.

The meeting will end after two hours, or when someone starts shouting or crying, whichever comes first.

The entire standard will fit (in reasonable type size!) on a sheet or two of paper, double-sided only if absolutely necessary.

Consider adopting somebody | else's | standards either as a starting point for your own coding standards meeting, or as a way of avoiding the meeting entirely.

Once agreed upon, developers should be able to (and should be expected to) police themselves. Occasional deviation from the standard shouldn't be a big deal (and might even be justifiable), but curmudgeonly refusal to abandon some favorite personal style in favor of the standard should result in immediate relocation to the office with the leaky water pipes, or whatever.

Demian Brecht points to lint tools. These are a perfect complement to a coding standards document. It's merely good to stick to coding style standards; it's important to stick to coding standards that relate to dangerous practices. Nobody other than the author is going to check that every line of code meets the standard for style, but you should certainly consider building a lint tool into your team's workflow to automatically catch likely bugs. In addition, the tool itself can codify the accepted practices so that you don't have to list them all individually in the coding standards; just specify the tool's configuration.

Note: The "coding standards" idea is not unique to programming. "Coding standards" are used in many fields, sometimes within an organization, more often across an entire industry or profession. Some examples:

Legal documents such as court filings and transcripts adhere to specific formats.

Scripts and screenplays must be written in a particular style in order to be taken seriously.

Technical drawings often must have a title block in standard form.

Bibilography formats are standardized.

In each case (and many others) a competent practitioner could easily understand "code" that doesn't meet the expected standard. Why do so many industries persist in writing detailed requirements for documents that don't even need to be parsed by a compiler? Because style matters. Presenting information in a standard style lets the reader focus entirely on content, makes reading faster and aids understanding, and reduces errors.


问:
Master, Slave: Politically Correct Version
What other tech synonyms are there for a master-slave relationship? The situation is a knob that controls other knobs, or a button that controls other buttons.</p>

答:
You could go with "Parent" and "Child". I guess "Manager" and "Worker" are also possible, though I don't see that nearly as often. Also possible is "Controller" and "Controllee" though that sounds weird, and I'm not even sure if "Controlee" is a word.

On the fun side of things, you could try something like "Overlord" and "Minion". Or "Hero" and "Sidekick". Or "BigBoss" and "Lackey". Or "Captain" and "Sailor". ;)


答: How about Parent / Child(ren) ?</p>

Title: Master, Slave: Politically Correct Version

Body: What other tech synonyms are there for a master-slave relationship? The situation is a knob that controls other knobs, or a button that controls other buttons.</p>

Body: How about Parent / Child(ren) ?


答:
Are you talking about master & slave as used for hard disks? In this case, master & slave are actually a politically correct terms to use. It would also be politically correct to apply those terms to software parts.

Otherwise, you may use some terms depending on the context: primary & secondary, parent & child, etc.


问:
What pattern helps to compose nested views at runtime?
Are there any design patterns to compose views within a parent view during runtime? Say we are composing the views in a workflow tab and views in the tabcontrol depend on the country, store type and/or other conditions.

This is a MVP, WPF, PRISM application.

答: The closest design pattern I can think of is decorator pattern. That said, are you nesting views, or enabling/disabling/auto-populating fields based on other selections in the UI, in which case you may want to use the strategy pattern?</p>


答:
The advantage is that not everyone needs to research and understand everything.  The disadvantage is that that makes each person necessary for their own area of code, and no-one else knows how to maintain it.

A compromise would be to have at least 2 owners for each area of code.  Then someone can go on vacation, take a new job, or retire, and there is still someone who knows the code (and can train the new second person).  Not everyone needs to learn everything, which is a bit more efficient.

Don't have the same 2 (or 3) people work together all the time.  Switch out pairs for different areas, so the knowledge is also shared inadvertantely when working with a different person on a related program area.


问:
Can daily reports decrease a developer's productivity?
In another question, I asked about why developers might don't like daily scrum. We talked to developers and we decided to not hold daily scrum for a while (to give it a try and customized scrum in our first attempt). This is the output of consulting with developers directly.

On the other hand, we don't want to lose good parts of daily scrum, like getting a chance to coordinate developers everyday, or watching the work progress like a Key Performance Indicator, to take actions early.

As an alternative to daily scrum, we're thinking about asking developers to provide daily reports with the following conditions:

No need to follow any specific format. Each and every format is accepted.

Even if the work is not done, we want to hear the amount of progress.

There is no need to mention the time spent on each task.

Development obstacles and coordination requirements should be mentioned.

There is no need to be obsessed with daily reports. It's not taken that strict.

Do you think that this can decrease their productivity? Have you had any daily report experience? Do you have any suggestion for us, so that we can get sure that we're not micromanaging?

答: I also agree that it is a bad idea to replace daily stand-ups with a report. A daily stand-up is a great place to vocalize ideas and problems. This is one of the reasons I like the good old whiteboard (which we use alongside Jira+Greenhopper). The whiteboard is a place where the group 'huddle' and share information, everything is there, everything is visible, everyone moves and changes the stickies that they worked on, it also a lot of fun. </p>


问:
Using OpenID to log into multiple domains: Is this plan feasable?
For example:

We're running a two community sites on two domains (call them example.com and example.net).

We want to be able to expand that to more domains later.

We want to allow multiple types of login (OpenID, Facebook, Twitter, standard username/password).

We want someone who's logged into one site to automatically be logged into the other(s).

In other words, it's a bit similar to the StackExchange network.

In this case, would this plan work?

Set up example.com and example.net (and any later additions) as OpenID relying parties, which accept OpenID login from id.example.org only.

Set up example.com and example.net to do an OpenID reply-immediate request the first time you visit them, so that if you're logged into id.example.org you're immediately and automatically logged into the site you're visiting. They should set a cookie if you're not logged in, to save them doing this on every page request.

Set up id.example.org as an OpenID provider and consumer. It should also consume Facebook and other identity providers, and allow standard username/password access. (Multiple login methods could be attached to one account.)

On logout, simply change the authentication tokens in the database. The user will still have cookies, but they'll be meaningless. Thus can the user be signed out of all sites simultaneously. Multiple authentication tokens can be stored against one user at one time (and should be different for each site), so that the user can sign out in one browser but still be signed in in another. Signing out always signs out for all sites.

The only problem I can see with the above is this:

Someone visits example.com. A "not-logged-in" cookie is set.

Zie then goes onto example.net. Ditto.

Zie then signs in, and continues browsing on example.net.

Zie then goes back to example.com and, because of the "not-logged-in" cookie, is not checked against id.example.org and is therefore not logged in.

However, as soon as zie clicks the "log in" button, zie is logged in.

I don't think this is a major problem.

On the whole, I think it's a pretty good system. I'd just like to see it reviewed. Are there any problems I haven't foreseen? Would it be buggy or slow? StackExchange uses a very different method. I assume they have a good reason for that?

答:
Movable Type uses a very similar login method to the one you describe. I personally do not mind it, but there are times when I present it to a customer and they can help but ask, "what exactly is going on here?"

The project I have been most intrigued by with regards to creating a coherent login system is the Google Identity Toolkit. The user experience is spot on, and the ease with which it appears to be implementable is very appealing.


问:
Having a Git repo and mercurial in the same directory
Ill explain my problem,

I am currently using an in-house install of gitorious using git. I would like to begin testing FogBugz and Kiln from Fog Creek which uses mercurial. I would like to for at a least a short while continue development using both solutions.

Does anyone know of any long term serious effects of having a git and a mercurial repo in the same directory. Or is there a better way of keeping git and mercurial server in sync.

Ive tried it with a test repo and I haven't seen any issues.

Thanks for any help.

答:
I have used both mercurial and git on the same project, in the same working directory. The great thing about using these two DVCS's is that they both only have one folder (.git/.hg) for their confs and blobs and trees and stuff.

Just put .hg in .gitignore (and .git in .hgignore) and you are more than good to go.

You of course have to double the work when committing, but I didn't find this to hard to manage.

This setup in my opinion is far more reliable than using any bridge solutions (I don't like them since the horror I had with git-svn).


答:
IMHO it depends...

Your first two examples are not just a matter of personal taste to me.

```<code>if (condition)
   // Do this one-line code
else
   // Do this one-line code
</code>```

(without brackets) = more bug-prone, if more code is added later on:

```<code>if (condition)
   // Do this one-line code
else
   // Do this one-line code
   // ...and this line as well... oops! this will actually execute either way
</code>```

And this is less convenient to debug:

```<code>new HelperClass().DoSomething(GetSomeData()); // etc.
</code>```

You cannot simply set a breakpoint where you need it. If this is a one-off - fair enough, but we discuss it as a matter of style, and once you've got stuff like this all over the place, debugging gets more unpleasant than it has to be.

As for your third example (for vs foreach), I see it as a matter of taste though.

Body:
IMHO it depends...

Your first two examples are not just a matter of personal taste to me.

if (condition)
   // Do this one-line code
else
   // Do this one-line code

(without brackets) = more bug-prone, if more code is added later on:

if (condition)
   // Do this one-line code
else
   // Do this one-line code
   // ...and this line as well... oops! this will actually execute either way

And this is less convenient to debug:

new HelperClass().DoSomething(GetSomeData()); // etc.

You cannot simply set a breakpoint where you need it. If this is a one-off - fair enough, but we discuss it as a matter of style, and once you've got stuff like this all over the place, debugging gets more unpleasant than it has to be.

As for your third example (for vs foreach), I see it as a matter of taste though.


问:
Interviews: How far to go on DVCS experience?
I've been interviewing some potential interns for a project I'm working on. We use git, so I'm looking for someone familiar with DVCS (or SVN/CVS or a desire to learn). A response that threw me off was "I've worked with github" with no further information, so it forced me to consider what to expect from a programmer working with version control.

I actually led a VCS conversion, so I got more intimately involved with Git/DVCS administration than I thought I ever would be, so I don't think it is fair to hold a student to that standard.

My question is, what should a junior programmer be comfortable doing when working with a DVCS? Should it be simple adds, commits, merges, remotes, or would you expect something more? If you've been asked good questions in interviews, I'd appreciate them being shared.

I don't really want to hire the developer that pushes a backwards merge!

Edit: I really should have mentioned before this got rolling that our distribution model relies heavily on Git and our self-hosted repository (I'm a web developer), and that's why  I feel it's important to know (at the very least) the consequences of serious actions like remote pushes; these actions triggers a few different processes in our environment. My fault! The answers have still been very helpful.

答:
No they shouldn't be expected to know about it. Some companies (stupidly, in my opinion) don't use version control. They won't necessarily have been exposed to it.

If you're hiring an intelligent, logical developer then they should be able to pick up the concept with very little effort. If you do choose to hire them and are worried they will break something, make sure you point them to a decent tutorial and quiz them a little afterwards.


答: Well, I realize version control is probably relatively important to you, but I wouldn't consider it a big deal.  If a programmer who has never heard of version control in his life (which would in itself be problematic, I admit, since they must have lived under a very remote rock for some time) can't pick up what he needs to know in a short time you have more serious problems.  He won't be in charge of the company-wide source control policies, he just needs what you described as the simple stuff, and I don't see why a good programmer couldn't learn that in half a day.</p>

Title: Interviews: How far to go on DVCS experience?

Body:
I've been interviewing some potential interns for a project I'm working on. We use git, so I'm looking for someone familiar with DVCS (or SVN/CVS or a desire to learn). A response that threw me off was "I've worked with github" with no further information, so it forced me to consider what to expect from a programmer working with version control.

I actually led a VCS conversion, so I got more intimately involved with Git/DVCS administration than I thought I ever would be, so I don't think it is fair to hold a student to that standard.

My question is, what should a junior programmer be comfortable doing when working with a DVCS? Should it be simple adds, commits, merges, remotes, or would you expect something more? If you've been asked good questions in interviews, I'd appreciate them being shared.

I don't really want to hire the developer that pushes a backwards merge!

Edit: I really should have mentioned before this got rolling that our distribution model relies heavily on Git and our self-hosted repository (I'm a web developer), and that's why  I feel it's important to know (at the very least) the consequences of serious actions like remote pushes; these actions triggers a few different processes in our environment. My fault! The answers have still been very helpful.


答:
If you're looking for a junior developer, "I've worked with github" is probably plenty.

Having graduated not that long ago, I think most students will not have run into situations where truly "advanced" uses of Git or SVN would have ever applied. I spent most of my college education as the sole committer to an SVN repository, it's just the nature of the projects you work on.

I would focus on their programming and critical thinking skills. If a candidate has those, they can pick up Git in a couple days with someone to bounce questions off of. You could search for someone who knows Git, but it should be way down on the list of important things they should know.


答:
There are at least three issues that the other answers point out; but I'd like to try and treat both of them together.  The two issues are:

expertise: Someone on the team has detailed knowledge about a particular field;  this knowledge is independent of the specific implementation of that domain in the project

leadership: Although the work of building the project may be shared across many developers; the roadmap, as well as immediate decisions about important implementation details are in the hands of a particular team member or only a few members of the team.

egoless code: The particular way that the project is implemented is not dependent on the coding styles, practices or knowledge of any particular developer on the team; and by strict adherence to a well known coding style or a well mantained specification, any new team-member has an equal chance at understanding the hows and whys of the project as the experienced devs.

When the topic is purely one of expertise, the project's success may be dependent on a high level of knowledge about the domain; but it isn't dependent on a specific expert's knowledge of that domain.  The experts, though perhaps rare and valuable, are still essentially interchangeable; one experienced tax accountant is as useful to a tax planning software project as another, from the point of view of their domain knowledge.  The issue becomes one of how well the expert is able to transfer her knowledge to the project.

When the topic is purely one of leadership, the project's success is dependent mainly on the consistency and insight of the decisions made by the project leader;  although we tend to favor project leads that have experience in the domain, or are proven as project leaders, this is sometimes secondary to the role.  The "leader" could change from day to day if the decisions made are consistent from one case to the next and each decisions is swiftly executed by the team.  If this is working right; many decisions don't have to be "made" by the project lead because the team already understands what decisions will be made.

I don't think the question was really about egoless code, but it's hard to talk about code ownership without also discussing how important this issue is.  Maintaining a project is probably the larger part of the development cycle.  The way to understand this issue is to wonder what would happen if some of the developers had to leave it immediately.  What would happen if the whole team had to be replaced?  If the project is cast in doubt because it depends on some key players, then you run a high risk of failure.  Even if you never lose a single team member, the simple fact that one or a few developers are needed to advance the project means you might not be working as efficiently as you could if more developers were clued in.


答:
I agree with the sentiments that you shouldn't hang to heavily on how much your prospects really know git, but if you wanted to know more about what they know, you might just try to get them to talk about some of these topics:

"Have you ever merged anyones patches into your repository?"

"What are the different ways you've used tags in your development cycle?"

"When would you commit your changes to your local repository? When would you push them to origin?"

"Have you ever fixed a mistake by rewriting the history of a git repository?  Have you ever been stung by it?"

I wouldn't spend much time on it, but it might still give you an idea of how the candidate works when combining his code with the rest of the team; which of course is really the key idea of DVCS.


答:
The process at my organization makes extensive use of branches and (a process that looks a bit like) continious integration.

At a high level view, developers don't worry too much about merging with mainline, they just commit to the branch. a (semi-) automated process checks what features are scheduled to go into mainline, merges those branches and builds the product.  The process works because we actually integrate this process of merging from the issue tracker, so that the build tool knows what branches to merge.

Title: To branch or not to branch?

Body:
Till recently my development workflow was the following:

Get the feature from product owner

Make a branch (if feature is more than 1 day)

Implement it in a branch

Merge changes from main branch to my branch (to reduce conflicts during backward merging)

Merge my branch back to main branch

Sometimes there were problems with merging, but in general I liked it.

But recently I see more and more followers of idea to not make branches as it makes more difficult to practice continuous integration, continuous delivery, etc. And it sounds especially funny from people with distributed VCS background who were talking so much about great merging implementations of Git, Mercurial, etc.

So the question is should we use branches nowadays?


问:
What are the characteristics for a good report generation software for reporting and tracking software benchmarking results?
This is an offshoot question from this answer to a previous question, where http://speed.pypy.org is highlighted as an example having a good presentation.

(However, it appears to me that the project doesn't separate the components of execution/tracking/report-generation/web-service, which makes it harder for other people to adopt.)

I am interested in both the functional and the UI requirements of such software. I hope to be able to choose an existing one based on the criteria so that I can use it in my project.

Right now, the only thing I can think of is that the Execution UI should be similar to a Unit Testing harness, but the Reporting UI should be totally different from the xUnit family of software. Webpages seem to be a better way to navigate through the results.

And, along with some minor ideas:

There should be a tracking component to track performance changes at all levels

However, the presentation layer should highlight only "relevant" performance changes, that is, performance drops in important areas that are serious enough to require developers' attention.

I am also interested in whether any of the advices from Edward Tufte can be applied here.

答:
You might find this so question about (macro-)benchmarking tools for java interesting (even if you use a different language):

for runtime measurements, there are a lot of technical aspects to consider, mainly optimizations;

for runtime measurements, the statistics are very important, but very few tools implement them;

there are a lot of monitoring tools that offer a unit testing or logging like harness, and a standardized reporting interface (JMX) - just like you thought of;

Point 2 and 3 are somewhat contradictory: the execution has to know about the reporting to do the statistics right, i.e. to be able to decide how often some code should be executed and measured to get a high enough statistical confidence;

a good tool that is pretty language independent is Auto-pilot.


答:
Code ownership tends to prevent refactoring, create development bottlenecks and cause ego problems when code has issues that should be dealt with.

I do recommend consulting with code authors before changing, even though high standard code should be well enough documented, unit tested, integration tested and system tested to make this redundant, it still can't hurt to get another opinion.


答:
In the final analysis, it's the programmer that drives the programming. Style issues exist, but they are secondary to getting the program out.

It IS helpful to give programmers SOME style guidance. This can/should be done before the programmers are put to work, especially if they are relative beginners to the environment, or to programming itself. Given guidance, some programmers will be very style conscious, others less so. The guidance given at the beginning of the project will help the first group of programmers, thereby making the overall task easier. It might do little for the second group, which will (hopefully) make up in creativity, what they lack in conformity.


答: Agree with the others in that it is a tool not a concept.  Consider your limited interview time with these individuals- spending several minutes of time on discussing DVCS may not be the most efficient use of scarce time.  All the version-control packages are easy enough to pick up at the level an intern would be using them (they're not going to be administering your system, just using it).</p>


问:
How have you made unit testing more enjoyable?
If you've always loved unit testing, good for you! But for the unfortunate ones who weren't born with a liking for it, how have you managed to make this task more enjoyable ?

This is not a "what is the right way to unit test" question. I simply want to know little personal tricks that reduce the boredom (dare I say) of writing unit tests.

答: Obviously, there is the satisfaction of test-first development and the feeling you get when your design and tests come together. However, writing tests for pre-existing/legacy code can be mind-numbing and frustrating.  When our project was in a maintenance pattern, I wrote tests for untested code using the coverage report as a game.  You can create a bit of a competition with yourself and/or others to boost the coverage numbers. Granted, you might take it too far and create some bad tests, but it can be a good motivator.</p>

ContentLicense: CC BY-SA 2.5


问:
Do companies care about university grades when hiring programmers?
Most of my fellow students that I've talked to claim that aiming for good grades is useless as the companies don't care about them when hiring programmers. To them, it's enough to have simply attended courses which may be important, and that's that.

Is this true? Are university grades useless when leaving campus, or do employers ask to see them for an interview?

答:
In general, the interviewer is going to look at a student and try to find multiple signs of either the student having already been vetted as being smart by someone, or, impressive work done somewhere else, or else, general competence. In order of importance, interviewers look at the following items when deciding whether to hire students, stopping when they've seen enough impressive details:

School attended
Schools tend to be filters - they tend to select particular kinds of people and students, through their admissions process. The school you've attended tells people that you've already, at least at one point in your life, seemed to be particularly productive and smart. It's an external filter.

Program graduated from
Different programs have different requirements and demands, and some are considered to be more challenging or appropriate than others. This changes based on the region you're in, and the time you're attending school. Just having graduated, though, gives important information to the employer about the kind and quality of work you do.

Relative placement within the program Grades don't matter so much as relative placement does. Grades have slowly been inflating over time, with more and more people graduating with higher and higher grades. A relative placement (6th in my year) is much more useful and will get more attention.

Relevant courses attended Relevant doesn't necessarily mean related to the work you're going to do. If you've taken a course requiring you to write a major piece of code (virtual machine for a subset of Java) in a team of four, that tells an employer lots of useful information about how competent you are.

Extra curricular experience What has the student done besides attend university. Have they started their own projects on Git? Do they have their own startup on the side? Are they in the top 10 player list for North America for one or more video-games? Do they know how to play an instrument? Did they achieve a black belt in Aikido? Did they start a wine tasting society which grew to several hundred members?


答:
This is bad for a lot of reasons, I worked in a shop where they tried to change from this to something more reasonable and it was ugly.

The reasons why this is bad:

If the code owner takes a vacation and some big bug pops up in their stuff, it will be very difficult and time consuming to try to learn the code AND fix the bug

If the code owner leaves the company, their projects will be severely set back since all the heritage and tribal knowledge just walked out the door

Documentation is poor.  If I'm the only person to code in it, why would I document it?  Related is the issue that any documentation that is forced to be created will also likely be poor because no one will know enough about the code to really say if the documentation is complete or even accurate.

Code holy wars can easily ignite when everyone has their own little sandbox, as others have mentioned this can get really stupid really quickly.  Where this is a problem is when two people have to work together, neither is used to compromising ever on anything.

Because of the point above, the teamwork skills never form- people never have to work with others.

Fiefdoms can easily form, little kingdoms made from pockets of waste that don't buy the company anything.  You don't know these are happening until it's too late because module or tool X is Bob's responsibility, and woe to thee who should even inquire as to what Bob is doing in his code.

Code reviews and peer reviews suffer since no one knows anything about the code.  If you don't know the code, you can't spot the places that aren't right and are limited to commenting on text formatting and naming conventions alone.

And if you work for me... the company owns the code, not you.  We have pride in what we do and what we accomplish, and in what we write, but it is a group thing, like when your team wins a difficult match.  Any employee who works for the company owns the code equally, and in the course of doing their job is allowed to edit it in any way they please to do their job which is to forward the company's goals.

The biggest ones really are the personnel issues and the documentation.  That person will leave some day, and boy will you be pushing schedule to the left for a few weeks.

The better approach is to have everyone be familiar with every part of the code base (or a half-dozen parts or so if it's really large and diverse) to the point that they can

Fix any defect in that area

Add minor or moderate new features or enhancements

Each person tends to know a little bit more about some things than others, so for the hard problems two or three can band together, or the defacto expert can take it on.  I've worked in groups where this was the case and it worked out really nicely.  Not only were there none of the cons listed above, the staffing was much more predictable since we weren't hunting around for experts.

The pro to sole code ownership is that the "code owner" can likely do things faster than others, but this only holds true if everyone is a "code owner" on non-overlapping projects.  In other words, if people rotate around the advantage of the "sole code owner" goes away.


问:
Is there a fundamental reason for keeping file systems and versioning systems separate?
I've done some work looking at Next3 and ext3cow, and a few other file systems that provide snapshots and/or file versioning. It seems a bit strange to me that file systems only go part-way with version control, though.

Are there fundamental reasons for keeping the two separate? How challenging would it be to, for example, build a version of the ext3 file system which includes a git-like interface for managing file versions?

答:
Sure- consider the size. I've got 850GB sitting on my harddrive, used, with 70GB left. How precisely do you plan on versioning any of that content? I would need a truly insane amount of space to version that.

Source control is only really useful for that- source. Because much else is just too big to keep around redundant copies of. Source is nice and small and frequently modified. My 150GB of Stargate, however, is massive and will never be altered. I certainly wouldn't want it to be versioned.


问:
What is O in Big O?
What is Big and O in Big O notation? I've read the definitions and it doesn't tell what is O pronounced as 'oh'.  For example - I understand that O(n) is complexity of a linear algorithm where n could be the number of operations. but what is an O?

答:
O stands for order.

It was originally introduced by the German mathematician Paul Bachmann in the second volume of his books on number theory Die Analytische Zahlentheorie, published in 1894 (p. 401). He notes, after a formula where he first uses the notation:

(...) wenn wir durch das Zeichen O(n) einde Grösse ausdrücken, deren Ordnung in Bezug auf n die Ordnung von n nicht überschreitet (...)

My translation:

(...) where with the notation O(n) we indicate a magnitude of which the order with reference to n does not exceed the order of n (...)

In contrast with what others have said, nothing in his text indicates that this is in fact a Greek capital omikron. He uses plenty of both Greek and Latin characters, so there isn't really any way to tell. Given his continued use of "Ordnung n log n" etc. in the text it's clear that it stands for "Ordnung" (German for "order" if there was any doubt) in any case, but that could still leave open the use of a fancy Greek O.

However, the origin of the omikron is more likely a retronym due to Donald Knuth who introduced the symbols omega (Ω) and theta (Θ) for related concepts in his paper Big Omicron and Big Omega and Big Theta, or possibly Hardy and Littlewood who introduced an omega symbol earlier.

Title: What is O in Big O?


问:
How do you off load work from the database?
In at least the web development field, web servers are everywhere but are backed by very few database servers. As web servers get hit with requests they execute large queries on the database, putting the server under heavy load. While web servers are very easy to scale, db servers are much harder (at least from what I know), making them a precious resource.

One way I've heard from some answers here to take load off the database is to offload the work to the web server. Easy, until you realize that now you've got a ton of traffic internally as a web server tries to run SELECT TOP 3000 (presumably to crunch the results on its own), which still slows things down.

What are other ways to take load off the database?

答:
One way I've heard from some answers here to take load off the database is to offload the work to the web server. Easy, until you realize that now you've got a ton of traffic internally as a web server tries to run SELECT TOP 3000 (presumably to crunch the results on its own), which still slows things down.

I think you might be taking this a bit too literally. It's not about having the web server(s) perform the same calculation as the database. In most applications there are opportunities to cache not just the result set from the database, but actually to cache the end result of whatever the result set is being used for (typically to generate some content on a page).

As an example, let's say you have a "most popular blog posts" list on a blog that is relatively expensive to query from the database. Without caching, if your blog suddenly gets a surge of heavy traffic, your blog application will repeatedly query the database to generate the "most popular posts" list for every page load and quickly fail under load. Now let's say you just cache that list of popular posts in memory for 15 minutes. This way even if you get a million hits in an hour your database will execute that query only four times.

By doing this you are making a tradeoff for the most popular blog post list to be stale for up to 15 minutes but gaining significantly decreased load on the database (and increased scalability).


问:
Should we encourage coding styles in favor of developer's autonomy, or discourage it in favor of consistency?
A developer writes if/else blocks with one-line code statements like:

```<code>if (condition)
   // Do this one-line code
else
   // Do this one-line code
</code>```

Another uses curly braces for all of them:

```<code>if (condition)
{
   // Do this one-line code
}
else
{
   // Do this one-line code
}
</code>```

A developer first instantiates an object, then uses it:

```<code>HelperClass helper = new HelperClass();
helper.DoSomething();
</code>```

Another developer instantiates and uses the object in one line:

```<code>new HelperClass().DoSomething();
</code>```

A developer is more easy with arrays, and for loops:

```<code>string[] ordinals = new string[] {'First', 'Second', 'Third'};
for (i = 0; i < ordinals.Length; i++)
{
    // Do something
}
</code>```

Another writes:

```<code>List<string> ordinals = new List<string>() {'First', 'Second', 'Third'};
foreach (string ordinal in ordinals)
{
    // Do something
}
</code>```

I'm sure that you know what I'm talking about. I call it coding style (cause I don't know what it's called). But whatever we call it, is it good or bad? Does encouraging it have an effect of higher productivity of developers? Should we ask developers to try to write code the way we tell them, so to make the whole system become style-consistent?

答:
While your first example is not great (the argument that it's more bug-prone under modification carries some weight), in general I've actually grown to prefer that developers use slightly different coding styles.

After working with other team members' code, sometimes for as little as a few months, it essentially starts to work line an in-line git blame.  After having been at my company for 10+ years, I can probably tell you with 80%+ accuracy who wrote any given class anywhere in our 500k lines of code, just by looking at it.

While there is a tiny bit of "ramp time" when you start looking at code that uses a style you don't agree with, what you're really doing in that time is saying "oh, this looks like John Doe's code (because he uses style X but not style Y, etc.)".  And that brings with it a whole heap of context.  To a first approximation, you know what to expect from John's code -- what other parts of the codebase he understands well and what parts he doesn't, whether he's an SQL guru or a GUI novice, etc. etc.

Running everyone's code through a formatter essentially strips out this information, hiding it behind a git blame, which you may not bother to run.


答: The fundamental reason is people don't want to create a new version every time they save their files.  If you've ever worked on a system like VAX/VMS that creates a new version every time you save, you'd know how annoying it can get.  Your disk fills up quickly, and you only have version numbers to go off of if you want an older version, no useful commit messages.  The killer feature of version control software is to be able to choose when not to commit.

Title: Is there a fundamental reason for keeping file systems and versioning systems separate?

Body:
I've done some work looking at Next3 and ext3cow, and a few other file systems that provide snapshots and/or file versioning. It seems a bit strange to me that file systems only go part-way with version control, though.

Are there fundamental reasons for keeping the two separate? How challenging would it be to, for example, build a version of the ext3 file system which includes a git-like interface for managing file versions?


答:
I think it comes down to the size of the project, and how many people are working on it. A skilled programmer can look at both differnt format styles and know what was going on in both of them but there needs to be a consictancy so the eye can catch it easily. If your going to do your single line ifstatments with out the curle braces then that project should not use them Who ever is leading that project should have that choice. I like things to look clear cut and also very compact as i can get them. If your going to make an a single line if statmeents they better looks like this

```<code>if() {}
else() {}
</code>```

Or even:

```<code>if() {} else () {}
</code>```

But a single line if should not use the spacing of a mulitiline if. It is just how I do things. I dont mind the way the object is called and that depends on how many times its called. if its getting called a few times then i rather start the object and depends if it has constuctors and what not also. Because if you have a constructor and you call:

```<code>Object.method();
Object.method2();
</code>```

Then you ended up call the the object constuctor method twice when it could have been avoided by instancying the object fully.

When it comes to foreach and for loops Its also about the lanauge some lanauges give you better control when looking at the array in a foreach loop so you have the key and the value in temp arrays. And I know some lanagues have some sort of optimization because they can look at the loop and know exactly how many times its going to get called.

Body:
I think it comes down to the size of the project, and how many people are working on it. A skilled programmer can look at both differnt format styles and know what was going on in both of them but there needs to be a consictancy so the eye can catch it easily. If your going to do your single line ifstatments with out the curle braces then that project should not use them Who ever is leading that project should have that choice. I like things to look clear cut and also very compact as i can get them. If your going to make an a single line if statmeents they better looks like this

if() {}
else() {}

Or even:

if() {} else () {}

But a single line if should not use the spacing of a mulitiline if. It is just how I do things. I dont mind the way the object is called and that depends on how many times its called. if its getting called a few times then i rather start the object and depends if it has constuctors and what not also. Because if you have a constructor and you call:

Object.method();
Object.method2();

Then you ended up call the the object constuctor method twice when it could have been avoided by instancying the object fully.

When it comes to foreach and for loops Its also about the lanauge some lanauges give you better control when looking at the array in a foreach loop so you have the key and the value in temp arrays. And I know some lanagues have some sort of optimization because they can look at the loop and know exactly how many times its going to get called.


问:
Other things to learn for becoming a Database Admin/Developer?
Obviously i'll have to make some sort of choice at what DB i choose to go with (MS-SQL/MYSQL/etc) but this question isn't about that.

The question mainly is what other languages/tools would be helpful for someone wanting to get into Database Programming/Administration. I assume PHP would be helpful with MySQL along with XML Probably (or not?) however Im not sure of what else. Im pretty fluent in C/C++ but if I wanted to get more in depth with the NoSQL databases out there I probably need to brush up on my Java skills.

Also Side question.....is 25 too young to be getting into this stuff? I took a few Database classes in College (Which I just recently graduated from), but I don't want it to be too late to learn something new.

答:
For a DBA, you need to know about the following (among others):

1- Operating system(s), LANs, Security

2- Storage device types (RAID 5, etc.)

3- SQL for RDBMS

4- Database design and modeling, including design optimization, index types and when to use each type, use of partitions, etc.

5- Stored procedures (if the language supports it)

6- Tools particular to the database such as backup, recovery and 3rd party tools

7- Types of application systems (OLTP, Data Warehouse, maybe real time)

8- General server security and in particular your chosen database security

9- Cloud environments

Regarding the age, I don't think it matters. What is important is the brains.

Now the thing to consider is the effect of Cloud databases on the future market demand for DBAs - This is something I don't know enough about, so research it.


问:
*Code owner* system: is it an efficient way?
There is a new developer in our team. An agile methodology is in use at our company. But the developer has another experience: he considers that particular parts of the code must be assigned to particular developers. So if one developer had created a program procedure or module it would be considered normal that all changes of the procedure/module would be made by him only.

On the plus side, supposedly with the proposed approach we save common development time, because each developer knows his part of the code well and makes fixes fast. The downside is that developers don't know the system entirely.

Do you think the approach will work well for a medium size system (development of a social network site)?

答:
Like so many of these questions, I think the answer is:

It Depends

There is reason to believe that taking the position that every programmer should know every line of code is misguided.

If we assume for a moment that someone with a deep understanding of a piece of code will make changes 5 times faster than someone who doesn't know it at all (not a giant leap of faith in my experience) and it takes about a month of coding experience to get a really good understanding of a significantly sized module (also not unreasonable) then we can run some (completely bogus and fictitious) numbers:

Programmer A: has deep understanding

Programmer B: none

Lets say programmer A gets 1 unit of work done per day.  In 4 weeks of 5 workdays he/she can get 20 units of work done.

So programmer B, starting at 0.2 units of work per day, and ending with 0.96 units of work on his/her 20th day (on the 21st day they're as good as programmer A), will accomplish 11.6 units of work in the same 20 day period.  During that month programmer B achieved 58% efficiency compared with programmer A.  However, you now have another programmer who knows that module as well as the first one.

Of course, on a decent sized project, you might have... 50 modules?  So getting familiar with all of them takes you about 4 years, and that means the learning programmer is, on average, working at  58% efficiency compared to programmer A... hmmm.

So consider this scenario: same programmers, same project (A knows it all, and B knows none of it.)  Lets say there are 250 working days in the year.  Lets assume that the workload is randomly distributed over the 50 modules.  If we split both programmers evenly, A and B both get 5 working days on each module.  A can do 5 units of work on each module, but B only gets, according to my little Excel simulation, 1.4 units of work done on each module.  Total (A + B) is 6.4 units of work per module.  That's because B spends most of their time without any skill with the module they're working on.

In this situation, it's more optimal to have B focus on a smaller subset of modules.  If B focuses on only 25 modules, they get 10 days on each, totalling 3.8 units of work on each.  Programmer A could then spend 7 days each on the 25 modules that B isn't working on, and 3 days each working on the same ones as B.  Total productivity ranges from 6.8 to 7 units per module, averaging 6.9, and that's significantly higher than the 6.4 units per module we got done when A and B spread the work evenly.

As we narrow the scope of modules that B works on, we get even more efficiency (up to a point).

Training

I would also argue that someone who doesn't know as much about a module will interrupt the person who does a lot more than someone with more experience.  So these numbers above don't take into account that the more time B spends on code they don't understand, the more of A's time they take up by asking questions, and sometimes A having to help fix or troubleshoot what B did.  Training someone up is a time consuming activity.

Optimal Solution

That's why I think the optimal solution has to be based on questions like:

How big is your team?  Does it make sense to have everyone cross trained on every part, or if we have a 10 person team, can we just make sure each module is known by at least 3 people?  (With 10 programmers and 50 modules, each programmer has to know 15 modules to get 3x coverage.)

How is your employee turnover?  If you're turning over employees at an average of every 3 years, and it takes longer than that to really know every corner of the system, then they won't be around long enough for the training to pay itself back.

Do you really need an expert to diagnose a problem?  A lot of people use the excuse, "what if that person goes on vacation", but I've been called in numerous times to diagnose a problem in a system that I've had no experience with.  It might be true that the experienced person could find it a lot faster, but it doesn't mean you can't live without them for a week or two.  Few software systems are so mission critical that the problem has to be diagnosed in 1 hour instead of 5 hours or the world will end.  You have to weigh these risks.

That's why I think "it depends".  You don't want to split 20 modules between two programmers right down the middle (10 each), because then you have no flexibility, but you also don't want to cross train 10 programmers on all 50 modules because you lose a lot of efficiency and you don't need that much redundancy.


问:
If the purpose of a single complicated LOC is clear, would you bother to split it on to multiple lines to make its method clear as well?
Given some (relatively) complicated line of code, I would often be inclined to split it onto multiple lines to make its function/purpose clear to others.

However, if it is quite clear from context what a line does, would you still do the same thing merely to make clearer how it does it? Or would you take the attitude that future developers probably don't know/care how it works, only that it works?

For some context, the particular line that's prompted this question is Python code that takes a string like "1.title" and uses it to modify self.data[1].title:

```<code>#IRL, these 2 values are already set somehow
id = "1.title"
val = "foo"

setattr(self.data[int(id[:id.index(".")])], id[id.index(".")+1:], val)
</code>```

That last line is not the nicest thing in the world to read, so I was thinking of splitting it into:

```<code>index = int(id[:id.index(".")])
attrib = id[id.index(".")+1:]
setattr(self.data[index], attrib, val)
</code>```

If you wanted to go crazy, you could even do dotLocation = id.index(".") first, and use that in the setting of index and attrib.

This is probably a bit clearer to someone else reading it for the first time, but I prefer it nice and concise on one line, and it's highly unlikely that anyone is going to need to modify this one-line utility function. Is there really much point to splitting it up like that?

(Note: I'm fully aware that this is not exactly life-or-death stuff. I'm not going to lose any sleep over it,  I'm just wondering what others would do in this kind of situation.)

(Last thing: someone might want to add better tags to this, it's my first Programmers question :) )

答:
It does look neat to have things concise. However, look at the following features of splitting especially when your 1 line is composed of separate logical functions.

Simple to read and maintain by others

Easier to catch errors on the individual logical parts rather than on the entire expression (in your example, index and attrib are logically separate parts) - You can test the result of each part separately

In a system with 10s of thousands of lines of code, what difference would it make if we add a few more?

A somewhat similar question was asked on:
Formatting 'Complex' Math

Modification:
I can't say that decomposition is always the right way. If the expression is obvious and you are not in identifying in which part it fails, make it all in one line.


答:
Besides the items Emmad gave, I'd add to the list:

Locks - get a good understanding of how each database system uses locks

NoSQL vs SQL databases - Both have their place; they have very different strengths and weaknesses. Get to know those so that you can help recommend the right tool for the job.

Scaling & Replication - It is becoming more and more important to have a database that can scale to the demand. Sometimes this is nothing more than upgrading hardware; other times it is a much more involved solution. Understanding these options can be very valuable.

I also would not worry so much about a specific product. If you want to learn, SQL Server or MySQL are your best choice because they have decent tools and very good free versions. Oracle and DB2 are good products but they are expensive and last time I looked, don't have any free versions available for home users.

Oracle offers a free version.

Title: Other things to learn for becoming a Database Admin/Developer?

Body:
Obviously i'll have to make some sort of choice at what DB i choose to go with (MS-SQL/MYSQL/etc) but this question isn't about that.

The question mainly is what other languages/tools would be helpful for someone wanting to get into Database Programming/Administration. I assume PHP would be helpful with MySQL along with XML Probably (or not?) however Im not sure of what else. Im pretty fluent in C/C++ but if I wanted to get more in depth with the NoSQL databases out there I probably need to brush up on my Java skills.

Also Side question.....is 25 too young to be getting into this stuff? I took a few Database classes in College (Which I just recently graduated from), but I don't want it to be too late to learn something new.


问:
Login with Twitter or Facebook - How to link accounts
I've been developing a site and I've been trying to come up with a method to make sure all Social Network accounts of a certain user are linked together. I've had one snag from the start, and maybe someone here has an idea of what to do.

This is the problem. Let's say someone comes to my site and they click login with twitter.

My site

creates an account (adds user to member database)

adds twitter credentials to database for that user

logs the user in

Now let's say this person logs out, and the next time they come to my site they login with Facebook.

My site

checks member database for a user with the same email as the one sent from Facebook on authentication

If there is no match, I create a user

add Facebook credentials for that user

Here is where my problem comes in. Twitter does not send an email of the user on authentication. So my database and script, when someone logs in with Facebook after they've already logged in with Twitter previously, does not recognize the accounts should be linked and creates a whole new user.

Is the only possible way to keep track with cookies? Or am I mjust missing something in the logic of it?

Any ideas would be great.

By the way this is for a website, using php + mysql

Question update

Hey Demian,I took a look at edit logins and noticed they don't have a twitter option. My issue isn't when the user is already logged in, everything works great and connects the accounts. It's more like this.

Lets say a user logs in to my site for the first time with twitter. I give them a unique user ID in my "members" database table, then add their oauth credentials for twitter in my oauth table, linking it to their member ID.

\Now let's say a month goes by and a user comes back. This time, though, they login with Facebook. There is no way for me to tell which user they are in my database from their previous login with Twitter because I don't have that unique member ID to link it to.

That's why I'm thinking storing the unique member ID in a cookie is a good idea, but what if they delete the cookie?

答:
Take a look at how StackExchange does it. Go to your profile page and click "edit logins" and follow that flow. Honestly, it seems to be the most reasonable of those that I've seen.

Essentially, you'll store a single user object in your database and add login providers (through a table with a FK perhaps) as your user chooses them. Now, when your user logs in with any of the providers, you know which distinct user (in your system) it represents.


问:
Should Professional Development occur on company time?
As a first-time part-time software developer at a small consulting company, I'm struggling to organise time to further my own software development knowledge - whether that's reading a book, keeping up with the popular questions on StackOverflow, researching a technology we're using in-depth, or following the front page of Hacker News. I can see results borne from my self-allocated study time, but listing and demonstrating the skills and knowledge gained through Professional Development is difficult.

The company does not have any defined PD policy, and there's a lot of pressure to get something deliverable done now! when working for consultants. I've checked what my coworkers do, and they don't appear to allocate any time to self-improvement; they just work at the problems they're given, looking up specific MSDN references, code samples, and the like as they need them.

I realise that PD policy is going to vary across companies of different size and culture, and a company like my own is probably a bit of an edge case. I'd love to hear views and experiences from more seasoned developers; especially those who have to make the PD policy choices in their team or company.

I'd also like to learn about the more radical approaches to PD, even if they're completely out there; it's always interesting to see what other people are trying.

Not quite a summary, but what I'm trying to ask:

Is it common or recommended for companies to allocate PD time?

Whose responsibility is it to ensure a developer's knowledge and skills are up to date?

Should a part-time work schedule inspire a lower ratio of PD time : work?

How can a developer show non-developer coworkers that reading blogs and books is net productive?

Is reading blogs and books actually net productive? (references welcomed)

Is writing blogs effective as a way of PD? (a recent theme on Hacker News)

This is sort of a broad question because I don't know exactly which questions I need to ask here, so any thoughts on relevant issues I haven't addressed are very welcome.

答:
Company-backed PD time can encourage an atmosphere of learning and sharing.  I don't really like the style where companies schedule PD time for you (like one Friday afternoon a month), but I do like a company that makes allowances for it.  I worked at a company where we actually set PD goals, and there was a heavy emphasis on sharing what you learned.  Some people did presentations, but I personally like learning about new ideas and then implementing them.  Sometimes this is through projects in different languages, sometimes they are still related to the current project (and may even be incorporated later).  I believe it does pay off because it can lead to more skilled developers.  I think companies may see more benefit from PD when developers share their knowledge, even if most of it is individual.  At the very least, discussing what you have been working on is good.

For example, I wrote a mock testing framework to see how it was done, and I also embedded an IronRuby shell that interacted with our C# application.  The mock framework helped me learn a lot more about reflection, expression trees, and testable code practices in general, and the IronRuby shell helped me learn about the DLR and brush up on my Ruby.  Experimentation is healthy here.

However, it is very hard when the client is breathing down your neck, and I will admit that my previous company really slipped on PD towards the end because the project was so demanding.  Unfortunately, I find that companies that do not foster this kind of environment often attract a lot of people who aren't passionate about what they do, and they tend not to improve their skills over time.  That's a generalization, but it's my current experience.


答:
DBA and developer are different roles.  In a small company you can do both but it is more usual for there to be a DBA and a database developer.

Emmad covers most of the DBA role but you also need to understand intimately the factors that go into making your database perform well or badly, memory management, SQL tuning etc.  Some databases give you lots of tuning tools & options (Oracle) others try to be a black box (MySQL, Interbase) which means that you have more problems tracking down the root cause of performance issues.

Database developers write stored procedures to do significant back-end processing.  For that you need to know SQL in all of its' varieties: DDL, DML & PL.  Knowing database tuning helps as well so you don't write horribly slow code, although a good DBA can help with this.


答:
Before immersing yourself in vendor-specific aspects, learn the science behind RDBMS.  Also learn the SQL standard.  You'll be using it ad nauseum (but that's a good thing in this case).

Then once you are comfortable with the aforementioned you should find an RDBMS that suits your desires.  If you're a Microsoft professional, you'd want to go with SQL Server.  If you are a Sun professional, then Oracle...etc. etc. etc.

The tools and the hey-that's-cool things will come with time and experience.  If I was you, I'd be more concerned with the bigger picture on data science.

And no, 25 is definitely not too young to invest in a promising career of database administration/development.  Follow your passion!  Databases are awesome...


问:
Submit issue, pull request, or both for a very small fix?
I've made a 4-line bug fix to a minor issue in a library on github. The project is actively maintained with changes every few days.

What is the ideal way to submit a fix that small? Is it to fork, fix and submit a pull request; file an issue and a pull request; or just file the issue with my fix copy-pasted? (Or something else?)

答: I went ahead and made a pull request. That was apparently okay to the library maintainer even for a tiny patch, though I needed to make some modifications. (Fantastic, I messed up a 4-line patch.) Also, a pull request automatically adds an issue associated with the pull request, so another issue would be redundant. This seems to be the best solution for smaller projects; larger projects might have different policies.</p>


问:
Is it an inefficient workflow to write out code and THEN go back and optimize?
I'm a newer enthusiast programmer. I've been doing small and big projects on and off for the past two or three years.

I always hit small snags in my code that add up to big memory hogs or unnecessary lines of code down the road. My philosophy on big projects has always been to just 'get it out of my head' and write all the code into a working product, then going back and reducing the code to a simpler, more optimized form. However, this doesn't always work: when doing database structures, I tend to have to go back many times to add in features that come up spur-of-the-moment. Entire blocks of code have to be erased because of a spontaneous brainchild.

My question to you is, is it more efficient to write an entire program and THEN go back and optimize it, or should I optimize code as I write it?

答:
I will make you a counter proposal. Suppose you were to outline your classes first, whether this is through something like UML mocks, or simply class outlines it matters not, then, once you have determined what appears to be the best approach, begin writing. Once you have finished a noticeable portion of the project, then it is appropriate to go back and clean the cruft.

Depending on the scale of the project and the developer, this might be a set of classes, an individual class, or even (rarely) a method. But it is almost never a good idea to wait until everything is done to optimize. OTOH, it is also equally bad to optimize too soon. This leaves as the only option a process of writing and then cleaning, and writing and then cleaning.


答:
This is a horrible idea. I have worked at a company that has used this approach and it is pretty much a recipe for heaps of technical debt. The bottom line is that two heads are almost always better than one. Why? Because unless you're an idiot, you know you're not a perfect programmer and you're not going to catch every mistake you make. This is why you need a team - more eyes looking at the same code from different perspectives.

It boils down to one thing: discipline. How many lone programmers do you know who are truly disciplined in their coding style? When you don't code with discipline, you take shortcuts (because you'll "fix it later") and the maintainability of the code suffers. We all know "later" never comes. Fact: It is harder to take shortcuts when you're immediately accountable to your peers in a team. Why? Because your decisions will be questioned and its always harder to justify shortcuts. End result? You produce better, more maintainable code that is also more robust.


答:
Premature optimization is the root of all evil.

That quote gets overused and applied beyond the original intended context, but the overall point certainly applies here: don't stop to optimize until you're sure you need to optimize it, and you won't be sure until after you've written most of the program.

Title: Is it an inefficient workflow to write out code and THEN go back and optimize?

Body:
I'm a newer enthusiast programmer. I've been doing small and big projects on and off for the past two or three years.

I always hit small snags in my code that add up to big memory hogs or unnecessary lines of code down the road. My philosophy on big projects has always been to just 'get it out of my head' and write all the code into a working product, then going back and reducing the code to a simpler, more optimized form. However, this doesn't always work: when doing database structures, I tend to have to go back many times to add in features that come up spur-of-the-moment. Entire blocks of code have to be erased because of a spontaneous brainchild.

My question to you is, is it more efficient to write an entire program and THEN go back and optimize it, or should I optimize code as I write it?


问:
Forgetting stuff I've done before and how do you fix this
I'm not sure if it's just me or if this is common in our field.

The past year has been a bit intense for me. I've been learning a few different technologies to get some tasks done and sometimes I've had to completely focus on that one new technology I'm learning.

What I noticed though when I go back to using everything together in the full project is that I forgot how to do things that I already knew how to do before I started focusing on learning that other new technology. Sometimes I find that I forget even simple things like the syntax for selecting a div in jquery, that I have to go back to old files to get a quick peek.

Sometimes I could be coding something that I recognize I did before in another project, but can't quite remember which project it was for, so I have to go through several projects and look through the code to try and remember where I did that.

What ways have you invented to prevent yourself from forgetting things you've done before, or to easily access code you've written in the past?

答:
That happened to me in many instances before. That's why we write documentation in our code.

And sometimes, you just need a reference over the internet to help you. It's perfectly fine to look up for help.


问:
Is programming a profession not for a person with speech impairment?
My friend has 15 years of programming experience and Ph.D. in mathematics. He has also cerebral palsy with speech impairment. Because of his handicap, he chose to being a software developer after his Ph.D. As far as I can see, he is still an excellent c# developer.

Nowadays, however, he has hard time to find a job for himself because most of developer jobs require good communication skills. Looking at him struggling so much, do I have to advise him software industry is not suitable for him any more? It will be extremely difficult for me to do that to the friend but I think it would be better than making him wasting his time.

What do you think?

Update: Thanks a lot for your excellent answers. I can see most answers recommend against my advice and I really really hope you guys are right. In reality, however, he has been rejected in 100 or so phone interviews. That's where I want to be a potential bad adviser rather than a politically right friend.

答:
He could always work on his own. If his programming skills are so strong I find it unfair he has to renounce to his passion because of his handicap.

Communication doesn't just happen by spoken words.

If he's as good as you tell, he won't have problems finding clients online, where nobody needs to know about his impairment.


答:
What do you think?

I think that each team can take a person with speech impairment with a positive net effect.  I would consider incapability to handle one such person in a team as either a management or an ethical failure.

Just take a look around.  Both PhD and college graduates, good or mediocre programmers have problems with communicating their thoughts.  But a lot of what we call "communication problems" arise from the inefficiency of development processes.  If a person has to "communicate" (i.e. "chat") with his peers a lot to make the development of the softwarerocess progress without failures, then there's something wrong with the process.

Efficient communication is not an eloquent blah-blah-blah or an ability to make a small talk easily. It's conveying information to others in a precise and concise manner.  How well a person pronounces words is not the most important part in it; more important is how well he or she thinks.

Moreover, I'm sure that a person with a speech impairment knows the price of each word, and wouldn't toss up a lot of them.  Isn't it what they call "communication skills"?

No, I can't actually give you any advice (edited).  Personally, I would prefer a badly speaking peer to a less clever one, because I'm sure that an effort into setting up a way to communicate with less words would pay the team back.  But I never had to make a hiring decision in my life, and the world may be just unnecessarily harsh sometimes...

Title: Is programming a profession not for a person with speech impairment?

Body:
My friend has 15 years of programming experience and Ph.D. in mathematics. He has also cerebral palsy with speech impairment. Because of his handicap, he chose to being a software developer after his Ph.D. As far as I can see, he is still an excellent c# developer.

Nowadays, however, he has hard time to find a job for himself because most of developer jobs require good communication skills. Looking at him struggling so much, do I have to advise him software industry is not suitable for him any more? It will be extremely difficult for me to do that to the friend but I think it would be better than making him wasting his time.

What do you think?

Update: Thanks a lot for your excellent answers. I can see most answers recommend against my advice and I really really hope you guys are right. In reality, however, he has been rejected in 100 or so phone interviews. That's where I want to be a potential bad adviser rather than a politically right friend.


答:
In your case, it seems the best time to "optimize" depends on what you're doing.

If your code is very modular, fiddling with it later may not be very annoying, so it might be better to "optimize" later. If you depend a lot on your database schema, then fiddling with your database schema later may be annoying, so it may be better to "optimize" earlier.

("Optimize" is in quotes because I'm not so sure of what you mean by "optimize".)


答:
I don't see any issue with lack of communication skills coming in way of a good programmer. Though, it adds value but it's not the sole criteria. If he is uncomfortable, he can state this is in his interview and ask for a job where he is not required to confront the client.

Federico idea of working as an independent developer is also good. He can visit sites like odesk , Elance and make a good out of it.

As far as i know Bill Gates was not at confronting people in early years either and still lacks bit of magic for words. But, still he is the first name that comes to our mind when we talk about computer. John Nash  is another example. The point is that you can't make these small things rule your life.

A good programmer is made out of passion. You can't ask him to leave his passion and do other things. Suggest him the ways to lesser the fear of communication but don't ask him to quit because he won't succeed in other fields.


答:
I am going to make the assumption that your friend does not have a lack of communication skills. Instead he has a lack of communication capability. This shouldn't be a problem in the field of software programming since there are many alternatives to spoken word communication from email and chat to pictures and diagrams. If your friend has the skills and knowledgeto perform the task then his slightly limited communications options should not be a hindrance.

Any company or client that uses such an excuse is looking for a reason in the first place and has questionable practices in my opinion.


答:
See Truck Number aka Bus Factor

bus factor (also known as truck factor, or bus/truck number) is a measurement of the concentration of information in individual team members. The bus factor is the total number of key developers who would need to be incapacitated (as by getting hit by a bus/truck) to send the project into such disarray that it would not be able to proceed; the project would retain information (such as source code) with which no remaining team member is familiar. A high bus factor means that many developers would need to be removed before the project would necessarily fail.

"Getting hit by a bus" could take many different forms. This could be a person taking a new job, having a baby, changing their lifestyle or life status, or literally getting hit by a bus: the effect would be the same...