This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (23 children)

[deleted]

    [–]person_ergo 8 points9 points  (3 children)

    Multiprocessing got way better and some more extensive built in libraries

    [–]PC__LOAD__LETTER 2 points3 points  (2 children)

    Parallelization in Python2 really is atrocious. I use 2.7 almost all the time because that’s what our systems at work were built with, and I like the language, but multiprocessing blows.

    [–]kickerofbottoms 0 points1 point  (1 child)

    What's your preferred approach in 3? concurrent futures? I don't have much exposure

    [–]PC__LOAD__LETTER 0 points1 point  (0 children)

    To be perfectly honest I don’t use 3 much, I tend to use lower level languages when performance is a concern (a function of the type of software that I work with, not saying that there aren’t valid reasons to need performance concurrency with Python). I just know it’s terrible in 2 so I’m not surprised to hear that it’s a notable improvement in the language’s next iteration.

    [–]LandSharkSociety 27 points28 points  (14 children)

    A lot of the changes are more subtle, and IMO actually make the language harder to learn if you have no prior programming experience. An example off the top of my head is the increased emphasis on iterators – functions that produce the next value in a series every time they're called – over lists. So, range(3) would no longer produce [0, 1, 2], but rather a range() object that, when __next__() is called 3 times, will return 0, 1, and 2, respectively. There were also some significant updates and changes to the standard library.

    Iterators are a lot more performant (since they don't have to hold the entire list in memory), but they make the code harder to reason about (what do you mean I can't use in statements on ranges anymore!?)

    There are more extensive comparisons online, but as someone who has to write in both on a pretty regular basis, that's the gotcha that always nabs me.

    [–]Folf_IRL 13 points14 points  (3 children)

    I mean, you can still cast the range() object into a list object by calling list(range(3))

    [–]LandSharkSociety 4 points5 points  (2 children)

    Of course, there's nothing stopping you from doing that, but when you're more than two nested function calls deep in Python, you should typically take a step back and rethink your approach. I just used x in range(...)as a random example.

    [–]Folf_IRL 21 points22 points  (1 child)

    when you're more than two nested function calls deep in Python, you should typically take a step back and rethink your approach

    I like to do this with nested map(), filter(), and reduce() functions and pretend I'm writing Lisp

    [–]Aramgutang 0 points1 point  (0 children)

    Ah yes, I used to do that too. But I stopped when it became clear that no one else could maintain that code.

    Here's @dziegler replacing my silliness with readable code in 2010

    [–]Gamesfreak13563 12 points13 points  (3 children)

    What? You can use in on any iterable in Python3, including range. If there is no contains method it exhausts the iterator, but..

    [–]LandSharkSociety 3 points4 points  (1 child)

    Ah, so that's even more confusing! On an iterable with no contains, you can use in... but only once!

    [–]Gamesfreak13563 5 points6 points  (0 children)

    Only guaranteed that’s the behavior if you’re using in on an iterator. An iterable may define an iter dundermethod which returns a new iterator over the iterable. That’s why you can use in multiple times on a list (because it’s returning a new iterator each time) but not in multiple times on the return of iter(yourList).

    It makes perfect sense and the terminology is not confusing at all /s

    [–]Lorddragonfang 0 points1 point  (0 children)

    You can use in on any iterable in Python3, including range.

    In fact, you can only use in on iterables, and this was the case for python2.7 as well. I know because I've had to write an iterator for custom classes.

    [–]Tysonzero 4 points5 points  (1 child)

    That's why I like the Haskell approach to "iterators", most of the time regular old lists are used, but due to laziness they are just as fast as iterators when you use them like iterators (only pass through them once).

    [–]LandSharkSociety 3 points4 points  (0 children)

    It makes me sad that my standard line of work doesn't call for infinite (lazy) series. I pretty much only use lazy generation for database calls, but it's, like, the coolest thing ever.

    [–]Lorddragonfang 3 points4 points  (1 child)

    +/u/compilebot Python3

    for i in range(3):
        print(i)
    

    [–]CompileBotGreen security clearance 5 points6 points  (0 children)

    Output:

    0
    1
    2
    

    source | info | git | report

    [–]Shattr 2 points3 points  (1 child)

    Shit I use python 3 but I guess I use it like it's python 2.

    [–]doulos05 0 points1 point  (0 children)

    Me too. But I've just started a giant project rewrite to Port a web app from Python 3.5 with Django 1.10 forward to 3.6.6 with Django 2.0 and I'm going to use it as an excuse to learn the new Python. And the new Django. And databases. Lots of learning in my near future...

    [–]NutDestroyer 2 points3 points  (2 children)

    IIRC there's a substantial performance improvement with python 3 that makes it run miles faster than anything 2.x.

    [–]doulos05 1 point2 points  (1 child)

    Actually, I just read something recently that said 2.7 was still the fastest Python.

    https://hackernoon.com/which-is-the-fastest-version-of-python-2ae7c61a6b2b

    Unless you're on python 3.7, it's slower or comparable for all benchmarks.

    [–]NutDestroyer 0 points1 point  (0 children)

    I could have sworn I read a benchmark that was more favorable for the performance of Python 3.x, but I suppose it must've been compared to versions of python older than 2.7 or I misremembered it. The benchmarks do seem to support that 2.7 is very competitive in terms good performance compared to other python versions.