Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • 4
    I made sure to claim that this was simplified "as far as possible", because that's the best way to make sure someone clever comes along and finds a way to simplify it even further just to make me look silly. :) Commented Apr 24, 2013 at 1:51
  • 1
    I believe it's not easy to beat that! :-) it's a great improvement since the first version I published here Commented Apr 24, 2013 at 1:56
  • 1
    maybe we can combine the first 2 loops into one? by instantiating and starting the threads in the same for loop? Commented Apr 24, 2013 at 3:40
  • 1
    @DanieleB: Well, then you have to change the list comprehension into an explicit loop around append, like this. Or, alternatively, write a wrapper which creates, starts, and returns a thread, like this. Either way, I think it's less simple (although the second one is a useful way to refactor complicated cases, it doesn't work when things are already simple). Commented Apr 24, 2013 at 18:05
  • 1
    @DanieleB: In a different language, however, you could do that. If thread.start() returned the thread, you could put the creation and start together into a single expression. In C++ or JavaScript, you'd probably do that. The problem is that, while method chaining and other "fluent programming" techniques make things more concise, they can also breaks down the expression/statement boundary, and are often ambiguous. so Python goes in almost the exact opposite direction, and almost no methods or operators return the object they operate on. See en.wikipedia.org/wiki/Fluent_interface. Commented Apr 24, 2013 at 18:07