答:
Here's how I do it:

First I ask the candidate to solve a realistic problem.  Usually this is a problem I can solve easily; usually in a lot less than the alloted time.

Once the candidate is done; I become the student.  I have the candidate talk and point through their solution and show me how they solved it.  I ask questions about their ideas, and if they know of alternative solutions, and why they chose this solution over that.

Here's what I'm looking for.

Just because I happen to know a good solution to the problem doesn't mean I'm looking for that solution.  Any valid solution within the initial constraints is acceptable.  I'm interested in how they planned their solution, how they used the provided tools.  I'm interested in what shortcomings they are able to identify in their own solutions.

I'm also interested in how well they listen and communicate.  Were they able to understand and implement all of the initial requirements?  How well did they explain the way their solution works?

At the end of all this, once I've got a good idea what the candidate is actually bringing to the opening, I might offer some of the points from my own solution, where I think my choices would be better.

If the candidate says something like "That's a good idea, I wish I thought of that," or "Oh, I didn't know about that technique," or even "I thought of that, but I used this instead" and supplies a sensible reason like "I understand this method better" or "I thought you were looking for this kind of solution", these all count strongly in favor of the candidate.

If it turns out the candidate chose differently from me, It might mean that I am wrong.  Or if I am right, and the candidate is open enough to discuss the differences in solutions, it's a good sign that the candidate can be nudged quite easily to make better choices.

Here's How I know a candidate is a poor choice:

the candidate tries to fish for an expected solution from the interviewer.

the provided solution doesn't solve the stated problem, or somehow violates some of the stated constraints in a way the candidate cannot explain away.

the candidate argues with the constraints to try to change the problem he's expected to solve (remember that this is a problem for which I have a solution that can be implemented in much less time than alloted).

the candidate gets "stuck", and spends much of the allotted time doing nothing.  Ideally a candidate would attack the problem from another angle or seek the interviewer to know what he should do when he cannot proceed.

the candidate doesn't know "why" he used a technique, even if he doesn't know of alternatives.  Answers like "I don't know any other tool that does this" or "I don't know how this tool works, but it does" are fine, but "because I did" are questionable.


问:
What is a reasonable and secure password requirement for user registration?
This is the password policy I just got from UPS (just for package status checking):

Your password must be between 8 and 26 characters long. It must
  contain at least three of the following character types: lowercase
  letters, capital letters, numerals, special characters, or spaces. The
  password may not contain your User ID, your name, or your e-mail
  address. (SSO_1007)

I actually have to wrack my brain somewhat to generate this password, but not only that, most importantly, I am sure that after 3 days I will forget what this password is.  Users won't be so happy.  Password reset can be frequent.  I think users will try to avoid using the site unless they have to.

What is a reasonable and secure password policy when setting up a website?   I think some companies may fear some hackers trying passwords a million times or more, so they add all those requirements for "special characters, lower case, upper case", but won't it be reasonable to turn off the account or just disable the password and require a password reset if a user has tried 30 times or 100 times?  Or, add a 5 second delay each time after the user tried 30 times?  If so, then those special characters won't be that much needed.

答:
Reasonable and Secure are mutually exclusive.  They are two ends of a rod.  Striking a balance in the middle will be best.  To far towards secure and people write down the passwords or use the totally un-secure password unlock feature.

The above example does appear to be leaning more towards secure than reasonable. I have seen worse.

I prefer leaning towards the reasonable.  The key is to lean towards the secure in your back-end.  Store as little as possible use salts etc.  All the latest recommended methods for encoding the passwords into your database and encoding them one way as well.  Then keep your database and your code secure.  Also train anyone that has admin rights to your system that they need to use a unique secure password.  It was shown recently that stringing together multiple dictionary words is more secure than dragging in special characters and case.  It required compound dictionary matches which really add up time wise for hackers, however, these were still memorable for users.

ContentLicense: CC BY-SA 3.0


问:
As an iOS developer, what type of technical interview questions should you be prepared with?
I just finished a technical interview yesterday and the interviewer asked about graph theory, data structure, and traversals. This has nothing to do with iOS stuff. So I came un-prepared. This was actually for a social mobile gaming company, is this the reason why they ask these kind of stuff instead of iOS stuff? Now it seems to me that I am just overwhelmed by the materials to review and study for future interviews, I have to review the whole data structure/traversal/searching algorithm and at the same time iOS/objective-C fundamentals as well. Can someone guide me on how to prepare? Is my past experience just a special case as it was a gaming company?</p>

答:
Oftentimes employers don't really want "iOS developers", "unix developers" or any other sort of potential one-trick-pony.  They'll be looking for good all-rounders who have a firm grasp of the basic concepts such as those you were asked about.

Usually, such talented developers have little difficulty turning their hand to any specific technology that comes their way.


问:
Is Systems Hungarian notation still a useful practice?
I searched the forum, but I couldn't find the answers why it should be avoided, only why it's not a silver bullet. So I don't think this question is a duplicate.

Is there a VALID reason why I should unlearn Systems Hungarian I'm used to?

So far I see the following benefits in using it:

Consistent variable naming

You see type without searching (intellisense is dead/indexing half of the time, so it's still a valid reason)

Semantics can still be packed into second part of the name

And following downsides:

It annoys some people (no idea why)

If type is changed, the type might not match the naming of the variable (I don't think it's valid reason, types are changed rarely, and you have "rename all")

So why:

```<code>vector<string> vecCityNames;
wstring strCity = L"abc";
//more code here
vecCityNames.push_back(strCity);
</code>```

is worse than:

```<code>vector<string> cityNames;
wstring city = L"abc";
//more code here
cityNames.push_back(city);//Are we pushing back int on a queue? Float on a stack? Something else?
</code>```

答:
I strongly dislike the form of Hungarian notation you describe. The Reason? It serves no point 90% of the time.

For instance, a bit of (equivalent C++. actually written in Delphi) code from a legacy project I'm forced to endure:

```<code>pRecords[0]->FooMember=10;
</code>```

...
pRecord is a variable, it's of type TRecordList. TRecordList *pRecords[10];

It's a class consisting of a orioerty named FooMember that points to fFooMember... or mFooMember depending on if it's a "field" or a "member" (hint: they're the same thing)

Problems? fFooMember could be something like FooMember_ because we will always access it through the FooMember public property. pRecords? It's pretty obvious it's a pointer from the fact that you dereference it all over the place. TRecordList? When can you possibly confuse a type name and an object of that type? The compiler will yell at you, and types are used in almost no places that objects are (except for static properties/methods)

Now, there is one place where I do use hungarian notation. This is when dealing with lots of UI variables that would have the same name as other UI variables or regular variables.

For instance, if I had a form for your First Name on it.

I'd have a class named FirstNameForm. Within it, lblFirstName and txtFirstName for the label and textbox respectively. And a public FirstName property for getting and setting the name in the text box.

This could also be solved by using FirstNameLabel and FirstNameTextBox but I find it gets long to type. Especially with something like GenderDropDownList and such.

So basically, hungarian notation is, at best, annoying at the systematic level and Worst case harmful (as the other answers give about problems with refactoring and consistency).

Body:
I strongly dislike the form of Hungarian notation you describe. The Reason? It serves no point 90% of the time.

For instance, a bit of (equivalent C++. actually written in Delphi) code from a legacy project I'm forced to endure:

pRecords[0]->FooMember=10;

...
pRecord is a variable, it's of type TRecordList. TRecordList *pRecords[10];

It's a class consisting of a orioerty named FooMember that points to fFooMember... or mFooMember depending on if it's a "field" or a "member" (hint: they're the same thing)

Problems? fFooMember could be something like FooMember_ because we will always access it through the FooMember public property. pRecords? It's pretty obvious it's a pointer from the fact that you dereference it all over the place. TRecordList? When can you possibly confuse a type name and an object of that type? The compiler will yell at you, and types are used in almost no places that objects are (except for static properties/methods)

Now, there is one place where I do use hungarian notation. This is when dealing with lots of UI variables that would have the same name as other UI variables or regular variables.

For instance, if I had a form for your First Name on it.

I'd have a class named FirstNameForm. Within it, lblFirstName and txtFirstName for the label and textbox respectively. And a public FirstName property for getting and setting the name in the text box.

This could also be solved by using FirstNameLabel and FirstNameTextBox but I find it gets long to type. Especially with something like GenderDropDownList and such.

So basically, hungarian notation is, at best, annoying at the systematic level and Worst case harmful (as the other answers give about problems with refactoring and consistency).


问:
What is the acceptable failure rate for software?
Say I produce some software with a genetic algorithm. In order to be certain that the software works correctly in all situations, I would need to test all situations, which could be prohibitively (or infinitely) many. So I evolve the software with evolving test input (some fixed, some inherited, and some random). Now, with each generation, the probability measurably increases that the fittest functions will be general solutions, not just solutions for the known data at hand.

As developers, we are flawed, and our software may fail, in fact quite often. Generally speaking, we have no idea of the probability of failure at any given point, though we may be able to discern specific cases in which the software will fail. All we can do to reduce the failure rate is test thoroughly and practice good software development. But logically, we distribute flawed software all the time.

Would it make you uncomfortable as a developer to know how often your software might fail, but to know nothing about the specific cases in which it might? What failure rate is acceptable? 0.01%? 0.0001%? Would you hold a genetic algorithm to a higher standard than a human when it comes to failure rates?

答:
It really comes down to the application.

If the software is controlling a nuclear reactor or an aircraft in flight then the acceptable rate is 0.0%

If the software is providing user comments on a free site with no ad revenue then the lost opportunity cost of failure is pretty close to zero so you could probably tolerate a reasonably high chance - say 5%-10%, and test the specific use-cases which are valuable.

The scary phrase from my (typically embedded) point of view is

...know nothing about the specific cases in which it might [go wrong]

I, perhaps over optimistically, hope that most developers put more design, implementation and test effort into the subjectively important areas of the software.

Say you are designing software for a vending machine.  If the 0.1% fault you deem acceptable occurs in the code which decides in which pattern to flash the LEDs when the machine is idle - it's a fancy machine - then I doubt you would even bother with a field change.
If on the other hand the fault occurs in the code which decides how much change or how much chocolate to provide then you have a much bigger problem.


答:
I'm not sure why it matters if your software is written by a developer or a genetic algorithm.

Somewhere there should be a Requirements document explaining acceptable inputs to the program and the expected outputs for said inputs. You can write unit tests to test small units of the program and business logic. You can have QA testers use the program and execute more complex tests. You should strive for a 0% failure rate within the constraints of the Requirements. Sometimes a client will accept a program with a low failure rate in some situations if they feel it does not matter enough to warrant the extra cost to fix the problem.

Your program does not need to account for every concievable scenario under the sun, only ever concievable scenario as described by the Business Users/Clients/whatever... And if they start having broad requirements that encompas everything under the sun, then you ask them to refine them. There's not much else to say, I think, unless you can give specifics about your situation.

Title: What is the acceptable failure rate for software?

Body:
Say I produce some software with a genetic algorithm. In order to be certain that the software works correctly in all situations, I would need to test all situations, which could be prohibitively (or infinitely) many. So I evolve the software with evolving test input (some fixed, some inherited, and some random). Now, with each generation, the probability measurably increases that the fittest functions will be general solutions, not just solutions for the known data at hand.

As developers, we are flawed, and our software may fail, in fact quite often. Generally speaking, we have no idea of the probability of failure at any given point, though we may be able to discern specific cases in which the software will fail. All we can do to reduce the failure rate is test thoroughly and practice good software development. But logically, we distribute flawed software all the time.

Would it make you uncomfortable as a developer to know how often your software might fail, but to know nothing about the specific cases in which it might? What failure rate is acceptable? 0.01%? 0.0001%? Would you hold a genetic algorithm to a higher standard than a human when it comes to failure rates?


问:
Is it a good practice to code in English?

Possible Duplicate:

  Do people in non-English-speaking countries code in English?

I have a development comming that is intended to be sold across Latin America (Spanish speakers), but I've heard from some partners that is a good practice to always code in English, I mean just code (methods, classes, pages names, etc), labels on GUI are going to be all in Spanish...

Code will be edited in the future by developer of companies across Latin America and just maybe some from outside.

What do you think?, any experience with this?

答:
I'm French and working in a French company.

However, we do code mostly in English. Here is why:

We sometimes have non-French people working with us so it's easier for them.

We have some code coming from third parties (lib, framework, etc.), and this code is often in English, so we don't want to end up with a patchwork of French-English code.

Generally speaking, this is not a problem because you have to understand English anyway if you want to be a good programmer.


答:
In most programming languages the keywords are in English, so it generally looks a bit forced if you mix languages.

For this reason, as well as developer numbers, English tends to be the language used in most developments, even developments by companies based in non-English speaking countries.

Title: Is it a good practice to code in English?

Body:
Possible Duplicate:

  Do people in non-English-speaking countries code in English?

I have a development comming that is intended to be sold across Latin America (Spanish speakers), but I've heard from some partners that is a good practice to always code in English, I mean just code (methods, classes, pages names, etc), labels on GUI are going to be all in Spanish...

Code will be edited in the future by developer of companies across Latin America and just maybe some from outside.

What do you think?, any experience with this?


答:
Secure vs. Convenient

The security policy of a password should be appropriate for the cost of compromise.  If your website fronts my financial account I would like stringent password protection. If it is a niche fan site about Autobots, you don't need very much protection.

The UPS rules are reasonable with the exception of:

The maximum length is way too small.  You should facilitate the use of passphrases which are easier to remember and can be more secure.

I didn't see the reset after X number of tries in the quoted rules, I think this is silly in most cases.  I think your better off locking someone out for a period of time, rather than forcing a reset.  This implies a certain level of security.  If that isn't necessary, then it's not and locking/resetting is a moot point.

There are many password policy rules that having marginal security benefits at best.  However, there are also rules that do have real, tangible benefits to the security of your password.

Rules (and the reasons):

minimum length

Prevents a combinatorial trial and error attack which will quickly break very short password.

proscription against using a single English word (or any other language)

This prevents dictionary attacks.

forced inclusion of different categories (ie. mixed case, numbers, punctuation)

This increases average attack space.

All these reasons can be traced to minimizing the user's bias in choosing passwords.  Most users are biased towards creating shorter, easy to remember passwords.  Unfortunately that usually makes the password easier to attack.  What most users need are instructions on how to create secure memorable passwords or a longer passphrase.

Secure Memorable Passwords

When I need to create a password with a length limit I always start with a phrase so I have a built in mnemonic.  I take the phrase and I get the same positional character from each word.  I now have a sequence of just characters.  I then choose capitalization, some based on proper names in the phrase, or by pattern (first and last, every other letter, etc).  I then add in punctuation and numbers based on some arbitrary rule or pattern.  (ie. all 'j's are 7, using '&' where there is an 'and' in the phrase, etc).

Mama, just killed a man. Put a gun against his head. Pulled my trigger, now he's dead.

Phrase provided by Queen

mjkampagahhpmtnhd - first letter of every word

MjkamPagahhPmtnhd - casing matches casing of phrase

Mjk0mP0g0hhPmtnhd - changed 'a' to 0

Mjk0mP0g0()Pmtnhd - changed 'his head' to ()

After I type it a few times when thinking the phrase I'll never have a problem remembering.

Title: What is a reasonable and secure password requirement for user registration?

Body:
This is the password policy I just got from UPS (just for package status checking):

Your password must be between 8 and 26 characters long. It must
  contain at least three of the following character types: lowercase
  letters, capital letters, numerals, special characters, or spaces. The
  password may not contain your User ID, your name, or your e-mail
  address. (SSO_1007)

I actually have to wrack my brain somewhat to generate this password, but not only that, most importantly, I am sure that after 3 days I will forget what this password is.  Users won't be so happy.  Password reset can be frequent.  I think users will try to avoid using the site unless they have to.

What is a reasonable and secure password policy when setting up a website?   I think some companies may fear some hackers trying passwords a million times or more, so they add all those requirements for "special characters, lower case, upper case", but won't it be reasonable to turn off the account or just disable the password and require a password reset if a user has tried 30 times or 100 times?  Or, add a 5 second delay each time after the user tried 30 times?  If so, then those special characters won't be that much needed.


答:
It annoys some people (no idea why)

The reason it annoys me is that it's a little speed bump on every single identifier that slows down my visual scanning of the code. sIt's mAs bIf pYou kHad zTo qRead iEnglish cText lLike uThis.

Title: Is Systems Hungarian notation still a useful practice?

Body:
I searched the forum, but I couldn't find the answers why it should be avoided, only why it's not a silver bullet. So I don't think this question is a duplicate.

Is there a VALID reason why I should unlearn Systems Hungarian I'm used to?

So far I see the following benefits in using it:

Consistent variable naming

You see type without searching (intellisense is dead/indexing half of the time, so it's still a valid reason)

Semantics can still be packed into second part of the name

And following downsides:

It annoys some people (no idea why)

If type is changed, the type might not match the naming of the variable (I don't think it's valid reason, types are changed rarely, and you have "rename all")

So why:

```<code>vector<string> vecCityNames;
wstring strCity = L"abc";
//more code here
vecCityNames.push_back(strCity);
</code>```

is worse than:

```<code>vector<string> cityNames;
wstring city = L"abc";
//more code here
cityNames.push_back(city);//Are we pushing back int on a queue? Float on a stack? Something else?
</code>```


答:
My opinion is that passwords should have only a length requirement. You don't want someone putting in "a" as their password. And as the xkcd answer shows, an extremely difficult to remember password isn't always that secure. Always allow people to change their password as well. And forget about the "you can't use any of the characters contained in your previous password" crap.

Making an obscene password policy will do more harm than good. At the college I went to the password policy was similar to the UPS policy AND you had to change it every 2 weeks AND you couldn't use the previous 50 passwords you used. So, what my teachers recommended when setting us up accounts is to use our regular password that conforms to the rules and add a counter to the end of it and put in your password hint what the counter number is.

Also, a strict password policy won't do anything whenever your plain text database gets hacked by a SQL injection bug... or you email passwords to your users and it gets intercepted..

Basically, don't make your password system a hassle for your users or it will encourage them to do insecure things so that they can work around it. For instance, my company when getting a dedicated server from a data center, they set us up passwords that were 20 characters long. They were too secure to be emailed to us and had to be faxed. We couldn't change the passwords, only request for a new 20 character password to be generated. And it was this way for every user... so what we ended up doing is just making a text document on our desktops with the password. Also, we don't use them anymore because for all the "security" they had, they were really quite insecure.


答:
In general, as said in other answers: Programming languages use English keywords, and when a project becomes larger, you might get foreign people working on the code. Additionally, concepts like "getters" and "setters" or instance in languages like Java are commonly called getFoo or setFoo and it makes sense to keep this convention.

On the other hand, you might create an application for a specific target market. I, for instance, was working for a large bank developing balance analysis software where we had German financial and legal language. In the end, we decided to use German identifiers to keep the exact terms as the English terms sometimes had a slightly different meaning; on the other side, we kept the convention to use English in other places, so we had functions like getUmlaufvermoegen() (instead of getCurrentAssets()) which looks "funny" but proved to work well, as we could easily go through the calculations together with the experts from the bank who defined the calculations we did but was consistent with frameworks etc. we used.

ContentLicense: CC BY-SA 4.0


问:
Do technical interviews tend to be subjective?
Based on my experience in technical interviews, I have found that most tend to be subjective because the interviewer already has his own answer. Even though the answer from the candidate is correct, because the interviewer was not prepared for that answer, the candidate does not get the job.

In an interview recently I said something about using an AVL tree algorithm to solve a specific problem that was asked. The interviewer responded: "What's an AVL tree?". Another example is anything around syntax; I've encountered this mostly in interviews that require Ruby code because there are many ways to implement a solution to a given problem. A very common ones is problems around Object Oriented designs.

In this situation, there's no way for the interviewee to succeed. Has anybody else felt this way too or is it just me? If it's not just me, how can we make technical interviews better?

答:
A very important skill when you work in a team is to be able to justify your own solution and fairly evaluate someone else's.  You need to be able to both learn from your colleagues and teach them.

If you want to use an AVL tree to solve a problem, and the other members of your team remember them vaguely from college and haven't thought about it since, you had better be able to explain its advantages to them.  If someone presents a solution you don't understand, you had better be willing to ask questions until you do.  If someone presents a clearly inferior solution, you had better be able to articulate why.  If someone presents a superior solution, you had better be able to recognize that and set your ego aside.

Those are the skills I look for when I ask a technical question at an interview.  Whether they came up with the "correct" answer off the top of their head is largely irrelevant.  That's only important in school.


答:
Your password must be between 8 and 26 characters long

The minimum password being 8 characters long is a legacy of Lan Manager. Lan Manager hashed passwords by breaking them up into 2 7-character strings, then hashed them. By requiring 8 chars minimum, they guaranteed that the 2nd word was not the same as for a blank password (there was no salt, so every instance of 7 blanks hashed to the same result).

I am sure that after 3 days I will forget what this password is.

I've given up, the rules are so silly and rediculous that I write them down now. All except the few I use for websites. My current employer also keeps track of the past 24 passwords used so that they cannot be recycled, nor can the password contain any 3+ character English word (forwards or backwards). It also makes sure you don't use a previous word and increment some number as part of it (so if P4ssw0rd1 were used, you could not use P4ssw0rd2, nor P4ssw0rd0).

I learned my lesson the hard way at the office when I had to change a password, it took 45 minutes to get the system to accept a replacement, then promptly forgot what I had come up with and had to get it reset and wasted another 45 minutes trying to get something I could remember that was complex enough to meet the requirements (some of the requirements are listed above, some aren't, and some I don't know). It is not a lot of fun trying to come up with something that meets rules you aren't allowed to know. At least with games like Mastermind you are given clues as to how close you get. At the office, some folks get to use a smart card, I'm not one of them.


答:
Do you think that, as an interviewee, your acceptance of a job is not subjective, to a certain extent?  Recruitment is a two way process.

As an interviewer, if I and my colleagues “click” with a candidate, they have a good chance of being in the running for the job, assuming that other factors such as a home-coding exercise and whiteboard problems go well.  To “click” is to be on my wavelength, to have a fruitful conversation, to share common values about the development process. How objective can this be?

On the question of the AVL tree I would be interested in the candidate’s explaining how it works and providing insights into properties and use.  To do better than the explanation on Wikipedia.  Bear in mind your audience may be someone in a corporate enterprise environment where the last reference to O(log n) in a technical discussion was basically... never.

As an interviewer I want to give a candidate every opportunity to shine.  I imagine this would apply to any organisation you would want to work for.

Title: Do technical interviews tend to be subjective?

Body:
Based on my experience in technical interviews, I have found that most tend to be subjective because the interviewer already has his own answer. Even though the answer from the candidate is correct, because the interviewer was not prepared for that answer, the candidate does not get the job.

In an interview recently I said something about using an AVL tree algorithm to solve a specific problem that was asked. The interviewer responded: "What's an AVL tree?". Another example is anything around syntax; I've encountered this mostly in interviews that require Ruby code because there are many ways to implement a solution to a given problem. A very common ones is problems around Object Oriented designs.

In this situation, there's no way for the interviewee to succeed. Has anybody else felt this way too or is it just me? If it's not just me, how can we make technical interviews better?


答:
I live in Colombia and we are taught to write our code in english for the sake of universality, most of the good programmers know the 2 languages anyway because its necessary and because almost all good documentation and reference is writen in english;

So i think is safe to write your code in english its very likely that they are going to understand and it is a good practice.


问:
What's the difference between syntax and semantics?
I've always thought that referring to the syntax of a language was the same as referring to the semantics of a language. But I've been informed that apparently that's not the case. What's the difference?</p>

答:
Very short example with "plain c":

```<code>void main()
{
  int a = 10;
  int x = a - 1;
  int y = - 1;

  printf("x = %i", x);
  printf("y = %i", y);
    getch();
}
</code>```

In this example, the syntax for the "-" token is the same,
but, it has a different meaning ("semantic), depending where its used.

In the "x" assignament, "-" means the "substraction" operation,
In the "y" assignament, "-" means the "negative sign" operation.

Body:
Very short example with "plain c":

void main()
{
  int a = 10;
  int x = a - 1;
  int y = - 1;

  printf("x = %i", x);
  printf("y = %i", y);
    getch();
}

In this example, the syntax for the "-" token is the same,
but, it has a different meaning ("semantic), depending where its used.

In the "x" assignament, "-" means the "substraction" operation,
In the "y" assignament, "-" means the "negative sign" operation.


问:
How much data should be required in a request to a webservice?
When recieving data from clients how much data that you provided to them should you require back from them?

For example when clients order a product from a webservice should they just need to provide a product code? The other alternative would be to require the product code product name and product price ect.

I have alway built webservices the former way with the minimum of data returned back to me, however I have just been consuming another web service that requires the vast majority of the data returned back to them. What are the advantages of the second way?

答:
It seems logical that if you send data to the client, then you only need a smal amount of data back rather than the full population.  However, there may be cases where an interface is treated as a save operation that can do both updates and inserts.  An insert will usually require the entire population is nothing is sent to the client and there are no pre-defined default values.

Some developers try to reduce the number of interfaces because fewer interfaces means fewer points of failure and reduced maintenance cost.  Although it does make things a little more difficult on the client side.

However, with that said, if performance or bandwith is an issue then you should try to minimize the amount of information passed between client and server.

This is a typical performance/simplicity trade-off that developers struggle with.


问:
What do you consider to be the prime cause of software defects (and how to minimize them)
I define defect as :

"something within the application design or code which prevents it functioning as per requirements."

I'm looking for ideas about the causes of defects, eg the human factor, lack of testing, lack of prototyping, and possible ideas to mitigate these.

答:
It's because software engineering is inherently complex.  The essay "No Silver Bullet" discusses this.

Ironically, many of the other answers here touch on topics that are "accidentally complex", in the language of that essay, whereas in reality most of what software developers do is "essentially complex", so it's just in the nature of it that creating software is difficult, software will have bugs, and our job is to deal with it.

ContentLicense: CC BY-SA 2.5


问:
At a higher level description, how is DLMALLOC supposed work?
There doesn't seem to be that many good descriptions that go into the specifics about how dlmalloc works. The sources I have come across so far mention dlmalloc, but then only goes on to explain what malloc() and free() are, rather than describing dlmalloc.

The Wikipedia description, on the other hand, was a bit hard for me to understand.
http://en.wikipedia.org/wiki/Malloc#dlmalloc_and_its_derivatives

Can anyone explain the workings of dlmalloc, how to implement it, and any additional sources that could help?

答:
If you ever don't understand an implementation you should check the source, if available. Here's a fairly extensive explanation which was mentioned in the source.

Can anyone explain the workings of dlmalloc, how to implement it, and any additional sources that could help?

If you want to use dlmalloc then download the source. Creating your own version of malloc is going to be very difficult and will take you days reading to understand dlmalloc's source.

If you want to learn how dynamic memory works then I suggest you create a memory pool/allocator which will teach you everything you need to know. All you need to do is allocate a large buffer and create functions which allocate/free parts of that buffer.


问:
Is there any merit to using `union` to create an alias?
I've inherited a bit of code and saw something new. They have a data structure definition out in a .h file, and in various local files they'll declare:

```<code>union globalStructOstuff localVar;
</code>```

Is there any merit to this?

I could see some if the global was some placeholder and the local versions were going to be different eventually.  But that's not the case here.

So I think all it's doing is causing new guys a couple of extra minutes searching for definitions. I'd axe it once I got the chance, but I wanted to see if I'm missing some greater purpose.

Edit, resolution

With your fine help, I managed to open my eyes and realize globalStructOstuff isn't a struct at all, it's a union which holds the struct of a similar name. And they didn't use typedef. So all that's happening here is declaring a local variable. It has a type of union. No alias to anything global.  Sorry for the confusion, thanks for all your help.

答: Some IDE's have a panel or window that lists classes, structs, etc. and their members for quick reference.  Possibly, declaring a union in this case serves no purpose other than to make the variable show up in such a list, or to change how or where it's listed by some documentation tool.  Otherwise it seems pointless, but then people do strange things for reasons only they know sometimes. </p>


问:
Why coffeescript instead of javascript?
I think somehow building a language which compiles to another language feels like a bad idea from the start, instead of learning javascript properly from the start. Look into Douglas Crockfords Good Parts and then are you hooked.
And javascript is not hard - writing good code is hard regardless of language! If you write crappy code in javascript, then you propably will write crappy code in coffeescript or lattescript or what the flavor will be of the day.
And to say that coffeescript syntax is beautiful passes me. I like my curly braces and C syntax - and would preferably work in a language which is like that (sorry VB!).
And more toys and languages and frameworks for doing the same thing all over again feels not like progress to me anymore! </p>

答:
I think the benefit (disclaimer: I have not used CoffeeScript beyond playing with the example on the website) is that it makes JavaScript a little more intuitive for the crowd it's catering to: i.e. the Ruby/Python people.

I personally don't see a need for CoffeeScript, as I like the JavaScript syntax.  However, I see how it could be useful.

Title: Why coffeescript instead of javascript?


问:
Do I need to Clean/Rebuild a project before Debugging/Publishing it in Visual Studio?
This is probably a stupid question, but do I need to Clean/Rebuild before Debugging or Publishing a Visual Studio project?

I see other developers doing it all the time, and at some point I started doing it without even thinking. It seems habit to always go Clean, wait, Rebuild, wait, Publish.

I know I didn't always do it.... I think I started to do it after spending a bunch of time debugging an error, only to discover it went away when I Cleaned and Rebuilt the solution. I've had this issue more than once too, so I know it wasn't a one-time thing, but it seems like a huge waste of time to always be cleaning/rebuilding your projects.

答:
You don't have to, but I find that Visual Studio sometimes looses track of what assemblies were built when. When that happens, you end up with stale assemblies and a bad debugging experience (when the code and symbols don't match).

As result, I simply do a re-build every time (this does a Clean + Build). This way, I don't rely on Visual Studio's hit and miss ;)


答:
Cleaning and rebuilding is just an easy way to cleanup any errant assemblies, resources or other assets that may have accumulated from previous builds.  It also helps to keep the assemblies in a consistent state, because Visual Studio sometimes gets confused about what it's actually referencing.

In our shop, we do it the same way, but I'm pretty sure a rebuild would work just fine as well.

Title: Do I need to Clean/Rebuild a project before Debugging/Publishing it in Visual Studio?

Body:
This is probably a stupid question, but do I need to Clean/Rebuild before Debugging or Publishing a Visual Studio project?

I see other developers doing it all the time, and at some point I started doing it without even thinking. It seems habit to always go Clean, wait, Rebuild, wait, Publish.

I know I didn't always do it.... I think I started to do it after spending a bunch of time debugging an error, only to discover it went away when I Cleaned and Rebuilt the solution. I've had this issue more than once too, so I know it wasn't a one-time thing, but it seems like a huge waste of time to always be cleaning/rebuilding your projects.


答: Whether you like the syntax or not is subjective, however the fact is that CofeeScript takes care of some annoying JavaScript warts. Of course, it still remains unclear if it is worth introducing a new language and coping with the compilation step.</p>

Title: Why coffeescript instead of javascript?

Body:
I think somehow building a language which compiles to another language feels like a bad idea from the start, instead of learning javascript properly from the start. Look into Douglas Crockfords Good Parts and then are you hooked.
And javascript is not hard - writing good code is hard regardless of language! If you write crappy code in javascript, then you propably will write crappy code in coffeescript or lattescript or what the flavor will be of the day.
And to say that coffeescript syntax is beautiful passes me. I like my curly braces and C syntax - and would preferably work in a language which is like that (sorry VB!).
And more toys and languages and frameworks for doing the same thing all over again feels not like progress to me anymore! </p>


答:
There is a misconception of JavaScript as a "toy" language. This causes people to regard it as something to be played with, rather than used for anything substantial. Add that to the low barrier for entry (i.e. you already have a browser and a text editor, so you can start writing JavaScript), and you end up with masses of people who don't understand the language writing mass amounts of code, and sullying the name "JavaScript".

There is a higher (absolute) amount of bad JS than other languages because of that increased visibility. Bad habits become commonplace as the bad code propagates throughout the web and people view source on pages that have not been vetted for accuracy or good practice, and JavaScript ends up with a bad name because of it.

For these reasons, people feel the need to build more familiar (more "real") languages that transpile to JavaScript. They want the comfort of classical OO, static typing, and other features that appear in other languages. They see the monstrosities created by inexperienced programmers using JS, and think it must be a result of the "fundamental flaws" (to quote Google) in the language.

</rant>

Anyway, use what you want. I'll stick with my object literals, dynamic typing, and prototypal OO, thanks.

Title: Why coffeescript instead of javascript?


答:
CoffeeScript is mostly a different syntax on top of JavaScript.

If you understand JavaScript and truly understand JavaScript, then your allowed to use CoffeeScript if you say, prefer whitespace and ->

I consider the difference between JS & CS to be the same as arguing about

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

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

(the latter is better. Anyone who does the former should get shot).

Anyway, the main issue with coffeescript is having people come into it (mainly from rails) and then write coffeescript without knowing javascript.

Therefore coffeescript has all the same flaws as jQuery. They are just more entry points for bad programmers to write more bad JavaScript. We really need to solve code quality somehow.

Title: Why coffeescript instead of javascript?

Body:
CoffeeScript is mostly a different syntax on top of JavaScript.

If you understand JavaScript and truly understand JavaScript, then your allowed to use CoffeeScript if you say, prefer whitespace and ->

I consider the difference between JS & CS to be the same as arguing about

if (thing)
{
  // code
}

if (thing) {
  // code
}

(the latter is better. Anyone who does the former should get shot).

Anyway, the main issue with coffeescript is having people come into it (mainly from rails) and then write coffeescript without knowing javascript.

Therefore coffeescript has all the same flaws as jQuery. They are just more entry points for bad programmers to write more bad JavaScript. We really need to solve code quality somehow.


答:
It is not "required," but you might want to do the Clean+Build before a major release and/or after you get files from other resources.

VS sometimes fails to identify the modified files and thus bypasses the necessary re-compilation. In my case, this usually happens when the files are updated via some overwriting behavior (e.g., downloading from SCM, copy/paste from the colleague's directory). The problem is probably the date of the file. If the new file has a modified date (or created date, I don't know which timestamp VC references to) older than that in VS's record, VS will not recompile the corresponding file.

My recommendation is: if you are compiling for the updates made only by you locally on the same machine, you should be okay by building without cleaning.


问:
How can I change sloppy company culture?
Sometimes when I have a problem that needs to be solved, I find that the easiest way to solve it is by writing a small program as a personal tool. I don't make it super usable or super robust, as I am the only one going to use it, and I don't have the time to refine it and test it thoroughly.

Then a coworker sees the program and asks for it, because he has run into the same problem and the tool could help. I give him the "It's not pretty but it'll get the job done" disclaimer and let him have it.

Next thing I know, my superior is calling me, telling me that he's trying to get the software to work on a client's computer but it's showing X error message. WTF?? That software is not ready for release, nor was I told that it needed to be ready for release. But for some reason, my superior thought it was good enough and released it without telling the original developer.

Now, this particular problem is easy to fix with a MessageBox.Show("DO NOT GIVE TO CLIENTS!");. However the problem is indicative of a much deeper problem: our company culture is sloppy. Sloppy software is OK and sloppy processes are OK. Don't worry about the future - put just enough effort into getting it barely working now, put the binaries in a .zip file, and ship it. Good enough for government work.

This is a small company with 10 full-time employees, is growing, and has been around for a while. Don't get me wrong; I love working here and I love the company. Don't tell me to run; I want to be a part of making the company better. How do you start to bring good change to this kind of culture?

答:
The only way to change is to make everyone else see the downsides of a sloppy culture and, perhaps more importantly, have management buy-in to fix it.  In reality though, that doesn't happen and you won't be able to change it.  That might not be the answer that you were expecting to hear, but after five years or so of trying and failing at several jobs to change sloppy culture, I can say with some authority that it's usually not worth the effort to do.

The first step would be finding out if anyone else knows or cares about the sloppy culture; if you are the only person that sees any problems, your efforts are in vain.


答: You may need to have a sit-down with co-worker and boss and explain that you what you had was a prototype and wasn't ready for clients to use.  If they wanted it to be ready for clients to use, you could make those changes given enough time but please don't take the "quick and dirty" stuff and pass it along to customers.  Just because something works doesn't make it good being the lesson to learn.  While you gave a disclaimer there is something to be said for giving it some respect as otherwise this is what can happen.</p>

Title: How can I change sloppy company culture?

Body:
Sometimes when I have a problem that needs to be solved, I find that the easiest way to solve it is by writing a small program as a personal tool. I don't make it super usable or super robust, as I am the only one going to use it, and I don't have the time to refine it and test it thoroughly.

Then a coworker sees the program and asks for it, because he has run into the same problem and the tool could help. I give him the "It's not pretty but it'll get the job done" disclaimer and let him have it.

Next thing I know, my superior is calling me, telling me that he's trying to get the software to work on a client's computer but it's showing X error message. WTF?? That software is not ready for release, nor was I told that it needed to be ready for release. But for some reason, my superior thought it was good enough and released it without telling the original developer.

Now, this particular problem is easy to fix with a MessageBox.Show("DO NOT GIVE TO CLIENTS!");. However the problem is indicative of a much deeper problem: our company culture is sloppy. Sloppy software is OK and sloppy processes are OK. Don't worry about the future - put just enough effort into getting it barely working now, put the binaries in a .zip file, and ship it. Good enough for government work.

This is a small company with 10 full-time employees, is growing, and has been around for a while. Don't get me wrong; I love working here and I love the company. Don't tell me to run; I want to be a part of making the company better. How do you start to bring good change to this kind of culture?


问:
How can I inspire my group to start using an online collaborative tool more?
I'm in a project with 4 other people, and I've been willing to fully adopt a collaborative tool in order to make it possible to share information and store data (PDFs, DOCs, etc.) in an online tool, rather than doing it by e-mail. The problem is that I'm the only one enforcing it; actually I'm the only one using it. The others only use it when I ask them to do so.

How would you handle this? Have you experienced something similar, if so, what have you done?

答:
Keep plugging at it.

When asked where some documentation is, point them to the online resource. When emailing around, use links.

When writing new documentation put it directly online and point to it and only to it. Encourage the same behavior from others.

If something isn't online, ask why.

When it is time to update the documentation, tell your colleagues that it has been updated - perhaps point out that since it is online, they do not need to change their local copy (if they had one).

Help them discover the benefits, or they will never buy in to this way of doing things.


答:
The other day, a colleague told me a story of a simple test tool to allow an engineer in a lab to issue a single command to a widget, and change a variable that goes with the command. This was written 9 years ago now, and last he knew, it is still in use today. A tool that was written in a couple of hours with minimal testing to prove, in the lab, that something works, was the basis for an entire engineering laboratory test tool. Once you write code, it exists. If it does something useful and it's seen by other people, people are going to want it. If it's good at what it does, people are going to ask for it to do X. Next thing you know, your simple tool is a significant component.

I think the first responsibility is on the software developer to make sure that anyone who looks at the code or uses the tool understands that it's a prototype or not a production system and say why that's the case. It sounds like you did that, however your coworker(s) neglected to carry on that responsibility. In order to address this, I would recommend speaking to them, reiterating that this was not production code and was only written to facilitate your work. If they find it useful, perhaps offer to work on the tool or support other people working on the tool to enhance it and make it more suitable for production.

As far as organizational process or culture change, expect it to take a while. Start by setting an example. If you haven't read The Pragmatic Programmer, do so. Take note about tips such as Care About Your Craft, Be a Catalyst for Change (show people better ways), Don't Live With Broken Windows, Fix the Problem Not the Blame. It sounds like you recognize some problems addressed by these tips, so start working and living an example to your colleagues.


答:
Until decision makers no longer tollerate the consequences of the bad code and are willing to pay/change their ways to fix the problem.

These are difficult decisions for small and growing companies. They don't know where to put all their efforts. There is a risk making code too robust when business rules and sometimes entire lines of business appear, change, and disappear over-night.

Strive to write good code. Make sure you inform everyone of the consequences so they can make informed decisions. If bad code gets put into production, keep a close eye on it if you can and continue to suggest improving it especially if that part of the business becomes critical.

Making people wait for what you see as minimally viable code seems to be beyond their current expectations.


答: You cant fix stupid. If your boss is doing things like you describe its unlikely you'll be able to change that.  Especially if he's not the owner - remember, he has pressure coming from the other direction, and that direction signs his pay check.  Same with your other co-workers. The best first course of action you can take is to get in the habit of protecting yourself.  Use such techniques as that message box you describe.  Keep all emails.  Get as much as you can in written form.  This way you dont take the brunt when stupidity strikes.  Then, as you get promoted up, institute the changes you want with those under your supervision.


答:
Well, social networking applications use a lot of graph theory. They're dealing with a big graph of "friend" connections, so they've probably got a bunch of algorithms that partition that graph into groups and suggest things to users based on the groups that they're in, who their friends are, etc.

But moreso than that, graph theory, data structures, and algorithms are fundamentals of software development, just as the MVC pattern, message-passing, and memory management are fundamentals of iOS development. Just because you're interviewing based on your specialties doesn't mean you don't need to have a solid grasp of basic Computer Science concepts.

For any interview, I would want to have a solid understanding of:

The basics of software development (design patterns, object-oriented design, development methodologies, big-O notation, data structures, graph theory, etc.)

Any technologies that are specific to the position (in this case, Objective-C, the iOS SDK, XCode, etc.)

Domain-specific concerns in the problem space that the position deals with (in this case, I would at least read the Social Network article on Wikipedia, as well as the Network Theory article, and probably some of the linked sources.)

The history of the company I'm interviewing with, existing products that they've created, the backgrounds of their principals, and their main competitors.

Title: As an iOS developer, what type of technical interview questions should you be prepared with?

Body: I just finished a technical interview yesterday and the interviewer asked about graph theory, data structure, and traversals. This has nothing to do with iOS stuff. So I came un-prepared. This was actually for a social mobile gaming company, is this the reason why they ask these kind of stuff instead of iOS stuff? Now it seems to me that I am just overwhelmed by the materials to review and study for future interviews, I have to review the whole data structure/traversal/searching algorithm and at the same time iOS/objective-C fundamentals as well. Can someone guide me on how to prepare? Is my past experience just a special case as it was a gaming company?</p>


答:
I'd point out that part of the problem here is that you've written a quick and dirty tool in the first place. Granted, there were good reasons. Granted, it did the job. But, I've found that anything that solves a problem, will fall into the trap of a "good enough" solution, if you start passing it out.

If your fellow wants it, either politely tell him it isn't fully functional, and you're keeping the keys. You can run it for him from time to time. Or, add in the extra functionality, preferably from the beginning of the project.

All of my quick and dirty tools at this point come from a heavily tested skeleton file. It lets me get going quickly, provides me with a working starting point, and lets me forget about adding all of those necessary blunt edges. I don't have to worry about the getopts library, and its quirks. I don't need to remember details about memory management when I use python. Build the program so that it does one simple task and only one. That makes it easy to test if they are trying to bend it out of shape.

Finally, take advantage of finite state machine architecture. If you know going in all of the possible states, it is far easier to make sure that no matter what, the user can never jump the tracks. I have a program that I wrote to follow this paradigm. It accepts arbitrary input files, which it reads through byte by byte. Even if the client told it to read a binary executable, it wouldn't have any problems. Since it wouldn't find any of the things it's looking for, it's internal buffer would fill up. That would cause it to gracefully clean up, close down, and report to the user that they need me to look at it.


问:
Is it a good idea to always use Google as the first step to solving a problem?

Possible Duplicate:

  Importance of learning to google efficiently for a programmer?

Avoiding lengthy discussions, as a senior level student in CS, how can I get away from Googling problems I run into? I find myself using it too much; I seemingly reach for the instant answer and then blindly copy and paste code, hoping it works. Anyone can do that. I've read the related threads about being a better programmer, but mostly those recommend practicing on pet projects, which I have done, but again I feel EVERY wall encountered, from design through completion, was hurdled with Google.

Do professionals instantly "research" their problem? Or do you guys step back and try and figure it out yourselves?

I'm talking about both 'algorithm/design' problems as well as compiler issues.

答:
I research most problems I encounter.

If I encounter an issue, my first assumption is that I am not the first one to have encountered it.

I also don't believe in reinventing the wheel - so will look for an existing solution before writing my own.

The thing about research is that you need to evaluate the results and how well they fit (or not) with your code base/model/project/team. This means you need to understand the solution, how it works and how to apply it to your situation.

My research saves my clients time and money.

Before the days of search engines, I asked questions on usenet. The Internet is a great tool - use it.


答:
Google is a tool, and you shouldn't feel bad about using it to your advantage.  Looking up problems is not a bad thing.  Why spend an hour solving a problem that may have already been solved, and in a better fashion, then what you may come up with.

With that being said, I would attempt to understand why the solution you find works.  Blindly copying and pasting code definitely won't get you anywhere, and down the road if problems arise from that code you will have a much harder time trying to solve them.

Title: Is it a good idea to always use Google as the first step to solving a problem?

Body:
Possible Duplicate:

  Importance of learning to google efficiently for a programmer?

Avoiding lengthy discussions, as a senior level student in CS, how can I get away from Googling problems I run into? I find myself using it too much; I seemingly reach for the instant answer and then blindly copy and paste code, hoping it works. Anyone can do that. I've read the related threads about being a better programmer, but mostly those recommend practicing on pet projects, which I have done, but again I feel EVERY wall encountered, from design through completion, was hurdled with Google.

Do professionals instantly "research" their problem? Or do you guys step back and try and figure it out yourselves?

I'm talking about both 'algorithm/design' problems as well as compiler issues.


答:
You don't just want to copy and paste answers; that's how you stay a terrible programmer. However, by looking at the work that others have done before you, you can start to understand the patterns that emerge to solve common problems, and apply them to your own code.

As a current CS student, it's unlikely that you haven't encountered many problems that have yet to be solved. In all likelihood, your exercises are themselves pretty trivial, and it won't be until you've got the time to really cut your teeth on real world exercises that you start to gain a better applied knowledge of software development. This is to be expected -- it's why the position of Junior Developer was invented. Don't sweat it, at this point in your career, a huge part of the battle is simply knowing how to find answers.


答:
Well, the answer doesn't have much to do with programming, except that software is a good that it is difficult to easily judge the quality of.

You might not be able to change the culture, because people may have no real motive not to be sloppy, because the people affected by the software quality don't have much to do with the process.  For example, your clients might be required to purchase and use software to do their jobs, but have little personal stake in how effective that software is, because they won't personally be blamed for it's problems or rewarded for it's virtues (in large part because nobody really knows if competing software would be any better).  So you might only have to meet their feature requests without taking too long, but not have to worry much about whether it's buggy.  So you can all be fairly sloppy without consequences (to anybody who makes any decisions that affect you).

I don't know if something like this is the case, but if it is you may have a hard time changing the culture since the people you are trying to get to change won't actually be better off if they do.

If they will be better off, you may have an easier time of it, since you can potentially convince them why they will.  Unfortunately, if there weren't some sort of political situation that makes sloppiness O.K. they probably wouldn't be sloppy in the first place, so it's likely to be tough.  You could always try the argument "someday you may have a job that requires doing things right" (perhaps more diplomatically phrased...)


答:
Check the usage carefully before you remove it, because there are some applications that merit using a construct whose internal structure can vary.  The fact that it's a union and not a struct says this might one of those situations.  Look for some field that's common to all of the union's variants which is used to tell code that refers to it which arrangement to use in interpreting the contents.

The X Window System's client-side library uses this technique to allow event messages received from the server to be dropped directly into a union and easily accessed without casting or other nastiness:

```<code>typedef struct {
        int type;               /* of event */
        unsigned long serial;   /* # of last request processed by server */
        Bool send_event;        /* true if this came from a SendEvent request */
        Display *display;       /* Display the event was read from */
        Window window;          /* "event" window it is reported relative to */
        /* ...etc... */
} XButtonEvent;

typedef union _XEvent {
        int type;               /* must not be changed; first element */
        XAnyEvent xany;
        XKeyEvent xkey;
        XButtonEvent xbutton;
        XMotionEvent xmotion;
        /* ...etc... */
} XEvent;
</code>```

Title: Is there any merit to using `union` to create an alias?

Body:
I've inherited a bit of code and saw something new. They have a data structure definition out in a .h file, and in various local files they'll declare:

```<code>union globalStructOstuff localVar;
</code>```

Is there any merit to this?

I could see some if the global was some placeholder and the local versions were going to be different eventually.  But that's not the case here.

So I think all it's doing is causing new guys a couple of extra minutes searching for definitions. I'd axe it once I got the chance, but I wanted to see if I'm missing some greater purpose.

Edit, resolution

With your fine help, I managed to open my eyes and realize globalStructOstuff isn't a struct at all, it's a union which holds the struct of a similar name. And they didn't use typedef. So all that's happening here is declaring a local variable. It has a type of union. No alias to anything global.  Sorry for the confusion, thanks for all your help.

Body:
Check the usage carefully before you remove it, because there are some applications that merit using a construct whose internal structure can vary.  The fact that it's a union and not a struct says this might one of those situations.  Look for some field that's common to all of the union's variants which is used to tell code that refers to it which arrangement to use in interpreting the contents.

The X Window System's client-side library uses this technique to allow event messages received from the server to be dropped directly into a union and easily accessed without casting or other nastiness:

typedef struct {
        int type;               /* of event */
        unsigned long serial;   /* # of last request processed by server */
        Bool send_event;        /* true if this came from a SendEvent request */
        Display *display;       /* Display the event was read from */
        Window window;          /* "event" window it is reported relative to */
        /* ...etc... */
} XButtonEvent;

typedef union _XEvent {
        int type;               /* must not be changed; first element */
        XAnyEvent xany;
        XKeyEvent xkey;
        XButtonEvent xbutton;
        XMotionEvent xmotion;
        /* ...etc... */
} XEvent;


答:
Nothing wrong with Googling stuff, but how you Google is important. 'Blindly copying and pasting' does not sound like a constructive way of doing it. A better way of approaching it is to think of it as learning from the experience of programmers who are more experienced (and in my case, often cleverer!) than you. Almost all of the problems you come across will have been solved by someone else in the past, so save yourself the time by not going down all the dead ends they did and learn from their experience. Another wise thing to do would be to not just go for the first answer, but to evaluate many. And of course, when it comes to using certain tools, you're looking for right or wrong answers.

And instead of Googling, you could just go direct to Stack Overflow or Programmers SE!

But seriously, Google is a tool used by all professional developers.


答: It is always good to research what other people have done in a similar or same situation and learn from them, instead of re-inventing the wheel, slowly and incorrectly. As long as you strive to learn from the solutions you Google, then you are in good shape!


答:
That looks like a variable declaration.

In C declaring a variable of a struct or union requires the struct or union keyword (C++ removed this requirement).

Most people use a typedef to automatically include the keyword into the type name, as Blrfl did in his code example.


答:
We were discussing coding standards recently at work and an interesting point came up. We are English speakers in the UK, and we have been directed to code in US English. As hard as it is for us to swallow our pride, we have to accept that this is the right thing to do. Although there is no difference in the keywords, much of the .NET framework is in US English, and I accept it is better to keep the consistency, rather than put national pride first :).

It also might help your English (not that there's anything wrong with it!). The big question is, with the emerging economies on the rise, when will us English speakers have to learn to code in Brazilian Portuguese, Russian, Hindi or Mandarin :)


问:
What Is The Best Technique For Managing Bugs and New Features With Version Control in CVS/SVN for a Team of 6 to 9 People?
In a company working on a long term software project, there are 6 to 9 developers working in the same office.

The development team uses JIRA for bug tracking and CVS (and some SVN) for version control of different Java Web Apps related to the software application.

The team uses REST to communicate between the Web Apps on different servers. The environment consists of Amazon EC2 and Google App Engine Apps, all written in Java, HTML, CSS, and JavaScript.

The development team commits the code every day. Using this strategy, deployments happen every 20-25 days, but they would like to target once per week or once every 2 weeks instead.

When the code goes through testing, the testers find and report bugs, but when the development team fix the bugs and deploy the software, the software sometimes then has more bugs in it because developers working on new features are still committing code to the repository.

Sometimes the sales team or customers find bugs as well on production systems. Our thought is that we could check out a copy of the code that is stable and make changes there.

I suspect this is a problem with how the version control is used, but it could be something else in the process. How should this agile development team of 6-9 people make sure that the releases are both frequent, once per week or once every 2 weeks, and that the deployments are high quality with no regression bugs?

答:
All I can suggest is a tighter feedback loop, via

unit or integration testing - initially aimed at defects and common
integration pain points.

a continuous build that will trigger on every check in that runs unit
and integration tests

a 'fix the build' type culture in the team - "always striving to get
the light green"

no code silos - as much as possible, all developers should be able to
work on any problem or build failure.

deploy often to a demo version of the application(s) that
developers/BA's can use to shake out new features before they hit the
test team.

a new defect, as well as getting fixed, also gets a test that focuses
on that problem.

I think you'll find that doing these things will allow you to reduce the number of bugs hitting the testers.


答:
Here's the thing with google:

There is nothing wrong with consulting google/stackoverflow/etc for help.  However, I wouldn't just blindly copy/paste the code as it's most likely not going to integrate right.  Use it as a launching point and go from there.

Don't be afraid to use google.  I would rather an employee google a problem than waste time spinning their wheels.  We've all consulted google - and that's a good thing


答:
You should go read some material about working with branches. I'd keep separate branches for old versions, current and upcoming version, and force all development into feature branches; none of your "stable" branches should ever be broken.

I suppose tooling is a large part of what's missing for you guys. Branching and merging is a bitch with SVN and CVS. I'd push for a move to Git.

Title: What Is The Best Technique For Managing Bugs and New Features With Version Control in CVS/SVN for a Team of 6 to 9 People?

Body:
In a company working on a long term software project, there are 6 to 9 developers working in the same office.

The development team uses JIRA for bug tracking and CVS (and some SVN) for version control of different Java Web Apps related to the software application.

The team uses REST to communicate between the Web Apps on different servers. The environment consists of Amazon EC2 and Google App Engine Apps, all written in Java, HTML, CSS, and JavaScript.

The development team commits the code every day. Using this strategy, deployments happen every 20-25 days, but they would like to target once per week or once every 2 weeks instead.

When the code goes through testing, the testers find and report bugs, but when the development team fix the bugs and deploy the software, the software sometimes then has more bugs in it because developers working on new features are still committing code to the repository.

Sometimes the sales team or customers find bugs as well on production systems. Our thought is that we could check out a copy of the code that is stable and make changes there.

I suspect this is a problem with how the version control is used, but it could be something else in the process. How should this agile development team of 6-9 people make sure that the releases are both frequent, once per week or once every 2 weeks, and that the deployments are high quality with no regression bugs?


答:
Rather than "check out a copy of the code that is stable and make changes there." use branching for each feature.

Set up a continuous integration server.  When you check code into the main "dev" branch it autobuilds to your dev server.

When you have a new task/feature/etc you branch the dev code into a feature branch.  Develop, then merge back into dev.

You also maintain a QA/Test branch, again, it has autobuilds setup to deploy to your QA/Test server.

Each feature can be deployed independently to dev then to QA.

Access to check in to the QA branch needs to be controlled.  So that if QA starts testing, no more can be moved there until they have signed off, and merged the QA branch into Production (or a Staging step in between)

This way devs don't clobber what QA is trying to test.  And it only goes to Prod once QA signs off.  Then, once they sign off and it's deployed to prod, you release another batch of features that are ready into the QA branch for them to QA.

Lather, rinse, repeat.


答:
I live in Italy and here you usually see English mixed with Italian or English words with Italian suffixes.. This is very widespread, for example in a slide in a CS university course I saw:

```<code>bool checkFatto;
</code>```

("check done")

I'm a strong believer that all code, including comments, and even including in person developer talk should be in english. Italian simply doesn't have many of the required words required to discuss programming topics. But this is virtually never done.. Maybe that's why I chose to telecommute for an american company.

Something that bothers me just as much is people who google programming questions in italian or look up the italian wikipedia. They have no idea of the quantity of the information they are missing out on (such as the entirety of SO).

Body:
I live in Italy and here you usually see English mixed with Italian or English words with Italian suffixes.. This is very widespread, for example in a slide in a CS university course I saw:

bool checkFatto;

("check done")

I'm a strong believer that all code, including comments, and even including in person developer talk should be in english. Italian simply doesn't have many of the required words required to discuss programming topics. But this is virtually never done.. Maybe that's why I chose to telecommute for an american company.

Something that bothers me just as much is people who google programming questions in italian or look up the italian wikipedia. They have no idea of the quantity of the information they are missing out on (such as the entirety of SO).


答: To what extent have you shown them how to use the tool?  Have you asked them if they have any difficulties using it?  You need to find out why they don't like to use it and try to remedy that.  Note that this is exploratory and there is the question of how well do those other 4 trust you as these may be rather personal answers they may give and thus some sensitivity may be required.</p>

Title: How can I inspire my group to start using an online collaborative tool more?

Body:
I'm in a project with 4 other people, and I've been willing to fully adopt a collaborative tool in order to make it possible to share information and store data (PDFs, DOCs, etc.) in an online tool, rather than doing it by e-mail. The problem is that I'm the only one enforcing it; actually I'm the only one using it. The others only use it when I ask them to do so.

How would you handle this? Have you experienced something similar, if so, what have you done?


答: In addition to what was already mentioned, try to show them why to use the tool by coming up with scenarios of the value of this tool. You can buy the team lunch and present your idea, some may be ready to listen for a free pizza :)</p>


问:
Speed of Java vs. JS / HTML / CSS for web applications
I am creating a web application.  I have primarily used Javascript specifically jQuery.  Because of some very specific functionality, I am running into practical limitations of Javascript--they're not hard limitations but stuff that I would find easy in Java, like making an equation editor where you can edit directly as opposed to entering TeX, is difficult in JS even using MathJax as a base.

I'm going to have to build even more complex functionality that involves 3D and physics engines.

For a large scale application like this--specifically one that involves 3D and physics engines--would Java be slower or faster than Javascript when one is run within a browser?  (Assume that code is written well in both cases.)  Or is it completely uncertain--i.e. dependent on far too many specific variables?

Thanks.

答: Assuming you mean client side java so that the hardware and network behavior are the same, it depends on the browser. The Internet explorer JavaScript engine is a couple orders of magnitude slower than chrome for example. Java or other plugins like flash should be fairly constant across browserson the same hardware.</p>


答: It depends on many variables, I will say that the Java VM is more consistent.  You can also look at Silverlight, Flash/Flex and something else I'm probably missing :-).</p>

Title: Speed of Java vs. JS / HTML / CSS for web applications

Body:
I am creating a web application.  I have primarily used Javascript specifically jQuery.  Because of some very specific functionality, I am running into practical limitations of Javascript--they're not hard limitations but stuff that I would find easy in Java, like making an equation editor where you can edit directly as opposed to entering TeX, is difficult in JS even using MathJax as a base.

I'm going to have to build even more complex functionality that involves 3D and physics engines.

For a large scale application like this--specifically one that involves 3D and physics engines--would Java be slower or faster than Javascript when one is run within a browser?  (Assume that code is written well in both cases.)  Or is it completely uncertain--i.e. dependent on far too many specific variables?

Thanks.


问:
Are captchas worth the decreased usability?
When is it useful to use a captcha? When is it an unnecessary hindrance? Is a captcha just a quick fix for the lazy/unexperienced programmer, or are they really the best way to prevent spam and bots? </p>

答: In my experience captchas are the best way to prevent spam, no matter how well the form is programmed there will always be a spam bot better than your app.</p>


答:
Per my experience, the most productive approach to handle issues like that was to track-reflect-tune the development process in sort of OODA loop. Key tricks are to isolate when needed, have clear checkpoints for dev and QA to communicate ("internal releases" if you wish) and, well, not to worry about what isn't really important.

oh and better get rid of CVS. Two version control systems seem to be one too much for the case like yours.

Now, let's take a look at some of the problems you mention...

When the code goes through testing, the testers find and report bugs, but when the development team fix the bugs and deploy the software, the software sometimes then has more bugs in it because developers working on new features are still committing code to the repository.

The only productive way I know to stabilize quality of software to be deployed (release candidate) is to isolate it from main repository (read: dedicated branch, with its own dedicated  Feature Freeze and Code Freeze mini-milestones).

Note my experience with doing it the other way around, ie with "freezing" main repository while testing for release-candidate code was total disaster.

Sometimes the sales team or customers find bugs as well on production systems. Our thought is that we could check out a copy of the code that is stable and make changes there.

Not necessarily so. Sorry for being vague but I doubt that it's possible to come up with technically precise recipe here. This kind stuff is better to communicate with product stakeholders. One thing dev and QA teams can (should) bring to the discussion table is comparative estimate of efforts involved into patching the older version vs deploying the newer one.


答:
If I don't know within a few minutes of looking at a problem how to solve it or at least have some ideas, I Google it.

The reason "expert" programmers are experts is because they have experience.  If my current level of experience does not solve a problem, I need to learn about it and gain more experience.

As a software developer, you will learn for the rest of your career.  When you stop learning, that's when your career starts stopping.

EDIT

I forgot to mention, when you find an answer that works by going on Google, you aren't done learning until you understand why that answer worked.


问:
Thread class design?
I have a method like this in my UI code:

```<code>void MyDialog::OnCommandSaveData()
{
    std::list<MyClass*> objects;
    service_->GetAll(objects);
    dataService_->SaveObjects(objects);
    AddMessage("Saved data.\n");
}
</code>```

Because this method can take some time, I want to kick off a thread to do this.  I'm using C++ and I plan on using Boost.Thread.  So my question is how to best do this.  My understanding is that I need to create a static function, static method, or functor which will contain the above code.  Where should this live, in the dialog class?  That just seems wrong, but then again maybe not.

And then I will need a mutex and lock around at least the SaveObjects method.  Where should the mutex live and where do I put the lock?

Most examples of threading, as with examples of so many things, don't show the threading in the context of a real application.  They show a main method with a global function and that's it.  So if you can point me to example of a class that manages threading for an operation that would be great.

I buy the logic in the accepted answer to this question: Is It "Wrong"/Bad Design To Put A Thread/Background Worker In A Class? However, the answer only tells you why to do it, not how.

UPDATE

I've refactored my code using MVP (Model View Presenter)/Humble Dialog Box pattern:

```<code>void MyDialog::OnCommandSaveData()
{
    presenter_->SaveData();
}
</code>```

So now I will need to look at adding multi-threading in the context of MVP.

UPDATE 2

I found this article which talks about creating mulithreaded winforms using MVP.  It's in C# so I'll have to translate it into C++ but it looks good:

http://aresterline.wordpress.com/2007/04/17/multi-threaded-winforms-application-mvp/

Basically it involves 1) creating a ThreadSafeView which is a wrapper or proxy around your view that allows your view to be updated from a worker thread. And 2) creating a ThreadedPresenter which allows presenter methods to spawned in a new thread.  I really like how this isolates the threading code from the view and the presenter code.

答:
It depends, of course, on how you've designed your application. If you've followed the MVC paradigm, you'd put that code somewhere in the data model or in the controller that manages the model. You're right that it certainly shouldn't be part of a dialog class.

Think about what you'd do if you wanted to add another way to interact with your application. Perhaps you'd add a command-line interface, or a scripting interface. Or maybe build-in a web server so that you could connect to the application from a web browser. You'd presumably still want to be able to add objects to whatever data storage your app uses, right? And you'd want to do that using this same data-saving method. What parts of the application would your hypothetical command-line interface interact with? That's where this method belongs.

Title: Thread class design?


答: There are other way to prevent spam and bots, but captcha's work the best.  Sometimes asking a simple question on a form like "2+10=" or "Are you human?" works fine as a captcha, for a while at least.  </p>

Title: Are captchas worth the decreased usability?

Body: When is it useful to use a captcha? When is it an unnecessary hindrance? Is a captcha just a quick fix for the lazy/unexperienced programmer, or are they really the best way to prevent spam and bots? </p>


答:
Are you copying and pasting a line of code or several lines just out of conveniance? You're always going to run into something you don't know. Sometimes it's so much the size of the language, but all the frameworks just keep piling on. It's not going to end.

If you keep searching for the same thing over an over, start your own set of cheat sheets or code samples.

Take some time to understand what you're copying. It takes understanding and repeated use before you gain any fluency. Some things you'll just do once.

In some cases, you're better off searching for a solution even if you know you can solve it on your own. Then you can compare and contrast and pick the best one for your situation.

Hate to tell you, but unless you start working with some minimal language in a narrow domain, you'll be searching for quite some time.


问:
Javascript frameworks for large development teams
My company is reevaluating what kind of web framework we want to use.  We are currently using the Ext 4.0 framework but there are questions being raised that it may not be the right framework to use.  I like what Ext has to offer (rich GUIs, data package and class system) are there other frameworks out there that are similar?  Are there frameworks out there tailored to medium/large software companies?

Info:
Potentially 100's of developers converting thick client screens to the web.  Data modeling is important and well as rich GUI support.  Maintainability and uniformity across multiple products important as well.

Any info is greatly appreciated.

答:
Javascript frameworks generally cover stuff that happens within the page rather than the app as a whole, so it doesn't matter too much which one you use.

To keep the overall app manageable you will need to set up your own framework on top of that. this could be as simple as a set of standards on how a page should be structured or as complex having a defined page template and your own set of customized controls.

It also makes a big difference how much happens on a page - for example jQuery Mobile loads multiple pages into a single DOM - great for performance, but losing the complete separation between scripts on different pages means that a bug on one page could stop script execution on any other page - not so good for a large app with a large team.


答:
If it can be described in BNF (Backus-Naur Form) or something similar, it's syntax.  If it can't, it's not.

Semantics, on the other hand, is about the meaning of a program (or other chunk of source code).

And sometimes the line between the two can be blurry.

One way to understand the distinction is to look at the kinds of errors you get when your program's syntax or semantics is incorrect.

A syntax error is a failure of the source code to match the language grammar, for example, not having a semicolon where one is required.

A semantic error is a failure to satisfy other language requirements (what C, for example, calls "constraints"); an example might be writing x + y where x and y are of incompatible types.  The language grammar tells you that an addition looks like something + something, but it's not powerful enough to express the requirements on the types of the left and right operands.

(Logical errors, such as using 1 where 2 would be correct, are not generally detectable by the compiler -- though in some cases a compiler can warn about questionable code.)

Title: What's the difference between syntax and semantics?

Body: I've always thought that referring to the syntax of a language was the same as referring to the semantics of a language. But I've been informed that apparently that's not the case. What's the difference?</p>


答:
In a large team like that the focus will have to be on separation of concerns and clear API's between the various application segments. While ext is pretty much as good as it gets in the pure client-side solutions, it's still based on javascript, a language that makes it essentially impossible to encapsulate logic behind strict interfaces. You'll also need a team with solid javascript skills, which may not be as easy to find as desktop developers.

You may want to consider GWT instead, possibly using ExtGWT if you like the ext components. It will be much easier to bring in desktop developers into a pure-java platform, and you'll be able to define stricter interfaces between application modules that can be verified at compile time.

Title: Javascript frameworks for large development teams

Body:
My company is reevaluating what kind of web framework we want to use.  We are currently using the Ext 4.0 framework but there are questions being raised that it may not be the right framework to use.  I like what Ext has to offer (rich GUIs, data package and class system) are there other frameworks out there that are similar?  Are there frameworks out there tailored to medium/large software companies?

Info:
Potentially 100's of developers converting thick client screens to the web.  Data modeling is important and well as rich GUI support.  Maintainability and uniformity across multiple products important as well.

Any info is greatly appreciated.


问:
Agile development deployment process. Where do QA and Business Owners test?
I've been reading up a lot lately on various web application deployment processes using SVN or GIT, with a view to redesigning how we currently deploy where I work.

As is the way with many flavours of Agile, it's assumed that anything committed to master or trunk is production ready. Both GitHub and Etsy, http://codeascraft.etsy.com/2010/05/20/quantum-of-deployment/ say that they work on this basis (although Etsy actually have a staging environment).

This process assumes all unit test and CI tests have been run. You run the tests locally and on CI and then commit to trunk. SO, at this point your code is technically sound.

Your code may be technically correct, but user/functional testing may unearth more bugs, particularly when it comes to front end testing.

My question is this. Where do QA and Business owners test the feature changes you have implemented? On your local development machine before you commit to trunk, or on a QA/staging machine?

If you have a staging machine that runs off trunk, and you assume that all code committed to trunk is production ready ... eh .. then at what point is the code signed off and good to go into production from both a technical and business perspective? If you have only one staging machine, many developers and that is where the code is to be QA'd, then how can you deploy from trunk as many developer changes can be waiting for sign off.

I'd be interested to hear how others have approached this?

答:
We have automated acceptance tests on the same feature branch. When you make a release candidate, it includes the automated tests you ran to see if the feature passes. You also test the release candidate. When everything passes, you promote it then by merging to master.

More on this process here:

https://plus.google.com/109096274754593704906/posts/R4qkeyRadLR

Do checkout the comments as well.

Hope this helps,

Adam

OwnerDisplayName: Bazza

OwnerDisplayName: adymitruk


答:
I agree that the internet is a tool that should be used.

That said, you need to be mindful of the license any code you use from the internet has been released under.  If you copy some pieces of GPL licensed code into your company's proprietary code, then that could end up causing some real problems when people come saying that your company now has to release its proprietary code under the GPL because it's a "derived work".  When I interned at Microsoft, my manager warned me against even looking at open source code too much.

Of course, this isn't as much of an issue when you're in school because you're typically not selling or distributing the programs you write for class.


问:
To Press Onward or Not?
In the past week I've been meeting and speaking with someone who's interested in finding help on developing a game (built using php and mysql, with a little bit of javascript). I agreed to help out, however, now that I've seen the code and file organization, I don't know if it's feasible for anyone (not just myself) but the original writer to even decipher what's going on.

Basically, there isn't any structure either to the files or to their code, it's just sort of strewn about as is. Every php file that didn't come from an external source is in the root and there is a little organization for other files types, but not much. Most of the code isn't indented or readable.

I'm not trying to say it doesn't work, I've seen it work, it's just that I don't think anybody else could try to get a handle on what it does (and I don't want to sound like I'm ragging on the guy who wrote it, he told me that he really doesn't do much coding).

Basically, my question is should I back out, or should I try to press onward? Does anyone have experience with working on a big-old-system that needs to be completely updated? Any thoughts?

Additional Information:
No, I don't have a contract yet, I've just looked at it thus far. My own feelings are that if I decide to press onward I'll end up rewriting the entire system (which is 113 php files in the root, plus several others located elsewhere in the system), and I don't know if I really want to continue, it's just that I feel like I said I would try to help out.

答:
If it was a well written, well structured piece of code he wouldn't need your help. You have this opportunity because the code is poor.

You have already assessed the amount and difficulty of the work involved. Now its time to assess the possible rewards.

This mostly depends on how good the game is. Forget about the code and have a good long look at the game. Does it grab you? Is it fun to play? Will it appeal to your cousin? Is it the only game like this? Is there an obvious way to make money out of it?

A good game badly implemented will always trump a bad game implemented well; so forget about the "inner beauty" and focus on whether the game has any chance of taking off.

Title: To Press Onward or Not?


问:
As an iOS developer, what type of technical interview questions should you be prepared with?
I just finished a technical interview yesterday and the interviewer asked about graph theory, data structure, and traversals. This has nothing to do with iOS stuff. So I came un-prepared. This was actually for a social mobile gaming company, is this the reason why they ask these kind of stuff instead of iOS stuff? Now it seems to me that I am just overwhelmed by the materials to review and study for future interviews, I have to review the whole data structure/traversal/searching algorithm and at the same time iOS/objective-C fundamentals as well. Can someone guide me on how to prepare? Is my past experience just a special case as it was a gaming company?</p>

答:
You prepare for this type of interview by not just knowing your niche specialty, or any particular subject such as graph theory, but by studying the entire broad field of encompassing software engineering, computer science, general design methodology, problem solving skills and more.  This could take years, not just a few days of cramming.

These types of interview questions are usually statistical spot checks of a random sub-topic from the above broader areas to see if you are the type of person who has the intellectual curiosity and who has put in the time to learn, and is not just a niche specialist who may or may not be able to morph with changing technologies and markets.

So, whatever random sub-topic someone crams on is likely to not be part of the next interview question on their general professional knowledge.

The solution?  Keep learning.


答:
A good programmer is one that knows a lot.  A great programmer is one that knows where to find everything.

It is rare to have the capacity to remember every fine detail of what we do.  There is just so much technology out there (languages/frameworks/platforms/etc.).  Sometimes you need to research documentation.  Opening a resource book or Googling it, the result is the same: your solution. (provided you are looking at a reputable resource on the internet)