Consider that such examples are often not about convincing, but teaching. That is, they often not trying to convince the reader, "Language X is better than language Y." Rather, the intent is more, "You already know language X, so here's some code in X. Now here's how you would do the same thing in Y." It's a pedagogical tool, rather than an argument tactic.
According to some people all mentions of PLs have to be evangelical and confrontational. :-)
Re:Rust for Python Programmers
by the_mitsuhiko on Wednesday May 27, 2015 @10:12AM
(#9611426)
You can also use a locked data structure in Rust. This was to show how to actually use mutexes. In theory (assuming a Python with GIL or locked dicts) you can get rid of the mutex as well. But this only works for such a simple example in any case.
The mutex generally works and was meant to show the relationship of the borrow checker and the mutability system to the mutex that moves checks to runtime.
Ok cool, I figured that was the case. I mostly sat down to write out the example to humour myself during my lunch break (as I said, I don't do much with threads so wanted to make sure I understood what was going on).
The ownership/borrowing system is really interesting, not something I'd seen before - though I guess other languages do it too?
Ownership/borrowing enforced at compile time doesn't exist in any other (practical) language. Though C++ has some runtime support for it and in C you would/should do it by convention.
Some people consider an abuse of list comprehensions if you use them just for the side effects. Why not just a plain for loop?
for t in threads: t.start()Believe it or not, it's the first time I've used a list comprehension for execution like that (other than when working interactively in ipython)! Originally I had a comment about how it was a non-idiomatic thing to do, but I deleted it.
What's strange is that I didn't even consider writing the for loop on a single line. I just never do that. It's clearly better in this case (than a list comprehension). In real code I'd just do it on 2 lines.
I plead guilty your honour, the one-liner syntax for loops is pretty frowned upon among pythonistas too. :-)
It's actually a style violation: https://www.python.org/dev/peps/pep-0008/
A minor peeve of mine is examples between languages that differ in ways that are unimportant (though maybe it can just justified as "idiomatic code"). It adds bias to the demonstration.
We could have written the python one like the following to wrap the lock up with the results structure (and get the automatic sorting behaviour, too):
Though, I've also taken other liberties to make it shorter. I normally stay away from threading in python because the GIL makes it a bit of a waste of time in most cases, and who needs the complexity in their lives?Again, thanks for the overview, I enjoyed it.