问:
What are the drawbacks of Python?
Python seems all the rage these days, and not undeservingly - for it is truly a language with which one almost enjoys being given a new problem to solve. But, as a wise man once said (calling him a wise man only because I've no idea as to who actually said it; not sure whether he was that wise at all), to really know a language one does not only know its syntax, design, etc., advantages but also its drawbacks. No language is perfect, some are just better than others.

So, what would be in your opinion, objective drawbacks of Python.

Note: I'm not asking for a language comparison here (i.e. C# is better than Python because ... yadda yadda yadda) - more of an objective (to some level) opinion which language features are badly designed, whether, what are maybe some you're missing in it and so on. If must use another language as a comparison, but only to illustrate a point which would be hard to elaborate on otherwise (i.e. for ease of understanding)

答:
I think the object-oriented parts of Python feel kind of "bolted on". The whole need to explicitly pass "self" to every method is a symptom that it's OOP component wasn't expressly planned, you could say; it also shows Python's sometimes warty scoping rules that were criticized in another answer.

Edit:

When I say Python's object-oriented parts feel "bolted on", I mean that at times, the OOP side feels rather inconsistent. Take Ruby, for example: In Ruby, everything is an object, and you call a method using the familiar obj.method syntax (with the exception of overloaded operators, of course); in Python, everything is an object, too, but some methods you call as a function; i.e., you overload __len__ to return a length, but call it using len(obj) instead of the more familiar (and consistent) obj.length common in other languages. I know there are reasons behind this design decision, but I don't like them.

Plus, Python's OOP model lacks any sort of data protection, i.e., there aren't private, protected, and public members; you can mimic them using _ and __ in front of methods, but it's kind of ugly. Similarly, Python doesn't quite get the message-passing aspect of OOP right, either.

Title: What are the drawbacks of Python?


问:
Are programmers bad testers?
I know this sounds a lot like other questions which have already being asked, but it is actually slightly different. It seems to be generally considered that programmers are not good at performing the role of testing an application. For example:

Joel on Software - Top Five (Wrong) Reasons You Don't Have Testers (emphasis mine)

Don't even think of trying to tell college CS graduates that they can
  come work for you, but "everyone has to do a stint in QA for a while
  before moving on to code". I've seen a lot of this. Programmers do not
  make good testers, and you'll lose a good programmer, who is a lot
  harder to replace.

And in this question, one of the most popular answers says (again, my emphasis):

Developers can be testers, but they shouldn't be testers. Developers
  tend to unintentionally/unconciously avoid to use the application in a
  way that might break it. That's because they wrote it and mostly test
  it in the way it should be used.

So the question is are programmers bad at testing? What evidence or arguments are there to support this conclusion? Are programmers only bad at testing their own code? Is there any evidence to suggest that programmers are actually good at testing?

What do I mean by "testing?" I do not mean unit testing or anything that is considered part of the methodology used by the software team to write software. I mean some kind of quality assurance method that is used after the code has been built and deployed to whatever that software team would call the "test environment."

答:
Programmers are fine defining tests when they define the tests before writing the code.  With practice, they get even better.

However, when defining tests for code they have written, they don't do very well.  They will have the same blind spots in testing that they had in writing the code.

Using programmers to do manual testing is just silly.  Manual testing is silly enough on it's own; making programmers do it is extremely silly.  It's expensive and drives away the competent programmers.

ContentLicense: CC BY-SA 3.0

Title: Are programmers bad testers?


问:
Reasonable Number of Directed Graph Nodes and Edges
How many directed graph nodes are typically represented in the browser? I'm working with some large data-sets with nodes and edges more then 400,000. I'm wondering if I am going down a fruitless path trying to represent them in the browser via arbor.js or similar JS libraries. What's the most effective way to allow a large number(large relative to my domain of real estate transactions, maybe 1-10,000) of users to visualize and browse a large directed graph of up to 500,000 records?</p>

答:
I would tend to think that javascript has grown up to where it can handle these issues and SVG (finally) is getting real momentum.

Check out d3 and browse around.  Directed graph might not be your best option.  Be sure to check out hive plots and this example. Matrix, cord diagrams. Very cool stuff out there.


问:
one single compressed js file VS compressed requirejs module files
I just started using requirejs and I love it. I have one concern though. I've been compressing all my js files into one single file. Even with requirejs optimizer, I need to load module files from the server time to time and I'm concerned with it.

Performance and user experience wise, which one is better?

答:
Performance and user experience wise, which one is better?

A single compressed file.

It is a single connection, so the browser is free to download other assets.

It is compressed, so it takes less time to transfer to the browser.

Both mean that the page and the javascript run faster - this is better user experience and better performance.

Win win.


答: The reason to break up your .js files is to reduce the initial load time to be as small as possible. the first load is the most critical because it generally determines if a user will bother with exploring your site further or they perceive it as slow. If that first load is important to you it may be worth taking out unneeded files for your homepage and checking if it noticeably changes that initial load, otherwise Oded's advice is solid.</p>

Title: one single compressed js file VS compressed requirejs module files

Body:
I just started using requirejs and I love it. I have one concern though. I've been compressing all my js files into one single file. Even with requirejs optimizer, I need to load module files from the server time to time and I'm concerned with it.

Performance and user experience wise, which one is better?


问:
Just getting started in Spring and my preference is XML config over annotations. Correct or not?
After having read through some of the Spring docs my inclination is towards using a XML config file rather than annotations on the classes themselves. My reasoning is that by doing so you avoid tying your POJOs to a particular framework.

Based on your experience with Spring, are there any advantages that XML configuration have over an annotation based configuration, and if not what are the disadvantages?

答:
I like using annotations for things that

are essential (like @Service)

won't change without a redeployment (like database column names)

I like using annotations for

global config (aspects)

things that could be changed by users of a component (security, role names, datasource jndi references), etc.

There is a thread at coderanch I really like on this topic.  Craig Walls - the author of "Spring in Action" explains why he evolved from never using annotations to his current state.


问:
Is there any research about daily differences in productivity by the same programmer?
There has been a flurry of activity on the internet discussing a huge difference between the productivity of the best programmers versus the productivity of the worst.  Here's a typical Google result when researching this topic: http://www.devtopics.com/programmer-productivity-the-tenfinity-factor/

I've been wondering if there has been any research or serious discussion about differences in day-to-day productivity by the same programmer.

I think that personally, there is a huge variance in how much I can get done on a day by day basis, so I was wondering if anyone else feels the same way or has done any research.

答:
There is a simple answer, why to re-search :)

Productivity of a "Workhorse Programmer" is strictly proportionality to a good sleep, supplies of caffeine and no distractions (including some family things)


问:
Reformatting and version control
Code formatting matters. Even indentation matters. And consistency is more important than minor improvements. But projects usually don't have a clear, complete, verifiable and enforced style guide from day 1, and major improvements may arrive any day. Maybe you find that

```<code>SELECT id, name, address
FROM persons JOIN addresses ON persons.id = addresses.person_id;
</code>```

could be better written as / is better written than

```<code>SELECT persons.id,
       persons.name,
       addresses.address
  FROM persons
  JOIN addresses ON persons.id = addresses.person_id;
</code>```

while working on adding more columns to the query. Maybe this is the most complex of all four queries in your code, or a trivial query among thousands. No matter how difficult the transition, you decide it's worth it. But how do you track code changes across major formatting changes? You could just give up and say "this is the point where we start again", or you could reformat all queries in the entire repository history.

If you're using a distributed version control system like Git you can revert to the first commit ever, and reformat your way from there to the current state. But it's a lot of work, and everyone else would have to pause work (or be prepared for the mother of all merges) while it's going on. Is there a better way to change history which gives the best of all results:

Same style in all commits

Minimal merge work

?

To clarify, this is not about best practices when starting the project, but rather what should be done when a large refactoring has been deemed a Good Thing™ but you still want a traceable history? Never rewriting history is great if it's the only way to ensure that your versions always work the same, but what about the developer benefits of a clean rewrite? Especially if you have ways (tests, syntax definitions or an identical binary after compilation) to ensure that the rewritten version works exactly the same way as the original?

答:
But how do you track code changes across major formatting changes?

Formatting changes are code changes; treat them as you would any other change to your code. Anyone who has worked on a significant project will probably have seen bugs and other issues that were created when someone decided to "just" reformat some code.

But it's a lot of work, and everyone else would have to pause work (or
  be prepared for the mother of all merges) while it's going on.

Why do you have to reformat everything all at the same time? Especially if the reformatting doesn't change the meaning of the code, you should be able to reformat files individually and check them in as you go along. Better, get everyone on your team to agree on a style (otherwise there's no point in reformatting anyway) and have them all take care of reformatting in the course of their other work. After a while, you'll have covered most of the code with out disrupting the rest of the project.

Title: Reformatting and version control


问:
Layout of mathematical views (iOS)
I am trying to figure out the right way to encapsulate graphical information about mathematical objects.  It is not simple.  For example, a matrix can include square brackets around its entries, or not.  Some things carry down to sub-objects -- for example, a matrix might track the font size to be used by its entries.  Similarly, the font color and the background color would carry down to the entries.  Other things do not carry down.  For example, the entries of the matrix do not need to know whether or not the matrix has those square brackets.

Based on all of the above, I need to calculate sizes for everything, then frames.  All of this can depend on the properties stored above.  The size of a matrix depends on the sizes of its entries, and also on whether or not it has those brackets.

What I am having a hard time with is not the individual ways to calculate sensible frames for this or that.  It is the overall organizational structure of the whole thing.  How can I keep track of it all without going crazy.

One particular obstacle is worth mentioning -- for reasons I don't want to go into here, I need to calculate the sizes and frames for everything before I instantiate any actual views.  So, for example, if I have a Matrix object, I need to calculate its size before I make a MatrixView.  If I have an equation, I need to calculate the size of the view for the equation before I create the actual view.  So I clearly need separate objects for those calculations.  But I can't figure out a sensible class structure for those objects.  If I put them all into a single class, I get some advantages because copying then becomes easy.  But I also end up with a bloated class that contains info that is irrelevant for some objects -- such as whether or not to include those brackets around the matrix.  But if I use a lot of different classes, copying properties becomes a real pain.

If it matters, this is all in Objective C, for an iOS environment.  Any pointers would be greatly appreciated.

EDIT: To clarify: I have model objects that contain mathematical information and can compute the text that will be displayed.  I also think it will make sense to have style sheet objects that will know the font size.  Therefore, between the two, I can compute everything.  This still leaves the issue of how to keep track of the resulting information.  I don't want to call the "compute-your-size" methods more than necessary as they are expensive.  So I have to cache some things.  But where?  And how do I manage that caching?

答:
I don't have experience with this directly, but I've been impressed with the MathJax implementation. It's used (among other places) in the iPython Notebook, and on StackExchange.

It's open source, so you can find it on GitHub. You'll probably want to start looking at the output formats. The interesting stuff looks like it starts around line 706, here.

Hope that helps!

Title: Layout of mathematical views (iOS)


答:
I doubt you're wrong and I think anyone in the industry would anecdotally confirm both that there is variations between programmers and devs, but I think the issue is much more interesting than that. The article you linked brings of an interesting point: you are not likely to find a good metric of productivity that fits all definitions of a developer. The 6 archetypes (ok, 5, because one is a joke) have different criteria - the workhorse may produce more code, but the innovator doesn't because he's thinking of new, crazy ways to do things.  There are different pathways to being a good coder and not everyone agrees what they are.

This probably applies to the variance in your day to day work, too.  You can measure this by, say, KLOCs, but that probably is only a facet of your productivity.  Improving this will improve your productivity, but the kicker is that if your metric/model of productivity doesn't include factors out of your control (meetings, for example) but that are highly correlated with your the factors that are (KLOCs), you may

The original paper measures problem solving on simple, quantifiable puzzles.  It's hard to do that in the real world, so you could use the warm and fuzzy approach of giving yourself a subjective judgment (or your manager) of how productive you were that day - this is likely to be a better measure given the difficulties quantifying this.

If you want to measure it yourself, the answer is probably specific to you and your workplace. Keep a log for a few weeks then have some fun dicing up your data.  A few ideas: to answer your basic question, if you partition the data into two sets randomly and perform a t-test, you can get an idea whether there is day to day variability.  You could bucket your days by day of week and do an ANOVA or pairwise t-tests to see if there are differences on days of the week.

Title: Is there any research about daily differences in productivity by the same programmer?

Body:
There has been a flurry of activity on the internet discussing a huge difference between the productivity of the best programmers versus the productivity of the worst.  Here's a typical Google result when researching this topic: http://www.devtopics.com/programmer-productivity-the-tenfinity-factor/

I've been wondering if there has been any research or serious discussion about differences in day-to-day productivity by the same programmer.

I think that personally, there is a huge variance in how much I can get done on a day by day basis, so I was wondering if anyone else feels the same way or has done any research.


答: I don't see how it would be even possible to get anything even remotely statistically valid around that. There is so much variance based on what types of tasks you are assigned on a particular day. If I am doing mostly simple stuff, I can certainly get more accomplished, but when I am working on some thing that requires a lot of research, it would appear to be making less progress. Same thing with client meetings, sending requirements back, good vice poor BAs or account managers, etc. WHat I am trying to say is there are so many possible factors to affect productivity, that it is an unswerable question.</p>


问:
It's ok to study the C++ from a book that only support the 1998 version of standard?
I have this big book that basically covers all the main aspects of the C++, the problem is that is pretty old according to the C++ standards of today, it's ok to use it?</p>

答:
It's fine to use it. You won't get the most up-to-the-minute information, but the large majority of C++ is the same language that it was in 1998. If you're just learning the basics, go right ahead. Just keep in mind that there have been some refinements, and look for resources that explain the differences so that you're aware of them.

Here are a few of those resources:

Wikipedia article on C++11 summarizes the new features in C++11.

AT&T's C++11 FAQ

Bjarne Stroustrup's C++ FAQ, which covers a lot of C++ stuff

ContentLicense: CC BY-SA 4.0


问:
Fix bugs, or wait for the customer to find them?
Do other people fix bugs when they see them, or do they wait until there's crashes/data loss/people die before fixing it?

Example 1

```<code> Customer customer = null;
 ...
 customer.Save();
</code>```

The code is clearly wrong, and there's no way around it - it's calling a method on a null reference. It happens to not crash because Save happens to not access any instance data; so it's just like calling a static function. But any small change anywhere can suddenly cause broken code that doesn't crash: to start crashing.

But, it's also not inconceivable that correcting the code:

```<code>Customer customer = null;
...
customer = new Customer();
try
   ...
   customer.Save();
   ...
finally
   customer.Free();
end;
</code>```

might introduce a crash; one not discovered through unit tests with complete coverage, and manual user testing.

Example 2

```<code>float speed = 0.5 * ((G * mass1 * mass2) / R) * Pow(time, 2);
</code>```

People knowing physics will recognize that it's supposed to be R2 in the denominator.

The code is wrong, it's absolutely wrong. And overestimating the speed will cause the retro-rockets to fire too soon, killing all the occupants of the spacecraft.

But it's also possible perhaps having it over-estimate the speed is masking another issue: the air-bags can't deploy while the shuttle is moving too fast. If we suddenly fix the code:

```<code>float speed = 0.5 * ((G * mass1 * mass2) / Pow(R, 2)) * Pow(time, 2);
</code>```

Now the speed is accurate, and suddenly airbags are deploying when they shouldn't.

Example 3

Here's an example that i had recently, checking if a string contains invalid characters:

```<code>if (StrPos(Address, "PO BOX") >= 0)
{
   //Do something
}
</code>```

What if it turns out there's a bug in the Do something branch? Fixing the obviously incorrect code:

```<code>if (StrPos("PO BOX", Address) >= 0)
{
   //Do something
}
</code>```

Fixes the code, but introduces a bug.

The way I see it there are two possibilities:

fix the code, and get blamed for breaking it

wait for the code to crash, and get blamed for having a bug

What do you politically do?

Example 4 - Today's real world bug

I am constructing an object, but calling the wrong constructor:

```<code>Customer customer = new Customer();
</code>```

Turns out that the "parameterless" constructor is actually an parameterized constructor from  further back in the inheritance chain:

```<code>public Customer(SomeObjectThatNobodyShouldBeUsingDirectly thingy = null)
public Customer(InjectedDependancy depends)
</code>```

Calling it is a mistake, since it bypasses all the subsequent constructors.

I could change the object's lineage to not expose such a dangerous constructor, but now I have to change the code to:

```<code>Customer customer = new Customer(depends);
</code>```

But I can't guarantee that this change won't break anything. Like my Example 1 above, perhaps someone, somewhere, somehow, under some esoteric conditions, depends on the constructed Customer to be invalid and full of junk.

Perhaps the Customer object, now that it is properly constructed will allow some code to run that previously never did, and now I can get a crash.

I can't bet your wife's life on it.

And I can test it from here to Tuesday, I can't swear on your daughter's life that I didn't introduce a regression.

Do I:

Fix the code and get blamed for breaking it? or

Leave the bug, and get blamed when the customer finds it?

答:
All of the examples you gave seem to to have a common thread. You seem want to fix a bug that you don't fully understand. I say that because you note the possibility of unintended consequences on each one.

I would say its probably a huge mistake and as Ben Laurie writes don't fix a bug you don't understand. In this famous example the Debian team broke the encryption for OpenSSL for Debian and derivatives like Ubuntu when they followed the results of an analysis tool.

If you believe there is a defect by looking at code make sure you can reproduce the defect in a way that the customer can see. If you can't why not spend your resources fixing something else.


答:
One type of testing that I have particularly seen devlopers fail at is testing if the requirement has been met. What devlopers think something in a requirement means and what testers think it means are often two completely different things.

I can think of one just recently where the develoepr was asked to do a delta export and the dev thought that meant to get any records that had not been sent once and the testers thought it mean get any new recrds and any changes. They had to go back to the client to find out who was correct. I code reviewed it and I made the same assumption that the dev did about the requirement. Because logically if you wanted to include updates, you would have mentioned them. And I'm usually good at spotting those ambiguous things because I used to be on the user end of things.

So other devs doing the testing would tend to make many of the same assumptions because they too would make certain assumptions like "well they would have had more detail if they mean X vice Y because there are so many details to be answered before I could do it.   But requirements writers don't think that way. So someone who thinks more like requirements writers needs to test the developer assumptions and someone who is not a developer is the better person to even see there is an issue.

Title: Are programmers bad testers?

Body:
I know this sounds a lot like other questions which have already being asked, but it is actually slightly different. It seems to be generally considered that programmers are not good at performing the role of testing an application. For example:

Joel on Software - Top Five (Wrong) Reasons You Don't Have Testers (emphasis mine)

Don't even think of trying to tell college CS graduates that they can
  come work for you, but "everyone has to do a stint in QA for a while
  before moving on to code". I've seen a lot of this. Programmers do not
  make good testers, and you'll lose a good programmer, who is a lot
  harder to replace.

And in this question, one of the most popular answers says (again, my emphasis):

Developers can be testers, but they shouldn't be testers. Developers
  tend to unintentionally/unconciously avoid to use the application in a
  way that might break it. That's because they wrote it and mostly test
  it in the way it should be used.

So the question is are programmers bad at testing? What evidence or arguments are there to support this conclusion? Are programmers only bad at testing their own code? Is there any evidence to suggest that programmers are actually good at testing?

What do I mean by "testing?" I do not mean unit testing or anything that is considered part of the methodology used by the software team to write software. I mean some kind of quality assurance method that is used after the code has been built and deployed to whatever that software team would call the "test environment."


答:
I found a study that focus specifically on the difference in productivity on a day to day basis in the work place.  After a cursory reading, it seems that the study suggests there are variances in efficiency on a day to day basis.  The data gathered seems to point to Monday being the most work-producing day, Tuesday-Thursday are not far behind, and Friday being about 2/3rds as efficient.  Saturday is about half that of Friday and barely any work is done on Sunday.

It also points out, as many of the answers have, that this is a very difficult thing to measure as there are tons of factors that apply.  This study is also not specific to computer science or related fields.


答:
C++11 is a pretty big deal- not to mention that many books back in 98 taught C with Classes, rather than C++. I'd look for something newer. We have a question on Stack Overflow which supplies recommendations for books worth possessing.

Edit: Of course, there are also many new C++ techniques which simply did not exist previously, especially where templates are concerned, and there are some idioms which are no longer, like checking for self-assignment, not to mention global changes in the software industry like pushes for parallelism.

Title: It's ok to study the C++ from a book that only support the 1998 version of standard?

Body: I have this big book that basically covers all the main aspects of the C++, the problem is that is pretty old according to the C++ standards of today, it's ok to use it?</p>


答:
It's probably better to learn the old version first:

It may be a while before C++11 is fully supported by the latest version of your favorite compiler.  Or the compiler your particular project requires you to use.

Code written before C++11 won't use it.  It may be a while (as in, "possibly never") before any given project migrates to C++11.

In order to understand the reasoning behind the design of C++11, it is probably best to understand the original form of the language.

At any rate, if you don't learn the old version first, you may have a hard time figuring out how to write for any system that doesn't fully support the new one.  For that matter, I would recommend learning C first, before learning the old version of C++:  it will save you many agonizing moments of "why the hell did they do it like that?"


问:
Copyrighting software, templates, etc. under real name or screen name?
My question is hopefully simple - should I copyright my work (art, software, web design, etc.) under my real name or my screen name? My real name and screen name are also easily connected with a bit of searching, so does it really matter in the end?

I'm not a professional (at this point).

I read this question and they recommended releasing on the app market under a company name.

I also read this question, but that didn't answer my question.

I know it probably matters for big projects, but for little projects, does it matter?

答:
The real question is, what are you trying to protect, and can you protect it?  You're probably trying to provide yourself with the ability to claim that you own the thing you've built, and that you want to have control over how it is used (i.e., you own the copyright and you license the thing's use).  So ask yourself:  How are you going to prove to an adversary who already wants to avoid your restrictions that you are indeed uB3rC0d3R69?  You might need to do so in court - how will you approach that?

You're better off using your real name, or if you want to hide, using a corporate entity of some sort (in the USA, LLCs are the easiest to set up).  When you want to "pierce the veil", you'll already have established the relationship between you and it.


问:
Communication between state machines with hidden transitions
The question emerged for me in embedded programming but I think it can be applied to quite a number of general networking situations e.g. when a communication partner fails.

Assume we have an application logic (a program) running on a computer and a gadget connected to that computer via e.g. a serial interface like RS232. The gadget has a red/green/blue LED and a button which disables the LED. The LEDs color can be driven by software commands over the serial interface and the state (red/green/blue/off) is read back and causes a reaction in the application logic. Asynchronous behaviour of the application logic with regard to the LED color down to a certain delay (depending on the execution cycle of the application) is tolerated.

What we essentially have is a resource (the LED) which can not be reserved and handled atomically by software because the (organic) user can at any time press the button to interfere/break the software attempt to switch the LED color.

Stripping this example from its physical outfit I dare to say that we have two communicating state machines A (application logic) and G (gadget) where G executes state changes unbeknownst to A (and also the other way round, but this is not significant in our example) and only A can be modified at a reasonable price. A needs to see the reaction and state of G in one piece of information which may be (slightly) outdated but not inconsistent with respect to the short time window when this information was generated on the side of G.

What I am looking for is a concise method to handle such a situation in embedded software (i.e. no layer/framework like CORBA etc. available). A programming technique which is able to map the complete behaviour of both participants on classical interfaces of a classical programming language (C in this case). To complicate matters (or rather, to generalize), a simple high frequency communication cycle of A to G and back (IOW: A is rapidly polling G) is out of focus because of technical restrictions (delay of serial com, A not always active, etc.).
What I currently see as a general solution is:

the application logic A as one thread of execution

an adapter object (proxy) PG (presenting G inside the computer), together with the serial driver as another thread

a communication object between the two (A and PG) which is transactionally safe to exchange

The two execution contexts (threads) on the computer may be multi-core or just interrupt driven or tasks in an RTOS.
The com object contains the following data:

suspected state (written by A): effectively a member of the power set of states in G (in our case: red, green, blue, off, red_or_green, red_or_blue, red_or_off...etc.)

command data (written by A): test_if_off, switch_to_red, switch_to_green, switch_to_blue

operation status (written by PG): operation_pending, success, wrong_state, link_broken

new state (written by PG): red, green, blue, off

The idea of the com object is that A writes whichever (set of) state it thinks G is in, together with a command. (Example: suspected state="red_or_green", command: "switch_to_blue") Notice that the commands issued by A will not work if the user has switched off the LED and A needs to know this. PG will pick up such a com object and try to send the command to G, receive its answer (or a timeout) and set the operation status and new state accordingly. A will take back the oject once it is no longer at operation_pending and can react to the outcome. The com object could be separated of course (into two objects, one for each direction) but I think it is convenient in nearly all instances to have the command close to the result.

I would like to have major flaws pointed out or hear an entirely different view on such a situation.

答:
The hidden transitions and the latency make this a pretty interesting problem, especially since you can't modify the gadget. You may be looking for a synchronizing sequence or a homing sequence. ("Synchronization" means you can issue some sequence of commands, and be sure of the state of the target state machine when you're done. "Homing" means that you can issue some sequence of commands, then verify the state by examining the output of the state machine).

Sven Sandberg has a pretty good paper showing that (for any well-defined Mealy machine) you can always construct these two types of sequences. It's all theory, no code, so you'll have to do some implementation. Here's the citeseer reference to the paper itself, and a PDF slideshow of the ideas.

In the case you describe, latency is still an issue. I'm curious to know if you have some idea of the margin of error on these "hidden" state changes. How long between them? Are they more common, or more frequent, in some cases than others? Answers to these questions can help you define these control sequences.


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

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

答: Programmers don't quit, they just go offline. :)

LastEditorDisplayName: Roger Pate

ContentLicense: CC BY-SA 2.5


问:
if you were asked to answer to the question " what is the difference between the English language and a programming language" how you will respond?
Basically in both cases you have:

a well defined vocabulary

a syntax to respect

they both can express a business logic

they can define semantics

I don't think that will be fair to say "A programming language is only useful for a PC" or something like that.

I just can't find a real answer, but we can feel the difference, it's strange.

答:
The essential distinction, I would say, is formally-defined syntax and semantics.

A programming language can be parsed by an automated tool according to formal rules, and found to either have meaning according to those rules, or be invalid and therefore worthless.  And if it does have meaning, it means exactly what the formal rules say it means and nothing else.

A human language, on the other hand, is not understood formally but intuitively.  You can mutilate the grammar to a pretty high degree and the person you're talking to will still understand what you mean, and what you mean (and are understood to mean) is frequently not precisely what you said.

As a side note, this tends to make natural language extremely difficult to parse. It remains one of the great unsolved problems of artificial intelligence, despite being one of the ones they've been working on the longest!


答:
"A programming language is only useful for a PC" isn't fair you're right.

Fair way to state the difference would be

A programming language is also useful for a PC

The point is, programming language (just like English) is primarily intended to be read / communicated by humans, but unlike English, it has a cumbersome limitation that it has to allow for machine execution.

...Writing code certainly feels very similar to writing poetry. When I'm writing poetry, it feels like the center of my thinking is in a particular place, and when I'm writing code the center of my thinking feels in the same kind of place. It's the same kind of concentration. So, I'm thinking up possibilities, I'm thinking about, well, so how do I reinvent the code, gee, you know, what's the simplest way to do this.

I'm thinking about things like simplicity -- how easy is it going to be for someone to look at it later? How well is it fulfilling the overall design that I have in mind? How well does it fit into the architecture? If I were writing a very long poem with many parts, I would be thinking, "Okay, how does this piece fit in with the other pieces? How is it part of the bigger picture?" When coding, I'm doing similar things, and if you look at the source code of extremely talented programmers, there's beauty in it. There's a lot of attention to compression, using the underlying programming language in a way that's easy to penetrate. Yes, writing code and writing poetry are similar...

         (Richard Gabriel, Janice J. Heiss, The Poetry of Programming)

...Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.

The practitioner of literate programming can be regarded as an essayist, whose main concern is with exposition and excellence of style. Such an author, with thesaurus in hand, chooses the names of variables carefully and explains what each variable means. He or she strives for a program that is comprehensible because its concepts have been introduced in an order that is best for human understanding...

         (Donald E. Knuth, Literate Programming)

Title: if you were asked to answer to the question " what is the difference between the English language and a programming language" how you will respond?

Body:
Basically in both cases you have:

a well defined vocabulary

a syntax to respect

they both can express a business logic

they can define semantics

I don't think that will be fair to say "A programming language is only useful for a PC" or something like that.

I just can't find a real answer, but we can feel the difference, it's strange.


答:
Here's a biggie:

Mason has already said this, but:  Formal languages have formally defined semantics.  Human languages don't.  It's not still really well understood how humans extract semantics despite the fact that this has been studied for decades by linguists, philosophers and psychologists.

I think it's pretty obvious that formal languages lack the semantic richness of even simple natural language.  "The cat jumped over the lazy dog" encodes and is dependent on far more information about the world than just the definitions of the words and the syntax alone.  Formal languages lack the syntactic and semantic ambiguity that is possible with natural language as well.


问:
How to refactor a method which breaks "The law of Demeter" principle?
I often find myself breaking this principle (not intentially, just through bad design).  However recently I've seen a bit of code that I'm not sure of the best approach.

I have a number of classes.  For simplicity I've taken out the bulk of the classes methods etc

```<code>public class  Paddock
{
    public SoilType Soil { get; private set; }

    // a whole bunch of other properties around paddock information
}

public class SoilType
{
    public SoilDrainageType Drainage { get; private set; }

    // a whole bunch of other properties around soil types
}

public class SoilDrainageType
{
    // a whole bunch of public properties that expose soil drainage values

    public double GetProportionOfDrainage(SoilType soil, double blockRatio)
    {
        // This method does a number of calculations using public properties
        // exposed off SoilType as well as the blockRatio value in some conditions
    }
}
</code>```

In the code I have seen in a number of places calls like so

```<code>paddock.Soil.Drainage.GetProportionOfDrainage(paddock.Soil, paddock.GetBlockRatio());
</code>```

or within the block object itself in places it's

```<code>Soil.Drainage.GetProportionOfDrainage(this.Soil, this.GetBlockRatio());
</code>```

Upon reading this seems to break "The Law of Demeter" in that I'm chaining together these properties to access the method I want.  So my thought in order to adjust this was to create public methods on SoilType and Paddock that contains wrappers i.e.

on paddock it would be

```<code>public class Paddock
{
   public double GetProportionOfDrainage()
   {
      return Soil.GetProportionOfDrainage(this.GetBlockRatio());
   }
}
</code>```

on the SoilType it would be

```<code>public class SoilType
{
   public double GetProportionOfDrainage(double blockRatio)
   {
      return Drainage.GetProportionOfDrainage(this, blockRatio);
   }
}
</code>```

so now calls where it used would be simply

```<code>// used outside of paddock class where we can access instances of Paddock
paddock.GetProportionofDrainage()
</code>```

or
    this.GetProportionOfDrainage(); // if used within Paddock class

This seemed like a nice alternative.  However now I have a concern over how would I enforce this usage and stop anyone else from writing code such as

```<code>paddock.Soil.Drainage.GetProportionOfDrainage(paddock.Soil, paddock.GetBlockRatio());
</code>```

rather than just

```<code>paddock.GetProportionOfDrainage();
</code>```

I need the properties to remain public at this stage as they are too ingrained in usage throughout the code block.  However I don't really want a mixture of accessing the method on DrainageType directly as that seems to defeat the purpose altogether.

What would be the appropiate design approach in this situation?  I can provide more information as required to better help in answers.

Is my thoughts on refactoring this even appropiate or should is it best to leave it as is and use the property chaining to access the method as and when required?

答:
It seems to me that the issue is in part due to the GetProportionOfDrainage being probably the wrong method. It seems strange that you're having to pass all this information in through multiple levels of object in the first place. Surely it would be better to make the SoilType the focus for those sorts of computations, with it asking the DrainageType instance for just the information it is an expert on.

Once you've done that, you just have to deal with the complexities of real paddocks. I believe they're not all flat and don't always have a single soil type. Thus, the application of the ratios might need to be the responsibility of the Paddock, as that knows about such information. (I assume that this is a proxy for the real model, yes?)


问:
ORM has schema to generate classes, does the reverse exist?
In Entity-Framework, you can create a DB schema, and then generate your ORM classes.  Is there any software that does this in reverse?  For example you create a few classes that have relationships, and software generates a database schema with the relevant primary and foreign key relationships?    </p>

答:
I've done this with DataNucleus/JDO, with Derby as the underlying database engine. It works, but you have to be ever so careful when doing it because effectively your classes are the schema and need to be subject to the usual level of carefulness with schema management.

I'm not sure I'd do it the same way again if I was starting out afresh.


答:
Every profession has this same variability. Baseball pitchers throw perfect games, or get pulled after a few innings; Doctors save lives, or make a mistake in surgery; Comedians get a standing ovation, or exit the stage to silence.

Besides the obvious: caffeine levels,  amount of sleep; there is also just luck. If your coworker asks just the right question it can be the clue to solving a problem that has stumped you for days.

In the US they give the same advice before standardized tests "get plenty of sleep, and have a good breakfast". While this is good advice regarding general productivity, it doesn't guarantee success.

Everybody has a time of the day where they feel the most productive, or the most artistic, or the most clearheaded. Unfortunately it is not the same time of day for everybody.

I don't see how knowing that for programmers the best 4 hour block is Wednesday from 10:17 to 14:17 local helps.


答:
Ask a strange question and you get a strange answer :) Here are some differences (INMO)!
 - Add to the list the fact that recursion is meaningful to computers only and not to humans.


答:
When I was a prof 30 years ago there would be these Faculty Colloquia or off-site weekends where some profs from around the university would get invited, with deans, for fancy food and "collegial" discussions.
Read: b o r i n g.

Once the question was raised: Should a computer language be allowed as a substitute for the foreign language requirement?

This drove me nuts.
To think that learning BASIC or PASCAL (at the time) was even on the chart, compared to learning French, German, or another human language and culture, seemed preposterous.

Technology is beautiful. It has a depth of meaning that can't really be imagined outside of it.
At the same time, it is easy just to think of it as a means to an end - a way to engineer our mechanical slaves.

What is there in programming that can compare to a poem, or a novel?
When you learn a human language, it is not just a vocabulary, syntax, etc.
It is a window on history, culture, beauty, what makes life interesting.


答:
Yes, it is available in EF starting from version EF 4.1.

You can do it with Entity Framework, using Code First.

EF 4.3 even has Migrations built-in.

Title: ORM has schema to generate classes, does the reverse exist?

Body: In Entity-Framework, you can create a DB schema, and then generate your ORM classes.  Is there any software that does this in reverse?  For example you create a few classes that have relationships, and software generates a database schema with the relevant primary and foreign key relationships?    </p>


答:
I am going to advocate learning C++11, not older versions. It's true that the large majority of the language syntax and semantics will be the same and it's true that there's virtually no C++ 11 codebases in the roughly gazillion lines out in the wild. So, yes, it's true that you're essentially learning a new and not-yet-common dialect and that may be a disadvantage if you are quickly charged with doing something with an older dialect.

But the new dialect is better and simpler. The problem, I think, is that when you do go and deal with an older codebase, you may be confused by "Why didn't they just use...?" thoughts. But the flipside is that if you learn an old dialect, as a beginner you are poorly prepared to know "Oh, okay, this template thing is replaced by a much simpler lambda thing..."  and you can find yourself dealing with some really hairy-looking code.

It's true that compiler support is still patchy, but I think everyone has auto and lambdas and range-based for and support shared_ptr/unique_ptr/weak_ptr. So there's a lot of really big wins that are widely available.

(It's true, though, that if you're just using a book, you probably won't be exposed to the full glorious melange of idioms you see in a legacy codebase.)


问:
How to manage a developer who has poor communication skills
I manage a small team of developers on an application which is in the mid-point of its lifecycle, within a big firm. This unfortunately means there is commonly a 30/70 split of Programming tasks to "other technical work". This work includes:

Working with DBA / Unix / Network / Loadbalancer teams on various tasks

Placing and managing orders for hardware or infrastructure in different regions

Running tests that have not yet been migrated to CI

Analysis

Support / Investigation

Its fair to say that the Developers would all prefer to be coding, rather than doing these more mundane tasks, so I try to hand out the fun programming jobs evenly amongst the team.

Most of the team was hired because, though they may not have the elite programming skills to write their own compiler / game engine / high-frequency trading system etc., they are good communicators who "can get stuff done", work with other teams, and somewhat navigate the complex bureaucracy here. They are good developers, but they are also good all-round technical staff.

However, one member of the team probably has above-average coding skills, but below-average communication skills. Traditionally, the previous Development Manager tended to give him the Programming tasks and not the more mundane tasks listed above. However, I don't feel that this is fair to the rest of the team, who have shown an aptitude for developing a well-rounded skillset that is commonly required in a big-business IT department.

What should I do in this situation? If I continue to give him more programming work, I know that it will be done faster (and conversely, I would expect him to complete the other work slower). But it goes against my principles, and promotes the idea that you can carve out a "comfortable niche" for yourself simply by being bad at the tasks you don't like.

I want to clarify that I'm not trying to address this issue due to a grudge, or that I have a "chip on my shoulder" as was mentioned. I'm looking for advice on how to keep a well-rounded team, which is happy and motivated. By observing the variety of answers to this question, it seems like there are a lot of different opinions on how to achieve this.

答:
30/70 split may be where all your problems begin. I've never seen developers happy with split like that.

I've seen developers being comfortable with 10, 15% other work (and been happy myself because it's fun when the dose is right) but 30% is too much. I'd rather think other team members prefer not to speak their mind than there is only one who dislikes "30% other work".

I also think it is important to adjust your "productivity math" to more realistic figures. It will never add up to 100% because of inevitable losses at "context switches".

30+70, summing up to 100% productivity when switching between programming and other work, will never happen in real life; it is more likely about 20+50 or even 20+40. Context switches are especially painful for software developers - if you're interested, check this article for a nice explanation of why is that: DON'T WAKE UP THE PROGRAMMER!

Programmers who value their productivity would naturally be unhappy about losses like that.

As for running tests part of job, did you consider passing it to testers? The fact that programmers can do it (I think any experienced programmer should be capable of that) does not mean they should. Testers can do it too, and they do it better, and they won't suffer productivity losses at "context switches".

Another point that makes me wonder how you utilize QA resources is your mentioning of Support / Investigation. Professional testers I used to work with tend to have "first say" in stuff like that.

As an ex-tester myself, I understand them pretty well - production issues have been to me (as a tester) an invaluable source of data to learn about testing coverage ("have this issue been properly covered by my tests?") and for defects prioritization ("okay it's been covered by tests and reported before release, but did I set the appropriate priority / severity back then?").

It's quite easy for a good tester to find out when to pass the support issue investigation to developers, and this does not happen very often. Reasons to overload developers with this simply escape my mind. As I already wrote, they sure can do that (I'd generally expect senior developer to know how to do anything QA does) but that does not mean they should.


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

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

答:
The field has certainly embraced specialization of labour. Grades achieved need to be good enough to get you to the interview, and after that, it is all a matter of technical mastery.

In the past most coders were generalists and academic achievement over a broad area of subject matter was considered to be of high importance, however, these days it is largely about specialization within a smaller subset of skills.


问:
Is this a decent use-case for goto in C?
I really hesitate to ask this, because I don't want to "solicit debate, arguments, polling, or extended discussion" but I'm new to C and want to gain more insight into common patterns used in the language.

I recently heard some distaste for the goto command, but I've also recently found a decent use-case for it.

Code like this:

```<code>error = function_that_could_fail_1();
if (!error) {
    error = function_that_could_fail_2();
    if (!error) {
        error = function_that_could_fail_3();
        ...to the n-th tab level!
    } else {
        // deal with error, clean up, and return error code
    }
} else {
    // deal with error, clean up, and return error code
}
</code>```

If the clean-up part is all very similar, could be written a little prettier (my opinion?) like this:

```<code>error = function_that_could_fail_1();
if(error) {
    goto cleanup;
}
error = function_that_could_fail_2();
if(error) {
    goto cleanup;
}
error = function_that_could_fail_3();
if(error) {
    goto cleanup;
}
...
cleanup:
// deal with error if it exists, clean up
// return error code
</code>```

Is this a common or acceptable use-case of goto in C? Is there a different/better way to do this?

答:
Yes.

It is used in, for example, the linux kernel.  Here's an email from the end of a thread from nearly a decade ago, bolding mine:

From: Robert Love

  Subject: Re: any chance of 2.6.0-test*?

  Date:     12 Jan 2003 17:58:06 -0500

  On Sun, 2003-01-12 at 17:22, Rob Wilkens wrote:

I say "please don't use goto" and instead have a "cleanup_lock" function
    and add that before all the return statements..  It should not be a
    burden.  Yes, it's asking the developer to work a little harder, but the
    end result is better code.

No, it is gross and it bloats the kernel.  It inlines a bunch of junk
  for N error paths, as opposed to having the exit code once at the end.
  Cache footprint is key and you just killed it.

Nor is it easier to read.

As a final argument, it does not let us cleanly do the usual stack-esque
  wind and unwind, i.e.

```<code>        do A
        if (error)
            goto out_a;
        do B
        if (error)
            goto out_b;
        do C
        if (error)
            goto out_c;
        goto out;
        out_c:
        undo C
        out_b:
        undo B:
        out_a:
        undo A
        out:
        return ret;
</code>```

Now stop this.

Robert Love

That said, it requires a lot of discipline to keep yourself from creating spaghetti code once you get used to using goto, so unless you're writing something that requires speed and a low memory footprint (like a kernel or embedded system) you should really think about it before you write the first goto.

Body:
Yes.

It is used in, for example, the linux kernel.  Here's an email from the end of a thread from nearly a decade ago, bolding mine:

From: Robert Love

  Subject: Re: any chance of 2.6.0-test*?

  Date:     12 Jan 2003 17:58:06 -0500

  On Sun, 2003-01-12 at 17:22, Rob Wilkens wrote:

I say "please don't use goto" and instead have a "cleanup_lock" function
    and add that before all the return statements..  It should not be a
    burden.  Yes, it's asking the developer to work a little harder, but the
    end result is better code.

No, it is gross and it bloats the kernel.  It inlines a bunch of junk
  for N error paths, as opposed to having the exit code once at the end.
  Cache footprint is key and you just killed it.

Nor is it easier to read.

As a final argument, it does not let us cleanly do the usual stack-esque
  wind and unwind, i.e.

        do A
        if (error)
            goto out_a;
        do B
        if (error)
            goto out_b;
        do C
        if (error)
            goto out_c;
        goto out;
        out_c:
        undo C
        out_b:
        undo B:
        out_a:
        undo A
        out:
        return ret;

Now stop this.

Robert Love

That said, it requires a lot of discipline to keep yourself from creating spaghetti code once you get used to using goto, so unless you're writing something that requires speed and a low memory footprint (like a kernel or embedded system) you should really think about it before you write the first goto.


问:
For a Javascript library, what is the best or standard way to support extensibility
Specifically, I want to support "plugins" that modify the behavior of parts of the library.

I couldn't find much information on the web about this subject. But here are my ideas for how a library could be extensible.

The library exports an object with both public and "protected" functions. A plugin can replace any of those functions, thus modifying the library's behavior. Advantages of this method are that it's simple and that the plugin's functions can have full access to the library's "protected" functions. Disadvantages are that the library may be harder to maintain with a larger set of exposed functions and it could be hard to debug if multiple plugins are involved (how to know which plugin modified which function?).

The library provides an "add plugin" function that accepts an object with a specific interface. Internally, the library will use the plugin instead of it's own code if appropriate. With this method, the internals of the library can be rearranged more freely as long as it still supports the same plugin interface. This could also support having different plugin interfaces to modify different parts of the library. A disadvantage of this method is that the plugins may have to re-implement code that is already part of the library since the library's internal functions are not exported.

The library provides a "set implementation" function that accepts an object inherited from a specific base object. The library's public API calls functions in the implementation object for any functionality that can be modified and the base implementation object includes the core functionality, with both external (to the API) and internal functions. A plugin creates a new implementation object, which inherits from the base object and replaces any functions it wants to modify. This combines advantages and disadvantages of both the other methods.

答:
This is an interesting topic that looks similare to the following post - How to extend javascript library through plugins?. I hope that post answers your question.

I would also recommend to loook at Closures for hiding things.


答:
To me, Extensibility means Interchangable_Parts.

At a high-level: to be extensible, over time - some code must
  be added, and some code must be removed. Extensibility is a painless
  system to achieve: addition, reuse, and replacement - over time.

In order to architect extensible systems, fundamental prerequisites exists in knowledge of advanced methodologies. Fortunately many are well documented in JavaScript.

Without specific knowledge of what you are attempting....

Here is a short list:

Modules - AMD.

Design Patterns - MVC, Namespaces.

Loose Coupling - Pub-Sub/Evented Views, App Architecture.

Templates.

Data-binding.

In many ways, a zest to learn the topics above becomes an art over a science.

You will have to:

A. Research many options
  B. Prototype many technologies
  C. Become a JSpolyglot and JSagnostic.
  D. and Fail-Fast, when applying best-fit over personal ideology.

Fail-Fast is based on entrepreneurial tech-companies motto for success. This is beneficial to realize for evolving software. If your software is Modular, you design to improve parts separately. You don't want to invest too much effort on a failing model.

Stub things off that you know you can extend later, and continue extending iteratively. This requires a certain amount of vision and discipline.

Stand on the shoulder of giants. Don't waste your time trying to re-invent the wheel. Use what the social-coding community is generating, and extend upon it. This will give you the best chance at modularity. And, the best chance to incorporate best practice Design Patterns.

Look at what others are doing in regards to plugins. Paul Irish has a few famous documents regarding '10 things I learned from reading jQuery source code.' If you want to write plugins, you should do this too. You should also look at ExtJS, and YUI, with reserved judgement; benefits arise from being agnostic. Each use divergent methodologies that can assist to your need.

Modular architecture. This is the basis for all flexibility. The biggest challenge, i've seen across languages, is to decouple abstracted objects- but then still allow them to communicate. Essentially, this is a non-trivial trade-off.

Here are recommended technologies for separation of concerns:

require.js, backbone.js, underscore.js, GitHub.

There are easily a thousand more. But if you have a single takeaway, it is to look at AMD and require.js. Many people say this is the future for modular JS.

Hopefully there are some terms dropped here that get you searching in the right direction. All the best! Nash

Title: For a Javascript library, what is the best or standard way to support extensibility

Body:
Specifically, I want to support "plugins" that modify the behavior of parts of the library.

I couldn't find much information on the web about this subject. But here are my ideas for how a library could be extensible.

The library exports an object with both public and "protected" functions. A plugin can replace any of those functions, thus modifying the library's behavior. Advantages of this method are that it's simple and that the plugin's functions can have full access to the library's "protected" functions. Disadvantages are that the library may be harder to maintain with a larger set of exposed functions and it could be hard to debug if multiple plugins are involved (how to know which plugin modified which function?).

The library provides an "add plugin" function that accepts an object with a specific interface. Internally, the library will use the plugin instead of it's own code if appropriate. With this method, the internals of the library can be rearranged more freely as long as it still supports the same plugin interface. This could also support having different plugin interfaces to modify different parts of the library. A disadvantage of this method is that the plugins may have to re-implement code that is already part of the library since the library's internal functions are not exported.

The library provides a "set implementation" function that accepts an object inherited from a specific base object. The library's public API calls functions in the implementation object for any functionality that can be modified and the base implementation object includes the core functionality, with both external (to the API) and internal functions. A plugin creates a new implementation object, which inherits from the base object and replaces any functions it wants to modify. This combines advantages and disadvantages of both the other methods.


问:
Why would he say "We don't want to support MVC3"?
I work in a small shop at a fairly big company doing intranet web applications. By small, I mean there is 1 other guy in my position... and he graduated with me last December. (we aren't the only IT, but the only ones in our field)

We are switching out an old COBOL system and converting it's only used application suite to a Web App. My company has contracted to a Web Application firm to help with this process who has chosen ASP.NET MVC, during one of the important meetings I asked if they will be using MVC2 or MVC3. Their lead developer said:

"MVC2, we don't want to support MVC3. haha"

My question is, why is this?

This was several months ago and I've been doing extensive and self training gearing up for the MVC switch. From everything I am understanding, MVC3 is just like MVC2 if you don't use Razor and it fixes a number of smaller bugs that MVC2 had. So in my eyes, I can't see any reason to NOT use MCV3.

There has to be something I'm missing. Since I don't really have any mentors to turn to in the real world, I'm coming here. What problems are there with MVC3 that might possibly lead him to say this that I'm missing?

答:
I have been using MVC 2 for more than 2 years now, and have application in production from early 2011 which works fine. Currently, we are using MVC 3 in our project without any problems. I compiled some posts that shows why MVC3 would be more productive for your project.

MVC 2.0 Vs 3.0 Performance

Introducing ASP.NET MVC 3 (Preview 1)

MVC 3 Project Upgrade Tool

ASP.NET MVC 3 release notes


问:
What popular "best practices" are not always best, and why?
"Best practices" are everywhere in our industry.  A Google search on "coding best practices" turns up nearly 1.5 million results.  The idea seems to bring comfort to many; just follow the instructions, and everything will turn out fine.

When I read about a best practice - for example, I just read through several in Clean Code recently - I get nervous.  Does this mean that I should always use this practice?  Are there conditions attached?  Are there situations where it might not be a good practice?  How can I know for sure until I've learned more about the problem?

Several of the practices mentioned in Clean Code did not sit right with me, but I'm honestly not sure if that's because they're potentially bad, or if that's just my personal bias talking.  I do know that many prominent people in the tech industry seem to think that there are no best practices, so at least my nagging doubts place me in good company.

The number of best practices I've read about are simply too numerous to list here or ask individual questions about, so I would like to phrase this as a general question:

Which coding practices that are popularly labeled as "best practices" can be sub-optimal or even harmful under certain circumstances?  What are those circumstances and why do they make the practice a poor one?

I would prefer to hear about specific examples and experiences.

答:
MVC - i often find that shoehorning many web design problems into the MVC approach is more about making a framework (rails etc) happy than about simplicity or structure. MVC is a favorite of "architecture astronauts" who seem to value excessive scaffolding over simplicity. ymmv.

class-based OO - in my opinion encourages complex structures of mutable state. the only compelling cases i have found for class-based OO over the years are the corny "shape->rectangle->square" examples that form chapter 1 of any OO book


答: A famous paper describing case of valid use of was Structured Programming with GOTO Statement by Donald E. Knuth (Stanford University). The paper appeared in the days where using GOTO was considered a sin by some and when the movement for Structured Programming was the at its peak. You may want to take a look at GoTo Considered Harmful.</p>

Title: Is this a decent use-case for goto in C?

Body:
I really hesitate to ask this, because I don't want to "solicit debate, arguments, polling, or extended discussion" but I'm new to C and want to gain more insight into common patterns used in the language.

I recently heard some distaste for the goto command, but I've also recently found a decent use-case for it.

Code like this:

```<code>error = function_that_could_fail_1();
if (!error) {
    error = function_that_could_fail_2();
    if (!error) {
        error = function_that_could_fail_3();
        ...to the n-th tab level!
    } else {
        // deal with error, clean up, and return error code
    }
} else {
    // deal with error, clean up, and return error code
}
</code>```

If the clean-up part is all very similar, could be written a little prettier (my opinion?) like this:

```<code>error = function_that_could_fail_1();
if(error) {
    goto cleanup;
}
error = function_that_could_fail_2();
if(error) {
    goto cleanup;
}
error = function_that_could_fail_3();
if(error) {
    goto cleanup;
}
...
cleanup:
// deal with error if it exists, clean up
// return error code
</code>```

Is this a common or acceptable use-case of goto in C? Is there a different/better way to do this?


问:
My boss decided to add a "person to blame" field to every bug report. How can I convince him that it's a bad idea?
In one of the latest "WTF" moves, my boss decided that adding a "Person To Blame" field to our bug tracking template will increase accountability (although we already have a way of tying bugs to features/stories). My arguments that this will decrease morale, increase finger-pointing and would not account for missing/misunderstood features reported as bug have gone unheard.

What are some other strong arguments against this practice that I can use? Is there any writing on this topic that I can share with the team and the boss?

答:
Just let it go. Your boss will discover on his own that it causes a problem, if it does.

Lets be blunt, you have an opinion and so does he. He is your manager and his opinion is the one that wins.

Yes you can go to war over this issue, but is it really worth it? I doubt it lasts more than 3 months before it falls into disuse.

But actively sabotaging this or screaming about it just uses up political capital that is better saved for asking for that extra time off, next raise, promotion, or when a really critical design decision is going to be made.

At that moment, when it really counts you do npt want the boss to remember that you were the person who actively sabotaged his idea for "person to blame".

Respect the office even if you do not respect the decision.

Save the stress and table pounding for decisions that are going to be much longer lasting.


答:
Email him this SO question. If he's open to reason, the comments here will provide sanity checks for his reasoning. If he's not reasonable, you're unlikely to convince him with reasons that make sense. Additionally, he'll be able to read the reasons outside of a conversation (which can sometimes be more convincing because of the removed motivation to "be right" in the heat of a conversation).

You could also try to turn it around. The field could be "possible steps to avoid a similar bug from occurring", or something shorter to that effect. Then you could pool up solutions and vote on which ones to implement to make your workplace better. Perhaps a solution-oriented approach is more productive and likely better received (provided that there's actual follow through on the revisiting of suggestions).

Title: My boss decided to add a "person to blame" field to every bug report. How can I convince him that it's a bad idea?

Body:
In one of the latest "WTF" moves, my boss decided that adding a "Person To Blame" field to our bug tracking template will increase accountability (although we already have a way of tying bugs to features/stories). My arguments that this will decrease morale, increase finger-pointing and would not account for missing/misunderstood features reported as bug have gone unheard.

What are some other strong arguments against this practice that I can use? Is there any writing on this topic that I can share with the team and the boss?


答: Purpose of any language is communication, to make your feelings known to other side be it a person or a machine. The basic difference between English language and programming language is the way of communicating the feelings. In programming language you do it in a way you do it with a child, giving parsed information while English is much more complicated than that. You need to make your thoughts understood as per the listener, but here you have a same set of instructions for the system. This is the basic point. Coming now to structure and composition- We use English in our programming languages but is not the other way around. Also neither the structure nor the composition is necessary in English but if you miss this in programs it computer will make your life hell till you correct it according to the predefined set of rules. It is why the programmers are trying to merge English into the Programming language that Artificial Intelligence was born; so as to merge the gap between English and Programming Languages, to make layman understand the machine and machine understand the layman. </p>


问:
Scrum - how to carry over a partially complete User Story to the next Sprint without skewing the backlog
We're using Scrum and occasionally find that we can't quite finish a User Story in the sprint in which it was planned. In true Scrum style, we ship the software anyway and consider including the User Story in the next sprint during the next Sprint Planning session. Given that the User Story we are carrying over is partially complete, how do we estimate for it correctly in the next Sprint Planning session? We have considered:

a) Adjusting the number of Story Points down to reflect just the work which remains to complete the User Story. Unfortunately this will mess up reporting the Product Backlog.

b) Close the partially-completed User Story and raise a new one to implement the remainder of that feature, which will have fewer Story Points. This will affect our ability to retrospectively see what we didn't complete in that sprint and seems a bit time consuming.

c) Not bother with either a or b and continue to guess during Sprint Planning saying things like "Well that User Story may be X story points, but I know it's 95% finished so I'm sure we can fit it in."

答:
I'm surprised there doesn't seem to be a straight answer to this. I was expecting a chorus of "option D, dummy"!

As we haven't seemed to be missing anything obvious, we figured this is one of those decisions each team needs to make for themselves based on how they want to work and what metrics are most important to them.

We decided that keeping accurate records of the user stories we have implemented is essential, as these form the basis for our testing, support documentation and release notes - that rules out option B.

Next we figured that being able to perform sprint planning accurately was essential - that rules out option C.

We have therefore concluded that option A is right for us. We're going to re-estimate the story points for any stories we partially complete in a sprint in order that we can plan for them properly in subsequent sprints. Over time the product backlog will slightly under report the amount of story points we have implemented, but this is going to be less of a problem than any of the other options and could possibly be resolved by changing our record keeping and reporting.


问:
How do I handle a user story that I complete, but with compromise and need to revisit?
I have just fulfilled (is that a good term?) two user stories out of a new project backlog I have just built. These are user registration and password reset, both requiring mail. I need to implement a substitute mail component because my initial choice, and a normally reliable one, wasn't working. Because I was focused on delivering the user stories, not debugging the mail component, I swapped it out to deliver working code at sprint end. Do I now log a new support issue for the mailer, or 're-insert' these stories into the backlog? If I do the latter, am I not introducing too much tech detail into user stories?</p>

答:
If you implemented the user story to the standards defined in the definition of done, then those user stories are finished and shouldn't be put back in the product backlog.

In similar situations I have raised a new user story, but described the requirement for making a technical change in terms of its business benefit, rather than having something purely technical in the product backlog. How about:

"As a developer I want the product to use the company standard email component so that support and maintenance is simplified."

As a developer, you're an actor too and you may have requirements that the system behaves in a particular way when you use (support / change) it. It should always be possible to articulate these in terms of their business benefit and prioritise them with your product owner alongside the implementation of new functionality.


答:
When you're speaking programming language you're speaking data and clear instructions.

When you're speaking English you're having 1 big negotiation over non-data which ends in ambiguous instructions and hidden meanings to data supposedly being clear.


答:
A clever person solves a problem. A wise person avoids it.

    — Albert Einstein

Body:
What's your favourite quote about programming?

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


问:
Do people in non-English-speaking countries code in English?
I've heard it said (by coworkers) that everyone "codes in English" regardless of where they're from. I find that difficult to believe, however I wouldn't be surprised if, for most programming languages, the supported character set is relatively narrow.

Have you ever worked in a country where English is not the primary language?

If so, what did their code look like?

答:
Even for personal projects I tend to use English mostly because it's easier to ask questions about the code on Stack Overflow or other websites. The same goes for my operating system - I only use English. I had a Dutch operating system once, and it's really horrible to google for errors or information.

There is one advantage of coding in another language and that is that you most likely won't run into conflicting or reserved words.


答:
```<code>for (int y=0; y<height; ++y) {
    for (int x=0; x<width; ++x) {
        if (find(x, y)) goto found;
    }
}
found:
</code>```


答:
I also use goto if the alternative do/while/continue/break hackery would be less readable.

gotos have the advantage that their targets have a name and they read goto something;. This may be more readable than break or continue if you're not actually stopping or continuing something.


答:
The goto statement (and its corresponding labels) are a flow control primitive (along with conditional execution of a statement). By that, I mean that they are there to allow you to construct program flow control networks. You can think of them as modeling the arrows between the nodes of a flowchart.

Some of these can be optimized out immediately, where there is a direct linear flow (you just use a sequence of basic statements). Other patterns are best replaced with structured programming constructs where these are available; if it looks like a while loop, use a while loop, OK? The structured programming patterns are definitely at least potentially clearer of intent than a mess of goto statements.

Yet C does not include all possible structured programming constructs. (It's not clear to me that all relevant ones have been discovered yet; the rate of discovery is slow now, but I'd hesitate to jump to saying that all have been found.) Of the ones we know about, C definitely lacks the try/catch/finally structure (and exceptions too). It also lacks multi-level break-from-loop. These are the kinds of things which a goto can be used to implement. It's possible to use other schemes to do these too — we do know that C has a sufficient set of non-goto primitives — but these often involve creating flag variables and much more complex loop or guard conditions; increasing the entanglement of the control analysis with the data analysis makes the program harder to understand overall. It also makes it more difficult for the compiler to optimize and for the CPU to execute rapidly (most flow control constructs — and definitely goto — are very cheap).

Thus, while you shouldn't use goto unless needed, you should be aware that it exists and that it may be needed, and if you need it, you shouldn't feel too bad. An example of a case where it is needed is resource deallocation when a called function returns an error condition. (That is, try/finally.) It's possible to write that without goto but doing that can have downsides of its own, such as the problems of maintaining it. An example of the case:

```<code>int frobnicateTheThings() {
    char *workingBuffer = malloc(...);
    int i;

    for (i=0 ; i<numberOfThings ; i++) {
        if (giveMeThing(i, workingBuffer) != OK)
            goto error;
        if (processThing(workingBuffer) != OK)
            goto error;
        if (dispatchThing(i, workingBuffer) != OK)
            goto error;
    }

    free(workingBuffer);
    return OK;

  error:
    free(workingBuffer);
    return OOPS;
}
</code>```

The code could be even shorter, but it's enough to demonstrate the point.

Body:
The goto statement (and its corresponding labels) are a flow control primitive (along with conditional execution of a statement). By that, I mean that they are there to allow you to construct program flow control networks. You can think of them as modeling the arrows between the nodes of a flowchart.

Some of these can be optimized out immediately, where there is a direct linear flow (you just use a sequence of basic statements). Other patterns are best replaced with structured programming constructs where these are available; if it looks like a while loop, use a while loop, OK? The structured programming patterns are definitely at least potentially clearer of intent than a mess of goto statements.

Yet C does not include all possible structured programming constructs. (It's not clear to me that all relevant ones have been discovered yet; the rate of discovery is slow now, but I'd hesitate to jump to saying that all have been found.) Of the ones we know about, C definitely lacks the try/catch/finally structure (and exceptions too). It also lacks multi-level break-from-loop. These are the kinds of things which a goto can be used to implement. It's possible to use other schemes to do these too — we do know that C has a sufficient set of non-goto primitives — but these often involve creating flag variables and much more complex loop or guard conditions; increasing the entanglement of the control analysis with the data analysis makes the program harder to understand overall. It also makes it more difficult for the compiler to optimize and for the CPU to execute rapidly (most flow control constructs — and definitely goto — are very cheap).

Thus, while you shouldn't use goto unless needed, you should be aware that it exists and that it may be needed, and if you need it, you shouldn't feel too bad. An example of a case where it is needed is resource deallocation when a called function returns an error condition. (That is, try/finally.) It's possible to write that without goto but doing that can have downsides of its own, such as the problems of maintaining it. An example of the case:

int frobnicateTheThings() {
    char *workingBuffer = malloc(...);
    int i;

    for (i=0 ; i<numberOfThings ; i++) {
        if (giveMeThing(i, workingBuffer) != OK)
            goto error;
        if (processThing(workingBuffer) != OK)
            goto error;
        if (dispatchThing(i, workingBuffer) != OK)
            goto error;
    }

    free(workingBuffer);
    return OK;

  error:
    free(workingBuffer);
    return OOPS;
}

The code could be even shorter, but it's enough to demonstrate the point.


问:
Which pattern to use with a typical Web Form?
I am writing a simple ASP.NET Web Forms application. I want to improve the code by implementing any design pattern with which abstraction is achieved and increases manageability and understandability.

Which pattern is recommended? Please also provide links to sample applications.

答:
You might consider using the Model-View-View Model MVVM pattern.  It is a derivative of MVC, but is designed / intended to be used in exactly the situation you describe.  There is a wealth of information on the MSDN site if you don't feel like googling it.

MVVM facilitates a clear separation of the development of the graphical user interface
  (either as markup language or GUI code) from the development of the business logic or back
  end logic known as the model (also known as the data model to distinguish it from the view
  model). The view model of MVVM is a value converter meaning that the view model is
  responsible for exposing the data objects from the model in such a way that those objects
  are easily managed and consumed. In this respect, the view model is more model than view,
  and handles most if not all of the view’s display logic (though the demarcation between
  what functions are handled by which layer is a subject of ongoing discussion and
  exploration). The view model may also implement a mediator pattern organising access to the
  backend logic around the set of use cases supported by the view.


答:
With ASP.NET Web Form, you typically use the Model View Presenter pattern.

GlenH7 mentioned in his answer MVVM; while it is an elegant pattern, ASPX Webform just doesn't have great support for that. MVVM is more popular in the WPF world.

Title: Which pattern to use with a typical Web Form?

Body:
I am writing a simple ASP.NET Web Forms application. I want to improve the code by implementing any design pattern with which abstraction is achieved and increases manageability and understandability.

Which pattern is recommended? Please also provide links to sample applications.


问:
What is the rationale behind Apache Jena's *everything is an interface if possible* design philosophy?
If you are familiar with the Java RDF and OWL engine Jena, then you have run across their philosophy that everything should be specified as an interface when possible.  This means that a Resource, Statement, RDFNode, Property, and even the RDF Model, etc., are, contrary to what you might first think, Interfaces instead of concrete classes.

This leads to the use of Factories quite often.  Since you can't instantiate a Property or Model, you must have something else do it for you --the Factory design pattern.

My question, then, is, what is the reasoning behind using this pattern as opposed to a traditional class hierarchy system? It is often perfectly viable to use either one.  For example, if I want a memory backed Model instead of a database-backed Model I could just instantiate those classes, I don't need ask a Factory to give me one.

As an aside, I'm in the process of writing a library for manipulating Pearltrees data, which is exported from their website in the form of an RDF/XML document.  As I write this library, I have many options for defining the relationships present in the Peartrees data.  What is nice about the Pearltrees data is that it has a very logical class system: A tree is made up of pearls, which can be either Page, Reference, Alias, or Root pearls.

My question comes from trying to figure out if I should adopt the Jena philosophy in my library which uses Jena, or if I should disregard it, pick my own design philosophy, and stick with it.

答:
There are a few advantages to using only interfaces as the public face of your API:

You can create dynamic proxies that implement an interface (read more). Dynamic proxies are often used to implement transparent RPC mechanisms (whereas objects "live" on a server but can be retrieved and operated on by a client application). One can proxy classes, but only through hacks. Thus, APIs which are implemented using proxies can be easily exposed for RPC.

It opens up to having different implementations of the interfaces which can be switched transparently. So, you can have an API which has several independent implementations which use different techniques (i.e. someone might create an implementation which is more performant- you could swap in their implementation with no changes on your code).

Of course, it is a kind of pain; you have to use factories to instantiate the APIs classes, and it makes the API implementation code more complex and redundant (all public methods are duplicated).

I think a neat solution is Dart's- each class implicitly declares an interface consisting of the class' public methods, thus avoiding the code duplication.

About the need of factories, I'm not sure a better solution exists. One could reimplement an API overwriting the original classes' namespace, but it's kind of hackish and I think it would pose problems, esp. with tooling.


答: The one thing you need to avoid at all costs is the WebForms anti-pattern of putting logic in your code-behind.  Whether you use MVP or a flavor of that or not, your code-behind files should be very sparse for the sake of your sanity.


答:
Short answer: look at the MVP pattern that avoids potential code-behind ASP.NET forms issues by loosely coupling (de-coupling) your view and logic.

You may also want to go one step further and look at this comparison: MVC, MVP, ASP.NET.

The following posts are good entry points and examples:

Model View Presenter with ASP.NET

Better Web Forms with the MVP Pattern

MVC vs. MVP vs. MVVM


答:
I think it is a decent use case, but in case "error" is nothing more than a boolean value, there is a different way to accomplish what you want:

```<code>error = function_that_could_fail_1();
error = error || function_that_could_fail_2();
error = error || function_that_could_fail_3();
if(error)
{
     // do cleanup
}
</code>```

This makes use of the short-circuit evaluation of boolean operators, which guarantees that after the first failing function the others are not executed any more. If this "better", is up to your personal taste and how much you are accustomed to that idiom.

Body:
I think it is a decent use case, but in case "error" is nothing more than a boolean value, there is a different way to accomplish what you want:

error = function_that_could_fail_1();
error = error || function_that_could_fail_2();
error = error || function_that_could_fail_3();
if(error)
{
     // do cleanup
}

This makes use of the short-circuit evaluation of boolean operators, which guarantees that after the first failing function the others are not executed any more. If this "better", is up to your personal taste and how much you are accustomed to that idiom.


问:
When to start writing Exception Handling, Logging
When do you start writing your Exception Handling Code? When do you start writing Logging Statements.

For the purpose of elaborating this question, let us assume that we are on .NET platform with log4net logging but feel free to answer in a generic way.

Solution: A Windows Forms Project.
Projects: UI, BusinessRules, DataHandlers

So, do you go about writing your DataHandlers which does your Data Manipulations such as Create, Read, Update, Delete first.

Then follow it up with your Business Rules

And then your UI or any other permutation of the above.

Test your Application for Functionality.

And then start writing your Exception Handling Code and finally your Logging code?

When is a right time to start writing your Exception Handling code?

PS: In the book Clean Code, they say Write your try-catch-finally block first. That, prompted me to ask this question.

答:
You write your exception handling code when you're writing the thing that calls something that might cause exceptions.

For instance, when you're writing something that sends data to a network, you should also be writing the code that handles connection timeouts. The exception's directly relevant to what you're doing, and the work is fresh in your mind.

On the other hand, if you're writing a parser that raises exceptions when it encounters a malformed protocol data unit, then you can't write exception-handling code for the exceptions that parser produces. (But of course you're writing tests to show how and when and why the parser raises exceptions!)

The reason behind the suggestion to write your try-catch-finally first is two-fold: finally is for cleaning up the resources the function creates/consumes, and writing the catch is a nice reminder that the functions you're calling may fail, and you need to handle (if necessary) those failures.

I tend to add logging after the fact. I'm not sure if that's wise, but it's just what has worked for me. As I start running acceptance tests and the like, and start hitting issues, then I add logging so I can track errors. (And then I leave the logging in.)


问:
Is there any well-known commercial project which is currently an open source ?
I mean is there some open sourced projects that were started as closed source and were commercially successful also? I am also interested in any story behind open sourcing them.</p>

答:
Qt was originally a commercial project by Trolltech, then when they were bought by Nokia it was released as a dual (commercial/LGPL) project.

The value to Nokia of having it as the default GUI toolkit of programmers all over the world was more valuable than the extra license fees from a few commercial customers ( or it would have been if Nokia could project manage their way out of a paperbag)


答:
Blender was initially commercial.

Update: this answer is far better than mine; upvote it instead.

Title: Is there any well-known commercial project which is currently an open source ?

Body: I mean is there some open sourced projects that were started as closed source and were commercially successful also? I am also interested in any story behind open sourcing them.</p>


答: Java, it's a GPL project for the biggest part ( some minor pieces of code can have a different license ) since 2007 </p>


答:
Here you are the TOP list - 63 Top Commercial Open Source Projects

Even a better post to look at the trend in Community-driven Open Source Projects Become More Marketing Savvy


问:
Scrum and Google Docs burndown chart
There is a tutorial on how to create a burndown chart for Scrum in the Google Docs application:

http://www.scrumology.net/2011/05/03/how-to-create-a-burndown-chart-in-google-docs/

The problem with it though is, it has only a place to update progress once per sprint but the burndown is supposed to be updated with daily progress, right? How can one modify this chart to be able to put daily progress on it?

I mean to be able to plot two lines (ideal and actual) with data such as (story points 255, velocity 24):

Actual Google Docs document (free to edit):
https://docs.google.com/spreadsheet/ccc?key=0AuPWErnOiLTUdElJVzJZaE5EWEZ2S2xCelF6Z2lzaUE

答: The tutorial is really only showing you how to use a spreadsheet to draw a graph. As you say, in a Scrum project, you are probably more interested in the burndown within an iteration, on a daily basis. So simply take their approach and replace Iteration with Day. There's no magic about the name of the column in the spreadsheet.

Title: Scrum and Google Docs burndown chart


问:
New insights I can learn from the Groovy language
I realize that, for a programmer coming from the Java world, Groovy contains a lot of new ideas and cool tricks.

My situation is different, as I am learning Groovy coming from a dynamic background, mainly Python and Javascript. When learning a new language, I find that it helps me if I know beforehand which features are more or less old acquaintances under a new syntax and which ones are really new, so that I can concentrate on the latter. So I would like to know which traits distinguish Groovy among the dynamic languages.

What are the ideas and insights that a programmer well-versed in dynamic languages should pay attention to when learning Groovy?

答:
Here is an interesting comparison of Javascript and Groovy.

As far as specific features, coming from a dynamic background, you will be familiar with:

Script-style source execution

Dynamic Typing

Closures

Operator Overloading

Native syntax for Dictionaries

Regular Expressions

However, you man not have seen:

Safe dereference operator: potentiallyNullVariable?.methodOrField[()]

Native support for markup languages via inline DOM syntax

Features of Aspect Oriented Programming (although you may have seen that with JavaScript and Python).  Take a look at SpringSource.

A full list can be found in the features section of the Wikipedia article.

All in all, Groovy is simply another dynamic language on top of the Java VM rather than its own native interpreter.  However, I would suggest taking a look at Scala as Groovy's creator seems to favor it as the next Java successor (and not actually Groovy):

I can honestly say if someone had shown me the Programming in Scala book by by Martin Odersky, Lex Spoon & Bill Venners back in 2003 I'd probably have never created Groovy...


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

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

答:
OOP to me means only messaging, local
  retention and protection and hiding of
  state-process, and extreme
  late-binding of all things. It can be
  done in Smalltalk and in LISP. There
  are possibly other systems in which
  this is possible, but I’m not aware of
  them.

-- Alan Kay

OwnerDisplayName: jozilla


答:
I don't think there's much more to Groovy than to Python. The main differentiator is that it runs on the JVM, so that's more about the platform than about the language itself.

Things that would come to mind without over-thinking things too much are:

a huge list of available libraries and frameworks,

a large choice of build systems,

regular improvements with JVM updates, which are usually backwards compatible (for good and bad, some would argue that the Python 3 break is beneficial and would be a welcome approach for the Java eco-system, others would stand strongly against it),

multi-threaded programming would be a lot easier.

Title: New insights I can learn from the Groovy language

Body:
I realize that, for a programmer coming from the Java world, Groovy contains a lot of new ideas and cool tricks.

My situation is different, as I am learning Groovy coming from a dynamic background, mainly Python and Javascript. When learning a new language, I find that it helps me if I know beforehand which features are more or less old acquaintances under a new syntax and which ones are really new, so that I can concentrate on the latter. So I would like to know which traits distinguish Groovy among the dynamic languages.

What are the ideas and insights that a programmer well-versed in dynamic languages should pay attention to when learning Groovy?