答:
Java has something called a CountDownLatch, which should do what you're after.  From the JavaDoc for it

```<code> class Driver { // ...
   void main() throws InterruptedException {
     CountDownLatch startSignal = new CountDownLatch(1);
     CountDownLatch doneSignal = new CountDownLatch(N);

     for (int i = 0; i < N; ++i) // create and start threads
       new Thread(new Worker(startSignal, doneSignal)).start();

     doSomethingElse();            // don't let run yet
     startSignal.countDown();      // let all threads proceed
     doSomethingElse();
     doneSignal.await();           // wait for all to finish
   }
 }

 class Worker implements Runnable {
   private final CountDownLatch startSignal;
   private final CountDownLatch doneSignal;
   Worker(CountDownLatch startSignal, CountDownLatch doneSignal) {
      this.startSignal = startSignal;
      this.doneSignal = doneSignal;
   }
   public void run() {
      try {
        startSignal.await();
        doWork();
        doneSignal.countDown();
      } catch (InterruptedException ex) {} // return;
   }

   void doWork() { ... }
 }
</code>```

The basic idea is you can configure the Latch to stop progressing until its counted down to 0.  Once it hits 0, the waiting threads continue.

Title: Calling blocking functions and execute code when result is ready, but without callbacks

Body:
I am designing an application that has some scripting capabilities: the host application may call the scripts to perform some operations when some events occur. To keep it easy and newbie-friendly, there is a single thread for everything: this means that if the script calls something blocking, the entire application hangs. So, I either use callbacks or polling to wait for a result of a blocking call to be ready. What is ugly in this approach, is that a function that happens to call a blocking function, has to be split in parts. For polling, I'd have

```<code>function do something part 1
    blabla
    launch something lengthy
    schedule do something part 2
end

function do something part 2
    if result not ready then schedule do something part 2
    use result
    blabla
end
</code>```

Callbacks are only slightly better:

```<code>function do something
    blabla
    launch something lengthy, when done call callback
end

function callback
    use result
    blabla
end
</code>```

If one has several blocking calls, and each one depends on the result of the previous, code gets uglier and uglier. What I'm looking for is for some programming language that have some builtin support for this pattern. Something like

```<code>function do something
    blabla
    launch something lengthy
    when done:    //fictional keyword
    use result
    blabla
    ....          //more and more blocking calls
end
</code>```

Of course if there are better solutions I'm glad to listen.

Body:
Java has something called a CountDownLatch, which should do what you're after.  From the JavaDoc for it

 class Driver { // ...
   void main() throws InterruptedException {
     CountDownLatch startSignal = new CountDownLatch(1);
     CountDownLatch doneSignal = new CountDownLatch(N);

     for (int i = 0; i < N; ++i) // create and start threads
       new Thread(new Worker(startSignal, doneSignal)).start();

     doSomethingElse();            // don't let run yet
     startSignal.countDown();      // let all threads proceed
     doSomethingElse();
     doneSignal.await();           // wait for all to finish
   }
 }

 class Worker implements Runnable {
   private final CountDownLatch startSignal;
   private final CountDownLatch doneSignal;
   Worker(CountDownLatch startSignal, CountDownLatch doneSignal) {
      this.startSignal = startSignal;
      this.doneSignal = doneSignal;
   }
   public void run() {
      try {
        startSignal.await();
        doWork();
        doneSignal.countDown();
      } catch (InterruptedException ex) {} // return;
   }

   void doWork() { ... }
 }

The basic idea is you can configure the Latch to stop progressing until its counted down to 0.  Once it hits 0, the waiting threads continue.


问:
Configuration file that can be modified by user in C#
I want to create a configuration file (text file preferred) that can be modified by user. A windows service will read from that file and behave accordingly. Can you recommend a file format for this kind of process?
What I have in my is a config file like the game config files, but could not imagine how to read from it.

My question is very similar to INI files or Registry or personal files?, but my question is different because I need to consider user editing.

答:
For .NET you might as well create your own custom configuration section. In terms of having users update it, you'd probably want to write a tool but that is relatively easy -- the configuration APIs make it easy to modify the settings without writing alot of code.

If you wish to avoid XML, there are lots of options. Most of those game config files you see are lua scripts. Some other interesting options would be ruby or python -- both of which have CLR implementations as IronRuby and IronPython and would be fairly straightforward to implement.

ContentLicense: CC BY-SA 3.0


问:
Scrum: What to do with epics once the stories are clear?
When working on a backlog, you define epics and break them down into user stories. Epics are estimated and kept on the backlog as epics until they become important enough to be planned into one of the next sprints.

But once an epic is split into sprintable units, what do you do with the original epic? Do you keep it with the stories until all are done? Do you retire them into some kind of epic archive? Do you just delete them?

They seem like unnecessary balast once the splitting is done.

答:
This depends on your tooling somewhat. From a process standpoint, once the Epic has been broken down into Sprint-Sized stories that can be estimated, the original Epic (which had really been functioning as a placeholder in your backlog) can be discarded. If you are using index cards, tear that Epic up!

Ideally, the resulting User Stories should be independent of one another, so their Epic ancestry would not be important. But if you want to maintain a connection to the original Epic, many tools provide a way to link it. This can also be done in the User Story itself: "[Epic] As a System Admin, I need....".

OwnerDisplayName: arumbay

OwnerDisplayName: justinpeck


答:
If the epic was put in with acceptance criteria associated with its user story, then you test that. If it's acceptable, you close the epic. If it's not, you schedule work to close out the user story.

Ideally, all the child user stories should have implemented all the requirements of the epic.

In any event, acceptance criteria should be assigned (if they are not there already), the work to test them scheduled and the epic closed (if the tests pass).

Title: Scrum: What to do with epics once the stories are clear?

Body:
When working on a backlog, you define epics and break them down into user stories. Epics are estimated and kept on the backlog as epics until they become important enough to be planned into one of the next sprints.

But once an epic is split into sprintable units, what do you do with the original epic? Do you keep it with the stories until all are done? Do you retire them into some kind of epic archive? Do you just delete them?

They seem like unnecessary balast once the splitting is done.


问:
Is LISP still useful in today's world? Which version is most used?
I try to teach myself a new programming language in regular intervals of time. Recently, I've read how Lisp and its dialects are at the complete opposite end of the spectrum from languages like C/C++, which made me curious enough to know more about it. However, two things are unclear to me, and I'm looking for guidance on them :

Is LISP still practiced/used in todays world, or is it a legacy language like FORTRAN/COBOL ? I mean, apart from maintaining existing code, is it used on new projects at all ?

What is the most widely used dialect ? I came across Scheme and Common Lisp as the 2 most prevalent dialects, and wanted your opinion as to which is the most favored/useful one to learn - and would be immensely gratified if you can suggest any resources for a rank beginner to start from.

While eager to learn a language which is fundamentally different from the procedural languages I'm used to, I don't want to invest undue effort in something if its totally obsolete - I'd still learn it if it was professionally "dead", but only with an academic perspective...

答: Another factor to consider in choosing which dialect of Lisp to learn may be the number and quality of implementations.  If a dialect has only one or two implementations, then you're stuck with their flaws until those flaws get fixed, and there's always a chance that people will stop refining the implementation.  In itself that's not a reason not to use a single-implementation dialect of Lisp, but it's something to take into account.  An advantage of Scheme and Common Lisp is that there are many implementations of these dialects.  Both languages have published standards, so relatively recent implementations are likely to run the same code, mostly.  Some of these implementations have been around a long time, but are still under active development: They're now high-quality implementations, and they are still being refined. (For example, Steel Bank Common Lisp--SBCL, mentioned above--is extremely fast.  I wonder how easy it would be to make JVM-based Lisp as fast.)</p>


答:
Two additional points:

First, Lisp is a great language for writing code in which interactions between functions or data are often complex.  In many popular languages, if you're confused about why your program is doing what it's doing, you have to write special functions to let you examine the program's internal state as it's going along.  In some languages, you then have to wait for your code to recompile.  Of course there may be tools such as debuggers that help with this.  In Lisp, though, all you need is a way to stop the program, and then, typically, you have access to everything in Lisp.  In Common Lisp, sometimes I just type ^C, or throw a call to error into a single function (which is the only thing that must get recompiled, and you don't have to do anything to recompile it).  Once I stop the program, I'm instantly thrown into a debugger--but the debugger gives me all of the power of Lisp, and I can exit the debugger, call specific functions, etc.  I can easily examine any of the data structures in my program.  Most Scheme's should allow similar practices.  Lisp is not unique in this regard, but what it offers goes beyond what many popular languages offer.

Second: If you're going to experiment with any dialect of Lisp, I would not do it without (a) using an editor that matches parentheses, and (b) learning proper Lisp indentation.  It would be a good idea to use an editor that will approximate proper indentation for you, too.  C/C++/Java-style code formatting is designed for languages with fewer parentheses/braces/brackets than Lisp.  Lisp pretty printing style works well once you're familiar with it, and you don't end up being confused by parentheses or wasting half of your space putting one closing parenthesis per line.

Title: Is LISP still useful in today's world? Which version is most used?

Body:
I try to teach myself a new programming language in regular intervals of time. Recently, I've read how Lisp and its dialects are at the complete opposite end of the spectrum from languages like C/C++, which made me curious enough to know more about it. However, two things are unclear to me, and I'm looking for guidance on them :

Is LISP still practiced/used in todays world, or is it a legacy language like FORTRAN/COBOL ? I mean, apart from maintaining existing code, is it used on new projects at all ?

What is the most widely used dialect ? I came across Scheme and Common Lisp as the 2 most prevalent dialects, and wanted your opinion as to which is the most favored/useful one to learn - and would be immensely gratified if you can suggest any resources for a rank beginner to start from.

While eager to learn a language which is fundamentally different from the procedural languages I'm used to, I don't want to invest undue effort in something if its totally obsolete - I'd still learn it if it was professionally "dead", but only with an academic perspective...


问:
What situations are appropriate for C# to C interop?
Given that C# has the unsafe keyword, are there situations in which it would still be beneficial to interoperate with C libraries?

I could see the need for very fast number crunching, graphical manipulation or matrix operations, using pre-existing C libraries.  But is there a use case for writing greenfield DLL's in, say, C99, and interoperating with them from C#?

I imagine that there might be edge cases where dropping down to C (in the sense that it is closer to the metal) would be the only way to get the needed performance characteristics.

答: Yes, for interfacing with legacy software. I had to create an interop DLL that could be consumed by my legacy C application to take advantage of technology that was not available when my toolkit was invented. </p>


问:
What is the (craziest, stupidest, silliest) thing a client/boss asked you to do?
See title, but I am asking from a technical perspective, not

Take my 40 year old virgin niece on a date or you're fired.

答:
My boss once insisted to me that Google's search results were all sorted by the highest bidder. He flatly refused to believe that Google tried to order its results by usefulness to the user. I tried to explain with simple logic that a system like that would result in the worst internet search engine imaginable to no avail.

In fact, he argued so vehemently that I'm pretty sure he'd just promised the client "the number one spot on Google if they were prepared to pay"... but didn't want to have to call back and look like an idiot.

*sigh*

ContentLicense: CC BY-SA 2.5


问:
Form validation and file structure
I have a form (lets say a registration form) and onsubmit, it calls a function to validate as follows:

```<code>$.ajax({
        url : "/ajax/validate.php",
        type : "POST",
        data : $(".form").serialize(),
        success : function(data) {
            data = $.parseJSON(data);
            $.each(data, function(i, item) {
                $('#' + i).addClass('errors');
            });
        }
    });
</code>```

The validate.php looks something like this:

```<code>if ($_POST['email'] == '' || filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) == false) {
    $errors['email'] = 'Not a valid email';
}
if ($errors) {
    echo json_encode($errors);
} else {
    // insert to db
}
</code>```

Now all of this code is specifically for the registration form. I'll have many forms on my site. My question is, do I make a new file (like validate.php) for each individual form? Such as /ajax/save_profile_data.php etc? Do I keep each form validation separate or is there a clever way to approach this? I don't know if having a validate file for each form on my site is the correct way to do it.

答:
The general answer would be yes - a separate file for each individual form. If the forms are different and need to be validated a different way, then each file will only need the code for that specific form, otherwise your one file would eventually grow too large in time. Something like /ajax/validations/register.php, /ajax/validations/login.php, /ajax/validations/profile.php, etc.,.

You could get some leverage out of this by having each of the form validation files include other intermediate files that contain re-useable methods to be shared between the different validation pages.

But for most projects I'd recommend using a framework to do as much of the work for you as possible, some of which allow you to create forms with their fields and bind them to a database table through an SQL object mapper, or something else, depending on your requirements.

Title: Form validation and file structure


问:
Define which tests are run after build in Visual Studio 2012
Visual Studio 2012 has a new feature where it automatically runs your unit tests after every build.

I would like to use this feature, but I have a number of tests that should not be run after every build (long running performance tests, etc).

Is there a way to define which categories are run automatically?  Or some other way to define which test should be run?

答: After update 1, you can filter on categories in the search box using the trait filter. See this blog post for more info.</p>

ContentLicense: CC BY-SA 4.0


问:
Is Googling every code a bad practice?
I just came from an interview in which they asked me several questions about programming and problem solving. Regarding the programming questions, I asked them to let me Google so I can see the code (I quoted that logic is the thing to learn, not the language). At the end of the interview they told me that my skills very good but what would I do if Google has been blocked around our country(It can happen in Pakistan, Youtube is yet blocked). Is it really that a programmer should know the code too?</p>

答:
You should be able to develop algorithms without the IDE and definitely without Google, and without help.

In terms of solviing simple problems I would say yes.

The only thing you should rely on research is complex problems, and particularly learning new developments and frameworks.

I used to be able to code in VB3 when I was 12 with no internet, no intellisense. I consulted help when I needed to.

With that said, I wouldn't appreciate an applicant Googling to find an answer for a sort algorithm or for a simple structure such as a list or queue.

Title: Is Googling every code a bad practice?


答:
It depends on the situation.

Personally if I were an interviewer, I would tell the candidate that they are not allowed to Google, but pseudocode is fine as long as it is sufficiently detailed that I am convinced that it could be translated directly into a real language.

However once you've actually typed in enough code, you're unlikely to need to refer to Google for how to write basic code.  Unless, possibly, you're used to having an IDE type for you.

Title: Is Googling every code a bad practice?

Body: I just came from an interview in which they asked me several questions about programming and problem solving. Regarding the programming questions, I asked them to let me Google so I can see the code (I quoted that logic is the thing to learn, not the language). At the end of the interview they told me that my skills very good but what would I do if Google has been blocked around our country(It can happen in Pakistan, Youtube is yet blocked). Is it really that a programmer should know the code too?</p>


答:
But is there a use case for writing greenfield DLL's in, say, C99, and interoperating with them from C#?

The main use case I see is when you are going to write a special lib which is targeted for many platforms where C or C99 is available, but C# is not or only for a few of them ("C#" may be not available for organizational reasons, not just pure technical ones).

Another use case is when you have an expert in some field (for example, an expert about a specific hardware), and he has the task to code some of his expert knowledge into a library, but that expert has 30 years of experience in C but none in C#.

One thing to consider: "100% greenfield" is a very rare situation today. For most kind of problems, at least partial solutions exist, or similar solutions which can be re-used when modified. So using C makes a whole lot of sense when you have to build something new on an existing C code base.

Title: What situations are appropriate for C# to C interop?

Body:
Given that C# has the unsafe keyword, are there situations in which it would still be beneficial to interoperate with C libraries?

I could see the need for very fast number crunching, graphical manipulation or matrix operations, using pre-existing C libraries.  But is there a use case for writing greenfield DLL's in, say, C99, and interoperating with them from C#?

I imagine that there might be edge cases where dropping down to C (in the sense that it is closer to the metal) would be the only way to get the needed performance characteristics.


问:
KISS principle applied to programming language design?
KISS ("keep it simple, stupid" or "keep it simple stupid", see e.g. here) is an important principle in software development, even though it apparently originated in engineering. Citing from the wikipedia article:

The principle is best exemplified by the story of Johnson handing a team of design engineers a handful of tools, with the challenge that the jet aircraft they were designing must be repairable by an average mechanic in the field under combat conditions with only these tools. Hence, the 'stupid' refers to the relationship between the way things break and the sophistication available to fix them.

If I wanted to apply this to the field of software development I would replace "jet aircraft" with "piece of software", "average mechanic" with "average developer" and "under combat conditions" with "under the expected software development / maintenance conditions" (deadlines, time constraints, meetings / interruptions, available tools, and so on).

So it is a commonly accepted idea that one should try to keep a piece of software simple (or simple stupid, in case you omit the comma) so that it easy to work on it later.

But can the KISS principle be applied also to programming language design? Do you know of any programming languages that have been designed specifically with this principle in mind, i.e. to "allow an average programmer under average working conditions to write and maintain as much code as possible with the least cognitive effort"?

If you cite any specific language it would be great if you could add a link to some document in which this intent is clearly expressed by the language designers. In any case, I would be interested to learn about the designers' (documented) intentions rather than your personal opinion about a particular programming language.

答:
Now, KISS approach to programming languages is a funny notion, at least if you consider programming languages to be an abstraction layer to a CPU's instruction set, etc. If you do not define "KISS" more closely. I am just saying here, that an oxcart is KISS applied to a car to its fullest.

Now another interpretation of KISS could be something like "smartly done without needless ornaments and not overly complicated". Especially one could argue, that there should not be too many specific cases for similar things, etc. Usually math is quite good at boiling down stuff to its essence, and - o wonder - mathematicians have spent some time thinking about programming and computers as well.

For programming, 2 quite famous abstract models exist:

One is the turing machine which defines a machine and a simple instructional model that is able to compute everything a computer could do.

The other one is the Lambda-Calculus by Church et. al. that is equivalent in power

Fun thing is: While the turing machine is quite simple in its layout, it is not a system that is easy to handle and I do not think it qualifies for "smart KISS". But Lambda Calculus has more to do with programming languages that we know -- and with Lisp and Scheme pioneering features of the lambda calculus it has made its way into a lot of languages.

Lisp and Scheme are REALLY simple, at least syntax wise. Syntax is a major problem with programming languages (which is probably why they are reinvented all the time). In the case of C++ it is almost unhandable for the human brain to predict how some source lines are interpreted by the compiler.)

Lisps are reducing the syntactical complexity altogether by introducing one common form for commands:

```<code>(command param1 param2 ...)
</code>```

This can be a method call, such as

```<code>(max 1 2 3 4)
</code>```

as well as a if branch, loop etc.

```<code>(if (< 1 2)
    (write 4)
    (write 5))
</code>```

(all code here is pseudo-Lisp/Dialect agnostic)

The form

```<code>(command param1 param2 ...)
</code>```

can also be interpreted as a list

```<code>(item1 item2 item3)
</code>```

And that is the basis for Lisps simplicity and beauty. Because nested lists (like in the if statement example) constitute trees and those can be easily understood both by the machine and by the human in front of the machine.

Another feature of Lisps are macros I won't go into the dirty detail here, but since there is no syntactic difference between normal function calls and "Syntax (e.g.g  for loops, variable declaration, etc., everything the parser has to handle in other programming languages) you can create your own syntax. Macros are in essence Manipulations of the Tree that constitutes your program.

I think Lisp has a KISS to programming. That you can manipulate syntax by using macros has lead to a phenomenon that Lisp has evolved quite dynamically. Need a new Language feature like - lets say object orientation - just write a OOP system with macros!

While C was extended roundabout 2 times with OOP features (C++, Obj. C) Lisp was extended multiple times, in the end there was a winner.

That is another quirk about Lisp, it evolves (see Clojure and Clojurescript for interesting new Mutation of lisp).

For its KISS properties Lisps is favored as teaching languages by some. Like Fogus outlines in his blueprint of an educational language (http://blog.fogus.me/2013/01/21/enfield-a-programming-language-designed-for-pedagogy/ )

To start, I’m strong believer that when learning new, and at times complex topics it’s outright detrimental to overload students with frivolous syntax rules. Therefore, Enfield is designed with minimal syntax rules and what’s more minimal than a Lisp like syntax.

Body:
Now, KISS approach to programming languages is a funny notion, at least if you consider programming languages to be an abstraction layer to a CPU's instruction set, etc. If you do not define "KISS" more closely. I am just saying here, that an oxcart is KISS applied to a car to its fullest.

Now another interpretation of KISS could be something like "smartly done without needless ornaments and not overly complicated". Especially one could argue, that there should not be too many specific cases for similar things, etc. Usually math is quite good at boiling down stuff to its essence, and - o wonder - mathematicians have spent some time thinking about programming and computers as well.

For programming, 2 quite famous abstract models exist:

One is the turing machine which defines a machine and a simple instructional model that is able to compute everything a computer could do.

The other one is the Lambda-Calculus by Church et. al. that is equivalent in power

Fun thing is: While the turing machine is quite simple in its layout, it is not a system that is easy to handle and I do not think it qualifies for "smart KISS". But Lambda Calculus has more to do with programming languages that we know -- and with Lisp and Scheme pioneering features of the lambda calculus it has made its way into a lot of languages.

Lisp and Scheme are REALLY simple, at least syntax wise. Syntax is a major problem with programming languages (which is probably why they are reinvented all the time). In the case of C++ it is almost unhandable for the human brain to predict how some source lines are interpreted by the compiler.)

Lisps are reducing the syntactical complexity altogether by introducing one common form for commands:

(command param1 param2 ...)

This can be a method call, such as

(max 1 2 3 4)

as well as a if branch, loop etc.

(if (< 1 2)
    (write 4)
    (write 5))

(all code here is pseudo-Lisp/Dialect agnostic)

The form

(command param1 param2 ...)

can also be interpreted as a list

(item1 item2 item3)

And that is the basis for Lisps simplicity and beauty. Because nested lists (like in the if statement example) constitute trees and those can be easily understood both by the machine and by the human in front of the machine.

Another feature of Lisps are macros I won't go into the dirty detail here, but since there is no syntactic difference between normal function calls and "Syntax (e.g.g  for loops, variable declaration, etc., everything the parser has to handle in other programming languages) you can create your own syntax. Macros are in essence Manipulations of the Tree that constitutes your program.

I think Lisp has a KISS to programming. That you can manipulate syntax by using macros has lead to a phenomenon that Lisp has evolved quite dynamically. Need a new Language feature like - lets say object orientation - just write a OOP system with macros!

While C was extended roundabout 2 times with OOP features (C++, Obj. C) Lisp was extended multiple times, in the end there was a winner.

That is another quirk about Lisp, it evolves (see Clojure and Clojurescript for interesting new Mutation of lisp).

For its KISS properties Lisps is favored as teaching languages by some. Like Fogus outlines in his blueprint of an educational language (http://blog.fogus.me/2013/01/21/enfield-a-programming-language-designed-for-pedagogy/ )

To start, I’m strong believer that when learning new, and at times complex topics it’s outright detrimental to overload students with frivolous syntax rules. Therefore, Enfield is designed with minimal syntax rules and what’s more minimal than a Lisp like syntax.


答:
When I think of minimialism, I think of Lisp and Go. With Lisp, all you have are functions and lists, which is about as simple as you can get (well, there's a little more, but whatever). However, I think the Go case is more interesting.

Go was designed to be simple (it's a decent read). The term they use is "feature orthogonality", which means that any feature should only be added if it provides something truly unique. This seems to stem with the authors' (Russ Cox and Rob Pike come to mind) involvement with Plan9, which was a reimagination of UNIX with simplicity in mind. (If you're interested in minimal design, Rob Pike's paper on a simple windowing system is a good read.)

Here's some simple examples of the syntax:

Only one looping construct

A loop can look like one of the following:

Infinite loop

```<code>for {
}
</code>```

While loop

```<code>for <conditional> {
}
</code>```

Traditional for loop

```<code>for i := 0; i < 10; i++ {
}
</code>```

Foreach loop

```<code>// works for maps or arrays
for k, v := range arr {
}
</code>```

Multi-purpose switch

```<code>switch {
    // cases must be evaluate to a boolean
}

switch <value> {
}

switch t := <value>; t {
    // can use t inside
}
</code>```

Multiple return

```<code>return val1, val2, ...
</code>```

Removes the need for throw (pass the error as last return value)

Removes the need for out parameters

Removes the need for tuples

Interfaces

```<code>type X interface {
    DoSomething()
    String() string
}
</code>```

Solves similar problems as generics

Allows abstraction

Embedding

```<code>type A struct {
    Thing string
}

type B struct {
    A // embeds A in B, so B.Thing refers to A.Thing
}
</code>```

Solves same problem as inheritance

Obviates need for classes

Channels

Can be used to implement semaphores

```<code>var c = make(chan bool, 1)
c<-true // semaphore lock
<-c // semaphore free
</code>```

Used for message passing between threads

```<code>func produce(c chan<- bool) {
    for {
        c <- true
    }
}
func consume(c <-chan bool) {
    for {
        <-c
    }
}

var c = make(chan bool)
go produce(c)
go consume(c)
</code>```

Can be used to handle asynchronous events

```<code>for <conditional> {
}
</code>```0

Conclusion

I'm not going to go into every part of the syntax, but hopefully you can see what minimalism can do. The language is intriguing not because it adds a ton of new features, but because it uses the best features from other languages without anything extra.

There's usually one "best" way of solving a problem. For example, on the mailing list, a lot of users complain about not having generics. After discussion, they realize that everything they want to do can be done with interfaces. Read up on effective go for examples on idiomatic syntax.

The benefit of KISS languages is it's possible to write idiomatic code, because code style is restricted by the language. For example, in Go, you cannot write something like this:

```<code>for <conditional> {
}
</code>```1

You have to use curly-braces:

```<code>for <conditional> {
}
</code>```2

There are many other examples of this in the syntax, which makes reading other peoples code easier.

Benefits of KISS language over featureful languages:

easier to understand others' code

easier to grok the entire language (C++ is notorious for being hard to understand)

focus on algorithm, not the syntax

Title: KISS principle applied to programming language design?

Body:
KISS ("keep it simple, stupid" or "keep it simple stupid", see e.g. here) is an important principle in software development, even though it apparently originated in engineering. Citing from the wikipedia article:

The principle is best exemplified by the story of Johnson handing a team of design engineers a handful of tools, with the challenge that the jet aircraft they were designing must be repairable by an average mechanic in the field under combat conditions with only these tools. Hence, the 'stupid' refers to the relationship between the way things break and the sophistication available to fix them.

If I wanted to apply this to the field of software development I would replace "jet aircraft" with "piece of software", "average mechanic" with "average developer" and "under combat conditions" with "under the expected software development / maintenance conditions" (deadlines, time constraints, meetings / interruptions, available tools, and so on).

So it is a commonly accepted idea that one should try to keep a piece of software simple (or simple stupid, in case you omit the comma) so that it easy to work on it later.

But can the KISS principle be applied also to programming language design? Do you know of any programming languages that have been designed specifically with this principle in mind, i.e. to "allow an average programmer under average working conditions to write and maintain as much code as possible with the least cognitive effort"?

If you cite any specific language it would be great if you could add a link to some document in which this intent is clearly expressed by the language designers. In any case, I would be interested to learn about the designers' (documented) intentions rather than your personal opinion about a particular programming language.

Body:
When I think of minimialism, I think of Lisp and Go. With Lisp, all you have are functions and lists, which is about as simple as you can get (well, there's a little more, but whatever). However, I think the Go case is more interesting.

Go was designed to be simple (it's a decent read). The term they use is "feature orthogonality", which means that any feature should only be added if it provides something truly unique. This seems to stem with the authors' (Russ Cox and Rob Pike come to mind) involvement with Plan9, which was a reimagination of UNIX with simplicity in mind. (If you're interested in minimal design, Rob Pike's paper on a simple windowing system is a good read.)

Here's some simple examples of the syntax:

Only one looping construct

A loop can look like one of the following:

Infinite loop

for {
}

While loop

for <conditional> {
}

Traditional for loop

for i := 0; i < 10; i++ {
}

Foreach loop

// works for maps or arrays
for k, v := range arr {
}

Multi-purpose switch

switch {
    // cases must be evaluate to a boolean
}

switch <value> {
}

switch t := <value>; t {
    // can use t inside
}

Multiple return

return val1, val2, ...

Removes the need for throw (pass the error as last return value)

Removes the need for out parameters

Removes the need for tuples

Interfaces

type X interface {
    DoSomething()
    String() string
}

Solves similar problems as generics

Allows abstraction

Embedding

type A struct {
    Thing string
}

type B struct {
    A // embeds A in B, so B.Thing refers to A.Thing
}

Solves same problem as inheritance

Obviates need for classes

Channels

Can be used to implement semaphores

var c = make(chan bool, 1)
c<-true // semaphore lock
<-c // semaphore free

Used for message passing between threads

func produce(c chan<- bool) {
    for {
        c <- true
    }
}
func consume(c <-chan bool) {
    for {
        <-c
    }
}

var c = make(chan bool)
go produce(c)
go consume(c)

Can be used to handle asynchronous events

func async() chan bool {
    var c = make(chan bool)
    go doSomethingAsync(c)
    return c
}

// wait for long async process to finish
c := async()
select {
    case _ = <-c:
}

Conclusion

I'm not going to go into every part of the syntax, but hopefully you can see what minimalism can do. The language is intriguing not because it adds a ton of new features, but because it uses the best features from other languages without anything extra.

There's usually one "best" way of solving a problem. For example, on the mailing list, a lot of users complain about not having generics. After discussion, they realize that everything they want to do can be done with interfaces. Read up on effective go for examples on idiomatic syntax.

The benefit of KISS languages is it's possible to write idiomatic code, because code style is restricted by the language. For example, in Go, you cannot write something like this:

if <condition>
    statement;

You have to use curly-braces:

if <condition> {
    statement;
}

There are many other examples of this in the syntax, which makes reading other peoples code easier.

Benefits of KISS language over featureful languages:

easier to understand others' code

easier to grok the entire language (C++ is notorious for being hard to understand)

focus on algorithm, not the syntax


问:
Wrapping specific checked exception in domain unchecked ones?
Uncle Bob says in Clean Code book that Unchecked Exceptions should be used. Now JDK has some checked exceptions: IOException, IllegalAccessException etc. which cannot be avoided.

In my application logic suppose I have an exception:

```<code>public class MyDomainException extends RunntimeException {
    public MyDomainException(Exception e) {
         super(e);
    }
    //etc
}
</code>```

And some code

```<code>try {
    outputStream.write(someBytes);
} catch (IOException e) {
    throw new MyDomainException(e);
}
</code>```

Is this a good approach or should these checked exception be propagated up the ladder and filling the method signatures?

Edit: I understand this was asked and answered.

Can MyDomainException be used for business logic validation too or this exception should only be used for wrapping and other exception(s) should handle the business logic?

Edit: I would still like an answer to this question.

答:
It's good style. For example Spring's JdbcTemplate makes the same with JDBC exceptions.

From Spring documentation:

It(JdbcTemplate) also catches JDBC exceptions and translates them to the generic, more informative, exception hierarchy defined in the org.springframework.dao package.


答:
I see no problem with that as long as you know you could eventually solve it on your own.

Googling for snippets of code is just a way to find a solution quicker than if you have to do it yourself. Besides, it's rarely the case you find some code that is exactly what you were looking for -- in practice, you always have to change it anyway to suit your problem at hand.

Also, Googling for solutions "just for the heck of it" is a great way to learn new stuff and approaches. Even though your solution certainly works, there might be other, more elegant ways to solve it.

We're not living in the dark. Use whatever tool you have at your disposal!

Title: Is Googling every code a bad practice?


问:
Whats the greatest most impressive programing feat you ever witnessed?
Everyone knows of the old adage that the best programmers can be orders of magnitude better than the average. I've personally seen good code and programmers, but never something so absurd. So the questions is, what is the most impressive feat of programming you ever witnessed or heard of?

You can define impressive by:

The scope of the task at hand e.g. John single handedly developed the framework for his company, a work comparable in scope to what the other 200 employed were doing combined.

Speed e.g. Stu programmed an entire real time multi-tasking app OS on an weekened including  its own C compiler and shell command line tools

Complexity e.g. Jane rearchitected our entire 10 millon LOC app to work in a cluster of servers. And she did it in an afternoon.

Quality e.g. Charles's code had a rate of defects per LOC 100 times lesser than the company average. Furthermore he code was clean and understandable by all.

Obviously, the more of these characteristics combined, and the more extreme each of them, the more impressive is the feat.

So, let me have it. What's the most absurd feat you can recount? Please provide as much detail as possible and try to avoid urban legends or exaggerations. Post only what you can actually vouch for.

Bonus questions:

Was the herculean task a one-of, or did the individual regularly amazed people?

How do you explain such impressive performance?

How was the programmer recognized for such awesome work?

答:
Richard M Stallman comes to the top of my mind.  This one man started giving life to GNU Emacs, GCC, GDB and many more notable programs.  He even went on to author the original GPL.  I have heard lore about him saying, he goes into a cave for 18 months and returns with over 150,000 lines of code that make the C compiler of GCC suite.  Those 150,000 LOC gave the bed rock for g++ later on.  In his own words, Emacs started as text editor, then it became a way of life, and now it is a religion for some of us.  Even today, Emacs' design principles are used in many successful programs.

Donald E Knuth's TeX system is another program that comes to the mind when thinking about programming marvels.


答:
It depends on what you google for.

You should not need to google for basic algorithms and logic. If you cannot come up with the basic logic to solve a problem yourself, you have a problem.

You may need to google for complex algorithms or for getting an idea how to approach a complex problem. There are many intelligent people out there attempting to solve complex problems using heretofore non-existent algorithms, there's no need for you to have to do the same thing from scratch; benefit from the existing work done by others.

You should not google for basic syntax questions. You should know your language of choice well enough to be able to write code without help.

You may look at the manual for specific API details. Nobody can be expected to keep the exact parameter order and behavior for every possible functions and method in one's head. You should not google for this, you should be able to go directly to the relevant manual page.

Specifically in an interview, if you're expected to be able to solve a particular kind of problem in your head and you're not able to, then this probably means you do not have enough experience required for the job. If you can do it in pseudocode but would need to look at the documentation for specific API calls, that's fine IMO.

Title: Is Googling every code a bad practice?


问:
Why does Cem Kaner consider a test not revealing a bug a waste of time?
What about confirming the functionality in positive tests, proving it is working - should I say it is a waste of time? What kind of concept is behind this quote?

Unsuccessful tests, i.e. tests that do not find errors are a waste of
  time.

Web Engineering: The Discipline of Systematic Development of Web Applications quoting Cem Kaner.

答:
The idea is, according to Kaner, "since you will run out of time before running out of test cases, it is essential to use the time available as efficiently as possible."

Concept behind the quote you ask about is presented and explained in good detail in the Testing Computer Software article by Cem Kaner, Jack Falk, Hung Quoc Nguyen, in the chapter "THE OBJECTIVES AND LIMITS OF TESTING":

SO, WHY TEST?

You can't find all the bugs. You can't prove the program correct, and you don't want to. It's expensive,
  frustrating, and it doesn't win you any popularity contests. So, why bother testing?

THE PURPOSE OF TESTING A PROGRAM IS TO FIND PROBLEMS IN IT

Finding problems is the core of your work. You should want to find as many as possible; the more serious the problem, the better.

Since you will run out of time before running out of test cases, it is essential to use the time available as efficiently as possible. Chapters 7,8,12, and 13 consider priorities in detail. The guiding principle can be put simply:

A test that reveals a problem is a success. A test that did not reveal a problem was a waste of time.

Consider the following analogy, from Myers (1979). Suppose that something's wrong with you. You go
  to a doctor. He's supposed to run tests, find out what's wrong, and recommend corrective action. He runs test after test after test. At the end of it all, he can't find anything wrong. Is he a great tester or an incompetent diagnostician? If you really are sick, he's incompetent, and all those expensive tests were a waste of time, money, and effort. In software, you're the diagnostician. The program is the (assuredly) sick patient...

You see, the point of above is that you should prioritize your testing wisely. Testing is expected to take a limited amount of time and it's impossible to test everything in the time given.

Imagine that you spent a day (week, month) running tests, find no bugs and let some bug to slip through because you didn't have time to run a test that would reveal it. If this happens, you can't just say "it's not my fault because I was busy running other tests" to justify this miss - if you say so, you will still be held responsible.

You wasted time running tests that did not reveal bugs and because of this, you missed a test that would find a bug.

(In case if you wonder, misses like above are generally unavoidable no matter how you try, and there are ways to deal with these, but that would be more a topic for a separate question... and probably a better fit for SQA.SE.)


答:
In my opinion this quote refers to too general or unrobusts tests.

If you make a test for a function that validate emails and on the test you only provide valid emails, that test is completely useless. You would have to test this function for "any" string posible, invalid emails, too long emails, unicode characters (áêñç....)

If you code a test that only checks that name@dom.com returns true and name@com returns false, that test is the same of no test at all.

Title: Why does Cem Kaner consider a test not revealing a bug a waste of time?

Body:
What about confirming the functionality in positive tests, proving it is working - should I say it is a waste of time? What kind of concept is behind this quote?

Unsuccessful tests, i.e. tests that do not find errors are a waste of
  time.

Web Engineering: The Discipline of Systematic Development of Web Applications quoting Cem Kaner.


问:
What is Java's primary focus? Why does it take so long to get new features?
I have been exploring the new features in the JDK8, like the lambda expressions, the extension methods, and the new stream API.

Evidently none of these features are new in the programming world and that made wonder why are getting all these things in Java until now.

We had lambda expressions in Lisp (1958), SML (1973), Haskell (1990), Python (1991), JavaScript (1994), Ruby (1995), Scala (2003), C# (2007) and 55 years after Lisp and practically everyone else, in Java (2013).

And I had read about streams in SIC (1996).

I have been wondering why now? The evidence suggests that competing with other languages is not the motivation.

It would seem that all the cool new features in this release of Java are just a by-product of implementing parallelism. We have lambdas because they make writing parallel algorithms simpler, and we have extension methods because we needed them to give support to the changes that lambda expressions required, etc., etc.

So, my question is: can we safely affirm that the main topic in this upcoming release of Java is actually parallelism? Or can we justify other reasons for the appearance of the oldest tricks in the book until now in Java?

答:
I would say that the most important purpose of a programming language is to be used; currently C and Java don't have lambda expressions and they are the most used languages (according to TIOBE for example).

And to answer the question I believe that Java is addressed to the enterprise; in this domain things need to be very stable and reliable; for example Java 7 has appeared for almost 2 years yet I don't know directly any project in Java 7. Also another important thing is backwards compatibility which is very important for the enterprise.


答: It depends, I understand Uncle's Bob's philosophy on this, but sometimes you want to capture the CheckedException and deal with it there and then.  The example you use of catching, wrapping and throwing is fine, especially under Java 7 which does a better job of maintaining the hierarchy of exceptions.

Title: Wrapping specific checked exception in domain unchecked ones?

Body:
Uncle Bob says in Clean Code book that Unchecked Exceptions should be used. Now JDK has some checked exceptions: IOException, IllegalAccessException etc. which cannot be avoided.

In my application logic suppose I have an exception:

```<code>public class MyDomainException extends RunntimeException {
    public MyDomainException(Exception e) {
         super(e);
    }
    //etc
}
</code>```

And some code

```<code>try {
    outputStream.write(someBytes);
} catch (IOException e) {
    throw new MyDomainException(e);
}
</code>```

Is this a good approach or should these checked exception be propagated up the ladder and filling the method signatures?

Edit: I understand this was asked and answered.

Can MyDomainException be used for business logic validation too or this exception should only be used for wrapping and other exception(s) should handle the business logic?

Edit: I would still like an answer to this question.


问:
Could submitting a Pull Request ever constitute accepting a Contributor Licence Agreement?
Some software projects have a Contributor Licence Agreement. The agreement could, for instance, assign copyright of 3rd-party contributions to the original project creator.  Could submitting a Pull Request on github ever constitute accepting such an agreement?</p>

答:
If you need an actual answer, as in "this could have real legal consequences", you need to ask an actual lawyer, not some people you've never met on the other side of the internet.

Shrinkwrap licences (where they give you a wad of text at install time and make you press "I accept the license" to install) have been held legally valid, but I believe a part of the reason for that is that they make sure you see (and press) the "agree" button.  Unless there is a similar action required of the person submitting the pull request, I suspect it might not be legally binding, since the contributor could stand up in court and say, "I had no idea they were using license foo" or something similar.

If it were me running a small project that needed some legal thing from contributors, I'd make sure they sent an email formally accepting the legal thing before accepting their contribution.


问:
Multi-threaded server
I have written a server/client program in which I am using 2 threads :

One to recieve data continously and

Other to send data as the user writes it on screen

Problem:

I have created the threads but durung execution ,the control gets stuck in
the recieving thread having the infinite loop to recieve data and never goes
to the sending thread.

Please tell me if there is any solution to the problem.

答:
Have a look at this tutorial for pthreads.  Even if you're not using pthreads, the general concepts will still apply to the threading library you're using.

In particular, look at Section 7 for mutexes and Section 8 for conditional variables.  At first glance, it doesn't appear that you're using any sort of signaling or mutexes in order to control the flow of your program.  One thread dominating the operations is a tell-tale sign of that problem.

Assuming you're using a single area to pass data between your two threads, you'll need some sort of mechanism to control access over that data area.  A mutex is the general route to solve that challenge, but you can use semaphores to control the access as well.

As an alternative and if you're running on a Linux / POSIX system that supports FIFO pipes, you could use that instead.  You'll need to weigh the cost of system access to the FIFO versus the implementation cost of mutexes.  Personally, I think FIFOs are a replacement for IPC (inter-process communication), and are not all that great of an option instead of a mutex.  But it's an alternative and if you can't wrap your head around using a mutex or semaphore, then FIFOs are an option.

Title: Multi-threaded server


答:
In my opinion, epics need to be maintained for communication at portfolio levels with C-level individuals in order to minimize confusion with what is in the team backlog.

There should be a backlog that is being used to communicate at that level which feeds down to the team.  That portfolio level needs to know where these epics are in terms of progress (To Do, In Progress, Complete).

For small projects, probably okay to get rid of the epics and just work with the one team backlog.  As this scales up, however, you'll probably need to separate the team backlog from that portfolio-level backlog and track the epics separately.


问:
JUnitEE vs JUnit
I know what unit testing is in general and what JUnit is in particular. But here I see that there is a project called JUnitEE which seems to me to be a wrapper over JUnit. So I would like to better understand the pain point of using vanilla JUnit and how JUnitEE is able to solve those problems.

答:
It seems not so much a wrapper or replacement for JUnit, but an extension of JUnit to allow running tests on a J2EE app server. There are many similar projects, such as HTTPUnit for testing web application UIs and DBUnit for making Database fixtures easier.

But JunitEE hasn't been updated in almost 10 years, so I doubt it's very useful for (or even compatible with) modern Java EE applications.

Title: JUnitEE vs JUnit


答:
First, unsafe is useful for a lot more than C interop. For example, doing image analysis with actual pixel data can be horribly slow while in "safe" mode. Flip over to unsafe mode, and doing the same work with direct access to the image buffer, is an order of magnitude faster.

Doing wholesale development in C/C++ for inclusion in a .Net project can certainly make sense, but it all comes down to performance. The classic advice would be to write the entire application in your language of choice, then profile. When you find a critical section of code that takes 50%+ of processing time and cannot be realistically tuned anymore while using a managed language, then re-implement that one routine in C and integrate.

A real life example: I was prototyping a path finding algorithm. After showing it worked with C#, I needed to make it fast enough to run many times a second. I had already built up some nice support UI in C# that showed all of the factors used for routing decisions, the results, etc. So I reimplemented the core part of the routing algorithm in C++. If I had started in C++, I doubt I would have gotten as far.


问:
Developing a cross-platform interface for writing to hardware like PicKit OR USB over the web?
I thought long and hard on weather to put this question in programmers or stack overflow. Please let me know if this is not the right place and I will post it to SO.

My friend and I am developing a display board that would need some configuration every now and then. e.g. setting contrast / backlight etc. Now this setting needs to be user controlled and we have prior experience of using PicKit2 in past. The way we programmed it was with use of command line / binaries available for both linux and windows. A front end would get the user input and then write to the pickit2 using these command line interfaces.

Our target is to try and achieve this through a web interface. Now we want to discuss with the community if there is a real possibility of developing such a cross platform interface? As a backup option we are thinking of developing native application for all needed platform and using pickit2 with command line.

Ideal way would be to just have the USB HID to do this. I looked into java USB libraries and ActiveX but nothing promising. Similar discussions around this topic are quiet old on StackOverflow so I thought I will ask this community to shed some light on possibility and limitations.

https://stackoverflow.com/questions/3503244/controlling-a-usb-device-from-a-web-application
https://stackoverflow.com/questions/2219378/control-a-users-usb-device-via-a-webpage-possible

Is there any option we are not thinking about?
Should we be happy that pickit2 is the backup solution and start developing different native apps.

答:
A front end would get the user input and then write to the pickit2 using these command line interfaces.

This is basically your answer, but You need a Web Exposed front End. That means a web-server running on the same machine as the USB Device. This way it's Server side code - Local to the USB Device  controlling the hardware. (The answers in you links assumed a your web-server with the hardware local to the user )

A common example of this are web enabled security Cameras. you can watch and control the camera from web interface. Also, because the camera is it's own device, the manufactures installed a lite wight web-server directly in cameras Firmware, so only a bit of router configuration is needed to be up and running. (Embedding the webserver in the firmware resolves all cross platform issues, there is only one Platform!)


答:
I am not a lawyer, and if you want an answer to rely on, consult a lawyer who specializes in copyright law, ideally with a focus on Open Source / Free Software.

That said, copyright is seldom transferred implicitly - a notable exception is work-for-hire, which is the default in some countries and a standard clause in employment agreements in others. With Open Source software, it is usually considered the project maintainer's responsibility to ensure that the distribution of the project meets the law, and that distributing it under a certain license does not violate any copyright nor any existing agreements and licences. There are two standard ways of going about this:

a) Only accept contributions that have been released under a compatible license by their respective authors; this approach requires no paperwork, but some diligence, because the project maintainer can be held liable if anything gets included and republished in a way that violates the original license (e.g., including GPL code in a project released under an MIT license).
b) Make the contributor sign an explicit copyright transfer agreement, usually in exchange for a promise to release it under a free license. Sometimes, copyright is not transferred, but an irrevocable license is granted instead that gives the project maintainer close to the same rights as a copyright transfer would have; it does, however, allow the original author to release their own code (but only that!) under a different license outside the main project.

This leads me to believe that unless you explicitly agree to a copyright transfer, you still retain full copyright. I would also expect though that sending a pull request could be interpreted as an implicit agreement for your contribution to be distributed under the same terms as the main project, i.e., if you submit patches to a GPL project, it can be assumed that you do so with the intent of having them included and distributed as part of the project.

Nonetheless, whenever I receive a contribution for any of my projects, I explicitly ask whether they agree to me including and redistributing their work.

Title: Could submitting a Pull Request ever constitute accepting a Contributor Licence Agreement?

Body: Some software projects have a Contributor Licence Agreement. The agreement could, for instance, assign copyright of 3rd-party contributions to the original project creator.  Could submitting a Pull Request on github ever constitute accepting such an agreement?</p>


问:
Python code style - blank lines in long list
I'm curious, is there a standard approach to dealing with long lists in the Python community, and in particular, is there any antipathy toward doing blank lines followed by comments to break up a particularly long list, e.g. of tuples, or in a dict, etc.?

For example, I'm developing a GUI application in wxPython, and am defining the keyboard shortcut mappings to . Is this fairly Pythonic?

accelerator_table = wx.AcceleratorTable([
    # Case accelerators
    (CTRL, ord('S'), EventIds.SAVE_CASE),
    (CTRL_SHIFT, ord('S'), EventIds.RENAME_CASE),
    (CTRL, wx.WXK_DELETE, EventIds.REMOVE_CASE),
    (CTRL_SHIFT, wx.WXK_DELETE, EventIds.DELETE_CASE),

    # Project accelerators
    (CTRL_ALT_SHIFT, ord('S'), EventIds.RENAME_PROJECT),
    (ALT, wx.WXK_DELETE, EventIds.REMOVE_PROJECT),
    (ALT_SHIFT, wx.WXK_DELETE, EventIds.DELETE_PROJECT),

    # Help accelerators
    (NORMAL, wx.WXK_F1, EventIds.HELP),
    (NORMAL, wx.WXK_F2, EventIds.LAUNCH_MANUAL),
    (NORMAL, wx.WXK_F12, EventIds.ABOUT),
    ...
])
```

The details aren't particularly important, but I'd like to write in a style that will not annoy other programmers along the way, and therefore to decide right now whether this pattern is worth keeping around.

Edit: Just to clarify: I'm not intending to put anything beyond that single blank line between sections in the list. That seems like it should minimize any confusion on the part of someone reading through the code.

答:
[snip due to people not reading the /entire/ response]

To answer your actual question, whitespace is fine to break things up visually, but I'd recommend that the number of lines that you use should not exceed that of the number of lines between other entities in your code (such as number of lines between functions within a class, or module-level classes or functions). As Python's readability is so heavily based on whitespace, using more whitespace in a particular method to break up internal code might initially throw off a reader looking to grok it at a glance.

Edit based on comments:

```<code>>>> accel_file = [('a','b'), ('c', 'd')]
>>> accel_project = [('e', 'f'), ('g', 'h')]
>>>
>>> from itertools import chain
>>> list(chain(accel_file, accel_project))
[('a', 'b'), ('c', 'd'), ('e', 'f'), ('g', 'h')]
</code>```

Grouping as such allows your code to be self-documenting. chain is an overly complex solution in this particular case (I was writing code using at the time of the answer :P), but could be useful if doing something like:

```<code>accelerators = [accel_file, acces_project, ...]
list(chain(*accelerators))
</code>```

But for the simple case, concatenation (+) would be preferred.

Body:
[snip due to people not reading the /entire/ response]

To answer your actual question, whitespace is fine to break things up visually, but I'd recommend that the number of lines that you use should not exceed that of the number of lines between other entities in your code (such as number of lines between functions within a class, or module-level classes or functions). As Python's readability is so heavily based on whitespace, using more whitespace in a particular method to break up internal code might initially throw off a reader looking to grok it at a glance.

Edit based on comments:

>>> accel_file = [('a','b'), ('c', 'd')]
>>> accel_project = [('e', 'f'), ('g', 'h')]
>>>
>>> from itertools import chain
>>> list(chain(accel_file, accel_project))
[('a', 'b'), ('c', 'd'), ('e', 'f'), ('g', 'h')]

Grouping as such allows your code to be self-documenting. chain is an overly complex solution in this particular case (I was writing code using at the time of the answer :P), but could be useful if doing something like:

accelerators = [accel_file, acces_project, ...]
list(chain(*accelerators))

But for the simple case, concatenation (+) would be preferred.


问:
Is it bad practise to create instances from a SQL-query?
I'm researching ways to create a OO-model/repository-layer using PHP's PDO. My idea was to create model classes that represent a domain object and a repository class for each model that has the responsibility of:

Saving to the database by taking a model as argument and mapping the objects properties to the VALUES of the SQL-query.

Reading from the database by return an instance of a model in a similar fashion.

I was inspired from a course in OOP in which we used .NET, EF and LINQ for the Labs.

I asked a question on SA about how this could be achived on SA. I got flamed because is is supposedly bad practise.

I don't see why this is the case.

答:
There are already libraries that do what you want available for PHP. It's called O/RM or Object/Relational Mapping. Not being a PHP programmer myself, I'll relegate suggestions to the experts

Funny, that's not the first time I've seen people arguing against using objects to represent database records in dynamic Object-Oriented languages. I recently read a Python thread arguing to just access the data record directly. Frightening to say the least.


问:
Converting Business Process Maps into Software
I am fairly new to web application development. I have defined my problem domain through talking to various stakeholders and putting a process map together - basically a flow chart showing the different steps and processes that the web application must be able to recreate.

The problem I am having is that I'm struggling to map this process into application design and code. I was wondering if there are any best practices or development methods that help map a business process into an application design?

I have briefly read up about Domain Driven Development and that seems like it may be a good approach.

To clarify, I am after a methodology or design principle that will help turn the business process into code. For example, I COULD just map every box in the process map to an identically named class in my code. Thus translating the business process into a domain model (i.e. object orientated) in my code. But is this the best way to do it?

答:
After a bit of research I've come across the repository/service design pattern. Both are used within the model context of MVC design pattern.

A repository (in my case an ORM) is a model that gets and saves directly from and to a database table sharing the same name. A service (I have actually called mine a 'process') is a model in the MVC sense, but contains a lot more logic than simply just getting and saving from and to a database table.

A 'process' model performs all the necessary logic and uses multiple repositories to get and save persistent data.

What I have done is develop my database to 3NF and setup a repository model for each table. If my application just requires the data from a table, the controllers call the required repository model directly. For a business process that requires the use of several tables, I create a process model. The name of this process model directly maps to my business process and performs the same steps. This has made translating the business process map into code really easy.

Would appreciate any thoughts people have on this approach?


问:
Enterprise knowledge sharing?
I recently read this article on knowledge sharing and immediately recognized the same problem within my own organization. My main goal now is to 'kill peer-to-peer collaboration' as the default method of communication for non-private, system related discussions. Otherwise you end up with all of the historical knowledge living in the heads of individuals, or lost in a massive email system.

My question for the group is as follows:

What methods / software have you used to encourage more 'public' discussions among your developers?

Some initial ideas I had.. any feedback would be great:

Internal news group

'better' wiki software (using Sharepoint now)

Message board

(I would love to have an internal instance of StackExchange, but don't think that is an option!)

Note: As stated above, we already have a wiki, but I dislike the wiki idea because things are usually only added to the wiki after the fact, if at all.

Thanks!

答:
StackOverFlow for enterprise like explained in the article you mentionned?

IMHO it's a terrible idea.

It will reinforce competition instead of collaboration.

You need cross division/department collaboration, not increasing their competition.

Also imagine the extremely high negative impact of being downvoted by your coleague (in front of others) can have on your psychic health.

Don't mix everything.

However, an idea box much more uservoice.com where employees can post ideas (anonymously) and other employees upvote them (also anynomously) will have a positive impact. I developed a such platform few years ago for a very large banking institution, and it helped executives to identify what to improve in priority.

Title: Enterprise knowledge sharing?


问:
How do objects fit into modern C++ (stl, policy-classes, functional) style?
I'm a bit confused so the question is a bit confusing. TL;dr: how to mix STL and OOP?

From the comment to Best overview to modern C++ paradigms? and http://www.boost.org/community/generic_programming.html there isn't much about objects-oriented programming. (boost guidelines mention object generators).

When planing a program, it seems that STL and objects should fit well together. You think of an algorithm and how to do things, then you think of what are the things you want to work with and what properties/characteristics they have. You express those things in terms of tuples and containers and you apply algorithms to them. From my understanding, that's STL style of thinking.

Now this is where objects come in. They are things that you do stuff with that contain data, algorithms that change that data and interfaces. But that overlaps with idea of stl where you separate data and algorithms.

In OO you combine data and algorithms and in STL you separate it.

Although mathematically and generically STL make more sense (when you can apply the algorithm to anything), it is easier to think conceptually in OO style when you have a lot of different objects and algorithms -- you get a better organization. For example, qt-style advocates using minimal and orthogonal interfaces specific to a class as oppose to general algorithms. I said specific because their objects are different and they ask for minimal interfaces meaning objects won't share the same interfaces.

So the question is: "can you get away with STL in modern C++ or should you use objects? and if you have to use objects then how?"

Other relevant questions at Stack Overflow:

What is so great about STL?

C++: Alternative to STL and Boost?

答:
I come from a background where most of my OO skills were gained using C#. However, most of my generic programming skills come from C++. I recently wrote a C++ project that recursively searched web sites for certain things (a web spider). I constantly ran into problems whenever I tried to mix OO and the STL.

Objects don't like to expose their internals. Those internals are the data structures (vectors, maps, etc.) that other objects want to interact with. It always felt clumsy to create accessor/mutator methods for these data structures. Consumers of my classes couldn't use the STL to grab and manipulate my data as they saw fit.

It is very easy to use the STL within the confines of a class. You have everything you need. But when you start interacting with other objects, using the STL is difficult without violating encapsulation. One topic I researched heavily was generic iterators (iterators that don't expose the underlying collection type). Even with generic iterators, your consumer needs to know whether the iterator is random access, forward, bi-drectional, etc.

Another approach I adopted later was passing functors to member functions. One object would pass a functor to another object's member function who would then pass it to an STL algorithm. At times I would have to decorate/adapt the functor to not expose implementation details about how data was stored internally. The problem with this approach was that it became difficult to know who "owned" a piece of functionality. Additionally, it meant that these member functions were templates, which limited where I could define their implementations. A lot of the problems I ran into with template member functions will be going away with C++11.

I ended up making classes that I felt were very exposed or whose implementations were spread out across too many other classes. A lot of this came from my desire to avoid writing explicit loops and avoiding inefficiencies. I believe on a professional project I would probably limit my use the STL to within the confines of my classes. I spent way too much time trying to use the STL everywhere I could.

By now it should be obvious that I'm probably not the best person to provide advice. I just wanted to share with you that the two styles are not always easy to combine. Bjarne Stroustrup's book The C++ Programming Language emphasizes how C++ was designed to allow programmers to switch between paradigms as needed. I don't think he intended the language to make it easy to combine them necessarily. Most of his examples regarding OOP touch the STL very little. He creates very distinct layers.

I'd recommend poking around my project to see how I used the STL across object bounds. Like I said, it's not perfect but it will provide some examples which may be useful.


答:
Well, I don't know Mr. Caner, but IMHO

tests that do not potentially find errors

are a waste of time. That includes the situation where you already have some tests (it does not matter if they are automatic or just on a checklist), and you add new tests which validate essentially the same cases you already have. So your new tests won't find any more errors than the existing ones.

Such a situation can happen, for example, if you just through a list of randomly - I could say also "brainlessly" (forgive me that word) - choosen test cases at your program, without thinking if they check new edge case, new equivalence classes of your input data, or if they increase code coverage in relation to the already written tests.


问:
How to train junior programmers for today's (complicated) web environment?
Currently our company develops applications consisting, most of the time, in Ruby on Rails web servers and a bunch of different REST clients, from kiosk systems in Java to embedded devices in C/C++ (besides the interfaces for standard web browsers). We need to expand our team and, having failed at finding good senior programmers, we decided to put some effort into training junior programmers who would grow together with the company.

We've already given them some Ruby and Rails books and asked them to build some toy programs, but I'm now realizing how steep the learning curve for the current state of web programming is.

When I started programming 15 years ago I used only Delphi and Source Safe and was able to produce usable software right from the beginning. They were both simple tools and it was easy to delve into the inner workings of the environment. Slowly I started using third-party frameworks, have switched to CVS, SVN and finally Git, learned the pieces which make today's web, like HTTP, JavaScript, CSS, REST etc. Today, even after years of experience, I don't know as much about how Ruby on Rails works inside as I did in the past about Delphi, and for me that was important so I could connect the basic learning blocks to the tools I was using.

It seems to me that the programmers I'm hiring will take a long time to integrate with the team and produce something usable, because there's so many things to learn to use a single framework (Rails): Ruby, HTML, CSS, JavaScript, REST, test-cases, database access (with SQL magically built inside the framework!), MVC, three different package managers (apt for Ubuntu, gem and bundler for Ruby), ssh, git, Apache and Phusion Passenger for deploying, etc.

I'm feeling lost since it's the first time I need to deal directly with junior programmers. What is the best way to train junior programmers in today's best practices for web development when there are so many choices?

答:
The toy applications you're asking them to do should implement some basic CRUD functionality, and each developer should write their own code.  But you can discuss the application in code reviews, and offer tips.  They will need to understand the overall architecture of an MVC application first, if any reasonable expectation of productivity is possible.

From there, each developer should be able to strike out on their own into the associated subjects like Javascript, CSS, DAL's, template generators, routing and so forth.  You can give them guidance on which topics to study (it can be based on your company's most pressing needs), mentor them, and monitor their progress.  Move developers one at a time to simple projects that produce functionality that will move your actual development effort forward, the moment they demonstrate a grasp of the necessary skills.

You can pair some of your experienced developers with an apprentice as a sort of mentoring program.  There should be guidelines available for the junior developers so that they know when they can interrupt their mentor, and for how long.  Their mentor can supervise their work when they start writing real code.

You will have a better time of it if you can find young people who are very smart, intellectually curious, and self-starters.  I've seen this process work; it was my prior employer's approach, since he didn't want to pay the big bucks for experts, although it was more of a "sink or swim" kind of thing (there was no formal training program as such).  His biggest challenge was getting them to stay long enough to recoup his investment; there was always the lure of better pay somewhere else.


答:
Pair Programming is a great way of disseminating tacit knowledge.

The problem with tacit knowledge is that it can pretty much by definition not be written down or taught, only experienced. Pair programming (specifically Promiscuous Pairing) provides that.

Title: Enterprise knowledge sharing?

Body:
I recently read this article on knowledge sharing and immediately recognized the same problem within my own organization. My main goal now is to 'kill peer-to-peer collaboration' as the default method of communication for non-private, system related discussions. Otherwise you end up with all of the historical knowledge living in the heads of individuals, or lost in a massive email system.

My question for the group is as follows:

What methods / software have you used to encourage more 'public' discussions among your developers?

Some initial ideas I had.. any feedback would be great:

Internal news group

'better' wiki software (using Sharepoint now)

Message board

(I would love to have an internal instance of StackExchange, but don't think that is an option!)

Note: As stated above, we already have a wiki, but I dislike the wiki idea because things are usually only added to the wiki after the fact, if at all.

Thanks!


答:
One thing that you should be careful to not forget is that C++ is a multi-paradigm language. It is a language that supports abstractions from low-level imperative code up to high-order functional code, and almost everything in between.

The standard containers (not the STL - that's a mostly unrelated library) are a type of abstraction that sits closer to the functional part of the paradigm spectrum. It provides the most generic interface possible to a category of standard algorithms, in a form that follows a functional style - a style in which algorithms and data structures are described in very high-level but consistent terms.

This is not at odds with the object-oriented paradigm that you are likely accustomed to. Rather, it is both orthogonal and complementary.

The reason modern C++ discussions don't revolve much around object-orientation is simply due to the fact that objects are merely one of the many tools C++ offers to model the computations that underlie user-defined types.

To restate that another way: The focus in modern C++ is in types. Objects happen to be used to model the behavior of some types, and templates and functions model the behavior of other types.

This is not the "STL way of thinking," rather, it is a paradigm that takes full advantage of the functional paradigm in that way in which C++ can support it.

When planning a program, you determine the core behaviors and the superstructure of the data model. Then, you build a computational model that incorporates both the behaviors and the data model. Indeed, you should think first about the data model, then the algorithms to operate upon it.

The standard library provides the most commonly-used linear data structures and algorithms that mutate them. Lists of various kinds happen to be the most convenient and easiest to model of the major data structures, and the functional paradigm teaches us that the most convenient algorithms for those data structures are the ones which the standard library chose to provide. The rest of C++ (classes, inheritance, functions, templates, etc.) provide a powerful way to model those data structures and algorithms efficiently, without sacrificing their genericity.

The way in which you choose to implement your data structures and algorithms doesn't matter to C++: It provides you with all of the tools you need to model computations in whatever form you find convenient. But that expressive breadth comes at the cost of complexity. Some models that you may choose may not be type-safe. C++ allows you to use them, but it also provides models that are type safe and generic.

Your question is, I think, the wrong one.

The question you should ask is not "should I use the standard containers or use objects," but rather, "What class of algorithms and data structures most clearly models my program?"

If you have a need for a simple data structure and the primary operations on that data structure are closely modeled by the standard algorithms library, by all means use it. They are part of the standard library because they are meant to be useful. It happens to be complete, in that it provides all of the high-level abstractions your program will ever need, but it may not always do so in a way that makes your code clear. This is why C++ provides all of its other tools: To give you a way to model your own kinds of abstractions.

Title: How do objects fit into modern C++ (stl, policy-classes, functional) style?

Body:
I'm a bit confused so the question is a bit confusing. TL;dr: how to mix STL and OOP?

From the comment to Best overview to modern C++ paradigms? and http://www.boost.org/community/generic_programming.html there isn't much about objects-oriented programming. (boost guidelines mention object generators).

When planing a program, it seems that STL and objects should fit well together. You think of an algorithm and how to do things, then you think of what are the things you want to work with and what properties/characteristics they have. You express those things in terms of tuples and containers and you apply algorithms to them. From my understanding, that's STL style of thinking.

Now this is where objects come in. They are things that you do stuff with that contain data, algorithms that change that data and interfaces. But that overlaps with idea of stl where you separate data and algorithms.

In OO you combine data and algorithms and in STL you separate it.

Although mathematically and generically STL make more sense (when you can apply the algorithm to anything), it is easier to think conceptually in OO style when you have a lot of different objects and algorithms -- you get a better organization. For example, qt-style advocates using minimal and orthogonal interfaces specific to a class as oppose to general algorithms. I said specific because their objects are different and they ask for minimal interfaces meaning objects won't share the same interfaces.

So the question is: "can you get away with STL in modern C++ or should you use objects? and if you have to use objects then how?"

Other relevant questions at Stack Overflow:

What is so great about STL?

C++: Alternative to STL and Boost?


问:
Are there any reasons not to accept a software deliverable as a virtual machine?
This is a question about logistics, not a technical question.

My company has outsourced some embedded software work.  Specifically, we have payed a contractor to develop an embedded system for us since we do not have adequate in-house knowledge to do it ourselves (we only have desktop application developers).

So, the contractors have finished the software and they have asked if they may deliver it to us in a virtual machine.  The VM is a Windows 8 machine containing the pre-configured CodeWarrior IDE with the source code as a CodeWarrior project.  The idea is that this will allow us to make code changes within the VM that is already configured for further development of this project.

Are there any drawbacks to doing this as opposed to having them walk us through how to configure our own development machines to make code changes to the project?  The only problem I can foresee is the VM running slowly and it taking a long time to rebuild the project when we make code changes.  But on the other hand, I like the idea of getting a pre-configured embedded system development environment so I don't have to add yet another IDE on my desktop application dev machine.

I can't really think of a good reason why not to accept a VM deliverable, but I just wanted to run it by this community in case there's something I'm missing.

答:
I would not accept VM as a code deliverable because it makes it hard to make updates. You have to have that VM as a golden image to do development work. That makes it harder to make mods. A developer has to reformat, or gets a new machine, they have to install a VM and pull the VM.

When you make edits, you have to commit a new "golden copy" of the VM. Why would you want to  manage a big binary file like that in source control? It's not possible to diff, and in my experience trying to source control a golden copy of anything binary doesn't end well. Unless you can maintain strict control over who edits the golden copy, you will end up with stuff in there that is undocumented and no one knows about.

If a developer wanted to deliver software to me in that form, I'd find a different developer. This tells me they aren't professional enough to script out their dependencies, or at the very least document them.

I'd have them either:

Create a text file that gets checked into source control with the code. It lists all dependencies that you need to get the project up and running, that aren't part of the source control repo (e.g., CodeWarrior, whatever command line tools, or other external apps you depend on).

A script to install the dependencies. Since you are on Windows, it shouldn't be too hard to create a Chocolatey script to automate the setup of the dev environment. Any dependencies you have that aren't already chocolatey packages, you can make. For example, you can install heavy commercial tools like Visual Studio and SQL Server via Chocolatey. Those packages install the trial versions, which are full featured, and can be unlocked by entering a license key. So it's possible the same thing can be done with CodeWarrior, and any other dependencies you have for your dev environment.

Maybe your developer is really good enough that you still want to work with him/her, but isn't good at this automation stuff. That's fine too, if that were the case, I'd either do the automation part myself, working with him/her to identify the dependencies and get the script working, or I'd get another developer who's good at the automation to do it. It should be done at the start of the project. A clean, barebones copy of a Win8 VM would still be useful because you can use it to test out your chocolatey script.


问:
Is it OK to partially change a collection with PUT or DELETE?
I have a collection of products in a product group e.g.:

```<code>product-groups/123/products
</code>```

If I need to add to the collection, is it OK that I pass only some products with PUT?

If I need to delete some products from the collection, is it OK that I pass filter data (an array of ID's) with DELETE?

What's the best way to implement the functionality in the spirit of ReST?

Edit: the items are links to separate entities, basically ID's of products.

答:
Usually, REST methods are intended to operate on a single entity/object (CRUD).

There are several options:

Treat your collections as entities and update them via POST

Create alternate, non-REST operations

The first one follows REST standards, but can be costly, since your collection objects/entities may be very large (updating a group that has thousands of products just to add/remove one product would be a heavy request).

The second option is preferred by many APIs, as a way to extend REST beyond the CRUD operations.

For example:

```<code>GET product-groups/123/products (list all the products in the group)
POST product-groups/123/products/append (POST a list of new product ids to append to the group)
POST product-groups/123/products/remove (POST a list of product ids to remove from the group)
</code>```

Many APIs use always POST for this extended operations, but nothing limits you to use other http methods (other than the limitation of GET and DELETE that needs to have an empty body)

Body:
Usually, REST methods are intended to operate on a single entity/object (CRUD).

There are several options:

Treat your collections as entities and update them via POST

Create alternate, non-REST operations

The first one follows REST standards, but can be costly, since your collection objects/entities may be very large (updating a group that has thousands of products just to add/remove one product would be a heavy request).

The second option is preferred by many APIs, as a way to extend REST beyond the CRUD operations.

For example:

GET product-groups/123/products (list all the products in the group)
POST product-groups/123/products/append (POST a list of new product ids to append to the group)
POST product-groups/123/products/remove (POST a list of product ids to remove from the group)

Many APIs use always POST for this extended operations, but nothing limits you to use other http methods (other than the limitation of GET and DELETE that needs to have an empty body)


问:
Release Management Tools with DVCS (Mercurial)
My development team is migrating from SVN to Mercurial. Having researched DVCS best practices, it has been suggested that we develop against feature branches of the repo mainline, test them separately, then cherry-pick the features we want in each release, before merging those selected branches into the mainline and eventually releasing it.

Question: What I'm looking for is recommendations for some sort of software tool that will make my role of "software release manager" easier, in that it will allow me to control (cherry-pick) which branches (features, bug fixes, etc) are merged (using Git, or Mercurial) into which software releases (in each environment), and be able to produce the binary deployment artefact.

Our applications are mostly Java Web apps, with a handful of Java Applications, and the projects built using Maven (v2).

I've looked around for release management tools, but nothing really fits the bill.

NB: Not all changes are released as soon as they are completed and pass QA - some are to be released at a later date, as part of a themed release

Things dismissed so far (based on recommendations in similar questions, in other SE threads):

Trac (seems to be just PM type stuff, which we already have with the Atlassian OnDemand offering)

Jenkins (plus other CI tools) - am looking for something to manage my releases, rather than a CI tool (we have used Jenkins in the past).

Mercurial Patch-Queues - I may well need this, but was looking at some sort of "nicer" interface to help me manage it.

ERP offerings - TBH, I didnt look too much into this option, as my initial feeling was that they were too heavy-weight.

BuildMaster, by Inedo - This was the closest match, by far, but was not quite suitable due to its lack of VCS branch picking/merging functionality. I would say however that this is a very nice piece of software, and would recommend it, if it fits your use-case, and is sensibly priced, even for Enterprise use.

Am currently evaluating the following tools:

Bitbucket Feature Branch management (since we use Bitbucket for our projects, seems prudent to evaluate their approach)

Since DVCS is new to us, these things may have been dismissed prematurely, so feel free to re-educate me. :)

答:
The issue I see here is more of a source management one -- what you really need to do is add a concept of a release branch which is where you can cherry pick feature branches to integrate and test. Any other tool you want to use can then be pointed at said release branch without having a whole lot off offline work.

Another variation on this concept would be to use a fork and pull requests to pull this stuff into a clean "release" repository for each release. I can't claim to have done this this way though.


答:
Looking at the OP's initial approach, it is immediately obvious to me what it's doing. I don't see that there are readability or maintainability problems with this at all, nor do I see that it violates any commonly-accepted Python conventions or idioms. It's clear, and it uses minimal syntactic boilerplate and extraneous operations to achieve its goal. I recommend sticking with this approach.

The implementation suggested by Demian's answer seems to create more problems than it solves. Returning a list from a property is usually not a good idea, because it creates an interface that will look identical to an attribute, but will exhibit bizarre behavior if used as such, e.g. t.file.extend(t.project) will not do what most users would expect, and will "fail silently", causing potentially confounding bugs.

The OP could use instance attributes or class fields instead of properties, but I'm not sure an object-oriented approach has much utility here (i.e. it seems to be using class syntax without employing actual OOP concepts).

But the suggestion to separate the tuple-list aggregate into multiple smaller lists, that are then concatenated and passed to wx.AcceleratorTable, seems sensible. The "right" approach is mostly a matter of preference, though I still prefer the OP's initial approach because it involves less list manipulation, and doesn't have any readability issues that I see.

Title: Python code style - blank lines in long list

Body:
I'm curious, is there a standard approach to dealing with long lists in the Python community, and in particular, is there any antipathy toward doing blank lines followed by comments to break up a particularly long list, e.g. of tuples, or in a dict, etc.?

For example, I'm developing a GUI application in wxPython, and am defining the keyboard shortcut mappings to . Is this fairly Pythonic?

accelerator_table = wx.AcceleratorTable([
    # Case accelerators
    (CTRL, ord('S'), EventIds.SAVE_CASE),
    (CTRL_SHIFT, ord('S'), EventIds.RENAME_CASE),
    (CTRL, wx.WXK_DELETE, EventIds.REMOVE_CASE),
    (CTRL_SHIFT, wx.WXK_DELETE, EventIds.DELETE_CASE),

    # Project accelerators
    (CTRL_ALT_SHIFT, ord('S'), EventIds.RENAME_PROJECT),
    (ALT, wx.WXK_DELETE, EventIds.REMOVE_PROJECT),
    (ALT_SHIFT, wx.WXK_DELETE, EventIds.DELETE_PROJECT),

    # Help accelerators
    (NORMAL, wx.WXK_F1, EventIds.HELP),
    (NORMAL, wx.WXK_F2, EventIds.LAUNCH_MANUAL),
    (NORMAL, wx.WXK_F12, EventIds.ABOUT),
    ...
])
```

The details aren't particularly important, but I'd like to write in a style that will not annoy other programmers along the way, and therefore to decide right now whether this pattern is worth keeping around.

Edit: Just to clarify: I'm not intending to put anything beyond that single blank line between sections in the list. That seems like it should minimize any confusion on the part of someone reading through the code.