News for hackers. Stuff that matters.
Re:Rust for Python Programmers by aidos on Wednesday May 27, 2015 @10:09AM (#9611403)
That was a really interesting introduction. I hadn't looked at Rust before and that gave me a good feel for it. Thanks for putting it together, Armin.

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):

    import queue
    from threading import Thread
    
    def fib(num):
        return 1 if num < 2 else fib(num - 2) + fib(num - 1)
    
    def thread_prog(results, i):
        rv = fib(i)
        results.put((i, rv))
    
    def main():
        results = queue.PriorityQueue()
        threads = [Thread(target=thread_prog, args=(results, i)) for i in range(35)]
        [t.start() for t in threads]
        [t.join() for t in threads]
        while not results.empty():
            i, rv = results.get()
            print("fib({}) = {}".format(i, rv))
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.

Re:Rust for Python Programmers by scott_s on Wednesday May 27, 2015 @10:55AM (#9611785)
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.
Re:Rust for Python Programmers by Dewie3 on Wednesday May 27, 2015 @11:52AM (#9612210)
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.

Re:Rust for Python Programmers by aidos on Wednesday May 27, 2015 @10:21AM (#9611489)
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?

Re:Rust for Python Programmers by DasIch on Wednesday May 27, 2015 @10:39AM (#9611650)
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.
Re:Rust for Python Programmers by scardine on Wednesday May 27, 2015 @03:06PM (#9613605)
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()
Re:Rust for Python Programmers by aidos on Wednesday May 27, 2015 @04:08PM (#9613966)
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.

Re:Rust for Python Programmers by scardine on Wednesday May 27, 2015 @11:31PM (#9615919)
I plead guilty your honour, the one-liner syntax for loops is pretty frowned upon among pythonistas too. :-)
Re:Rust for Python Programmers by hobarrera on Friday May 29, 2015 @12:40AM (#9622701)
It's actually a style violation: https://www.python.org/dev/peps/pep-0008/
Re:Rust for Python Programmers by Phrodo_00 on Wednesday May 27, 2015 @10:18PM (#9615731)
Yeah, I also found weird that he'd check the type of the addend in the adding example, he just talked about protocols, and that negates their use, and instead forces inheritance.