News for hackers. Stuff that matters.
Re:Incrementally migrating over one million lines of code fr... by nvr219 on Wednesday February 06, 2019 @02:20PM (#19098730)
That "learn python the hard way" guy says don't use python 3. As someone who is at the "Hello World" stage, should I use 2 or 3?
Re:Incrementally migrating over one million lines of code fr... by doctoboggan on Wednesday February 06, 2019 @02:30PM (#19098860)
It is a good question, and I am glad you asked as many new python developers hear this advice from Zed.

I think in 2019 there is no question that you should be using python 3. Zed seems to be personally offended by both how the transition was handled and some of the design choices in python 3, but I think he is doing his readers a disservice if he is still recommending python 2 today.

Re:Incrementally migrating over one million lines of code fr... by outworlder on Wednesday February 06, 2019 @02:26PM (#19098811)
> That "learn python the hard way" guy says don't use python 3

They are wrong. There is no good reason to start with Python 2 for new projects. The reasons people stay on 2.x are institutional inertia and legacy code. A hello world program has none of these problems.

Re:Incrementally migrating over one million lines of code fr... by eesmith on Wednesday February 06, 2019 @03:09PM (#19099307)
The previous poster should have written "said" not "says". If you look at https://www.learnpythonthehardway.org/ you'll see the first paragraph starts "Newly updated for Python 3".

The work started around 2 years ago - https://zedshaw.com/2017/04/22/learn-more-python-rough-draft... .

Shaw doesn't "agree with the direction of Python 3", and regards it as "being a complete waste of human energy" - https://zedshaw.com/2017/08/26/what-if-it-worked/ . But that's different than saying that new projects, in 2019, should not start in Python 3.

Re:Incrementally migrating over one million lines of code fr... by kalimoxto on Wednesday February 06, 2019 @03:27PM (#19099498)
Shaw also declared that Python 3 is not Turing complete so I would take his Python 2/3 opinions with a heft grain of sea salt
Re:Incrementally migrating over one million lines of code fr... by eesmith on Wednesday February 06, 2019 @03:43PM (#19099689)
Covered in https://learnpythonthehardway.org/book/nopython3.html .

If I understand the trolling logic, "if it's impossible for Python 3 to support Python 2 then Python 3 cannot be Turing complete." This hinges on 'impossible' being used as a technical objection.

The argument should be that it's economically infeasible for Python 3 to support Python 2, not that it's technically impossible.

Re:Incrementally migrating over one million lines of code fr... by joshuamorton on Wednesday February 06, 2019 @04:25PM (#19100142)
Even then he's wrong. It's perfectly economically feasible to write a python2 interpreter in python3-the-language. Take an rpython based py2 interpreter and make sure the rpython code is py3 compatible.

What he suggests is that since the python3 interpreter cannot run python2 code, that somehow this implies that python3 the language is not turing complete. This makes about as much sense as saying that since gcc won't compile my Java code, C++ isn't turing complete. In fact it's the same statement.

And there are, in fact, valid reasons why the python3 interpreter cannot run both 2 and 3 code intertwined (mostly because things are ambiguous in such a situation. Does `{}.keys()` return a list or an iterator? How do you decide? Well you need to know if the code you're running is py2 or py3 in advance and you don't.

I include his original statement here: [1].

[1]: https://www.reddit.com/r/shittyprogramming/comments/5ejbr9/p...

Re:Incrementally migrating over one million lines of code fr... by eesmith on Wednesday February 06, 2019 @04:44PM (#19100354)
I made the statement about economically feasible, not Shaw. Based on many readings of the Python developer comments, there wasn't enough people time + money to make that happen for mainline Python, that is, CPython.

Your statement is perhaps true about Python-the-language. CPython has additional constraints, including specific details of reference counting and extension APIs, as well as the desires of the current developers. You'll note all the work that PyPy has had to do for that level of compatibility, and it's still not perfect.

My comment was with respect to "Shaw also declared". Shaw's posting is, in my reading, obvious mockery and not a declaration of a truly held belief.

I don't see how a flamebait posting in a Reddit group titled "shittyprogramming" means much about the contents of his book or the topic of this thread.

Isn't there something more substantial about his opinions to criticize?

Re:Incrementally migrating over one million lines of code fr... by joshuamorton on Wednesday February 06, 2019 @04:58PM (#19100491)
(his comment was quoted in shitty programming not originally made there. It was originally made in the blog post where NOTE I was trolling now appears, I just found the first quote in shitty programming).

My comment has nothing to do with cpython. Python2, the language and Python 3, the language, are ambiguous. The broader context for Shaw's comments were that the py3 interpreter should just transparently run py2 code. Without a flag, that's not possible. Not like hard, or a time investment, or something like that. But truly probably impossible. `print(b'b'=='b')` will give a different result in 2 vs 3. An interpreter can't transparently run both. It needs to know which is which.

As to your last question, not really. Very few of his opinions on py3 made any sense to people who were at all informed. The problem was, his audience is uninformed people.

Re:Incrementally migrating over one million lines of code fr... by eesmith on Wednesday February 06, 2019 @06:31PM (#19101285)
(I only have access to Reddit through a text browser, which makes it hard to figure out what's going on. I deliberately blocked Reddit at my firewall since I found the noise level entirely too high, and don't think this is an important enough topic to unblock.)

shrug I'm not here to really support or defend Shaw, only to say that kalimoxto's comment seems like a frivolous reason to disagree with Shaw's opinions on Python 2/3. Why not pick one of his more substantive statements?

What URL to you mean for the "blog post where NOTE I was trolling now appears"? https://learnpythonthehardway.org/book/nopython3.html ? The earliest archive.org entry for the page has the note:

> Yes, that is kind of funny way of saying that there's no reason why Python 2 and Python 3 can't coexist other than the Python project's incompetence and arrogance. Obviously it's theoretically possible to run Python 2 in Python 3, but until they do it then they have decided to say that Python 3 cannot run one other Turing complete language so logically Python 3 is not Turing complete.

Now, I happen to believe he's wrong - lack of staff and funding are perfectly reasonable justifications.

I listen to The Changelog podcast, and in episode #300 Shaw himself has argued that open source projects (including Python, though he didn't say that directly) are underfunded. "the strategy is if you keep the cost and the amount of money that these developers make down, then it’s easier to take their project and use it, and they can’t fight you back, they can’t sue you in court if you violate the GPL, all these things, and then you commoditize your complement, and off to the races".

As for Python 2/Python 3 co-existence, I'll note that Python/Tcl co-exist as part of the standard distribution. (Python calling Tcl for Tk calling back to Python.) I've had Python/R coexist. Shaw argues that the existence of something like .Net shows that general co-existence is possible.

I don't see him making the argument that it must be 'transparent'. But since I don't know the original source, I could have missed it.

FWIW, I considered writing a Python 2 tool to modify the AST and generate new code that would check for run-time behavior that was inconsistent with Python 3. For example, if x.values() where x is a dict was only used in an iter context, and x is never modified, then it doesn't need a list(x.values()) during the conversion.

In essence this would be a Python 3 implementation for Python 2, used to help identify problems that might come up in the 2/3 transition without jumping immediately to Python 3.

I couldn't get the business model to come anywhere near working. And since it's not hard for Python 3 code to create an AST for Python 2 and modify it, but no one has written a Python 2 in Python 3 implementation, even with the much greater demand, I again argue that it's an expensive project to do.

So anyway, I bit the bullet. Here are more substantive points:

> The end result of this defect is that most people will not bother switching to Python 3 as rewriting Python 2 code is the same switching costs as just using a totally different language completely.

This is not true. My switch from Python 2 to Python 2+3 took 2 months. It took several years to develop the application in the first place. The switching costs would have been far higher to switch to another language, even ignoring that I depend on third-party components which were already in Python 2+3 that I would need to replace.

> The strings in Python 3 are very difficult to use for beginners.

So far I've only taught 2 beginning Python courses for Python 3.6, vs about 20 for Python 2. I didn't notice much difference. Python 2 strings are also difficult. FWIW, I taught f-strings from the get-go, which worked for everyone. It's annoying that I have to also teach the two older forms. (Really, I point out they exist then ignore them.)

> The choice to not have Python 3 run legacy code will be the main reason it does not get adopted.

Since Python 3 is about par with Python 2 in use, Shaw's conclusion is wrong.

> "members of the Python project have actually told me this is impossible"

Names or citations/context would be nice. Shaw makes many statements concerning anonymous people. What did they mean by 'impossible' and did Shaw misunderstand them?

> There is no technical reason for the Python 3 version to differ from the behavior of the Python 2 version, they just decided that you should have to handle all the type problems related to Unicode and bytes with no help.

Python 2 didn't handle all the type problems either.

  >>> addstring("\xff", u"\u012c")
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "<stdin>", line 2, in addstring
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal
  not in range(128)
while in Python 3:

  >>> addstring(b"\xff", u"\u012c")
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "<stdin>", line 2, in addstring
  TypeError: can't concat bytes to str
> even the error message is macho and terse

Though the Python 3 error message in my example is easier to understand in this case than the Python 2 one.

Hmmm. Does the traceback let you know which expression caused the failure? I thought it was only to the line number of the expression/statement. That makes it difficult for anything to do better than simply report which variables were active in that line, like what the Django debugger does.

Re:Incrementally migrating over one million lines of code fr... by Alex3917 on Wednesday February 06, 2019 @09:28PM (#19102419)
> If I understand the trolling logic

Zed trolls as a didactic technique. Don't pay attention to what he says, pay attention to what he's actually trying to teach you.

Re:Incrementally migrating over one million lines of code fr... by viraptor on Thursday February 07, 2019 @06:44AM (#19104584)
This works if you have a small target group which understands it without explanation. Zed writes for the internet. That approach makes him a troll, not a clever teacher.
Re:Incrementally migrating over one million lines of code fr... by newen on Thursday February 07, 2019 @10:21AM (#19105692)
Wow, you are completely misinterpreting what he said here. Either that or you're repeating what other idiots on the internet said. Any CS undergrad would understand that he was making a joke when he said that.
Re:Incrementally migrating over one million lines of code fr... by nvr219 on Thursday February 07, 2019 @09:12AM (#19105303)
he still recommends starting with python 2
Re:Incrementally migrating over one million lines of code fr... by eesmith on Thursday February 07, 2019 @03:39PM (#19108364)
Not at https://www.learnpythonthehardway.org/ . Where are you getting the "still"?
Re:Incrementally migrating over one million lines of code fr... by bunderbunder on Wednesday February 06, 2019 @02:41PM (#19098971)
FWIW, the latest version of LPTHW is focused on learning Python 3.

Beyond that, I personally don't find the arguments presented in versions of the book that recommend beginners learn Python 2 to be all that compelling. They read to me as one complaint about string handling that's wildly at odds with my own experience, nestled in a great big bowl of sour grapes about the fact that the breaking changes are happening in the first place.

The library support issue is a consideration, but depends heavily on what you want to do. My own sense has been that it's tools that are primarily used by devops and sysadmins that have the poorest Python 3 support, whereas the rest of the ecosystem is more-or-less 100% migrated at this point. Many have already started to discontinue Python 2 support. So, if you're saying that you're at the "Hello World" stage, I'm guessing that you'll hit a lot fewer speed bumps if you just start with Python 3 and don't look back.

Re:Incrementally migrating over one million lines of code fr... by ldiracdelta on Wednesday February 06, 2019 @02:28PM (#19098842)
Python 2 support is sunsetting in 2020 after over a decade of python 2 and python 3 support. I'd recommend starting with Python 3. Many external libraries you may need will only be issued for python 3 and many external libraries will choose to not even issue bug fixes for python 2.
Re:Incrementally migrating over one million lines of code fr... by ageitgey on Wednesday February 06, 2019 @08:02PM (#19101964)
He's 100% wrong. Use Python 3. Don't spend a second thinking about Python 2.

His complaints are bizarre. He mostly claims that Python 3 sucks because he can't figure out how to convert his old Python 2 code to work on Python 3 easily so therefore a beginner couldn't possibly learn the language from scratch. But all of his examples are edge cases of him intentionally fighting against the changes in Python 3 by doing things that don't make any sense like trying to concatenate unicode strings with raw binary data. It's just the weirdest argument ever.

Python 3 makes almost everything slightly simpler and more logical - especially if you ever have to deal with unicode text. And since emojis are unicode and people love emojis, that means literally everyone.

Overall, he comes off to me like people who spend a lot of time ranting about USB-C ports when in reality USB-C is mostly great and honestly just isn't that big of a deal anyway. It's a strange hill to die on.

The only good historic argument for using Python 2 was that it used to be that some popular libraries weren't updated for Python 3 yet. But that hasn't been true for years. Nowadays you are more likely to run into libraries dropping Python 2 support than you are to find them not supporting Python 3. I can't think of a single remotely popular library that still doesn't support Python 3.

Re:Incrementally migrating over one million lines of code fr... by carbocation on Wednesday February 06, 2019 @02:22PM (#19098761)
I don't write a lot of Python (use it mostly when deep learning calls for it), but my understanding is that it's time to start with Python 3. I try to write Python 3 whenever I have to write Python.

https://pythonclock.org/

Re:Incrementally migrating over one million lines of code fr... by minimaxir on Wednesday February 06, 2019 @02:36PM (#19098930)
The bottlenecks to Python 3 acceptance were popular package and cloud environment support.

Both have been resolved.

Re:Incrementally migrating over one million lines of code fr... by 0xADEADBEE on Wednesday February 06, 2019 @02:42PM (#19098979)
One oft-overlooked externality is the time taken to migrate. If I maintained a Python 2 codebase and can use Pypy as a drop in replacement after 2020, I'd certainly be tempted to do so.
Re:Incrementally migrating over one million lines of code fr... by minimaxir on Wednesday February 06, 2019 @02:43PM (#19098992)
Correct, but the original comment was asking about new code.
Re:Incrementally migrating over one million lines of code fr... by phowat on Wednesday February 06, 2019 @02:26PM (#19098810)
Python 2 will be EOL'd on the 1st of January 2020. So you should definitely go with python 3.
Re:Incrementally migrating over one million lines of code fr... by 0xADEADBEE on Wednesday February 06, 2019 @02:39PM (#19098951)
It's worth noting that only the reference implementation (cPython) is slated for deprecation. To my knowledge, Pypy and others have no such plan.
Re:Incrementally migrating over one million lines of code fr... by raverbashing on Wednesday February 06, 2019 @02:53PM (#19099136)
Today, that advice is uncalled for

Use Python 3

Re:Incrementally migrating over one million lines of code fr... by happy-go-lucky on Wednesday February 06, 2019 @02:44PM (#19099013)
If this is your genuine question, I'm afraid you are ill-advised and your Google-fu is rusty.
Re:Incrementally migrating over one million lines of code fr... by ben509 on Wednesday February 06, 2019 @03:00PM (#19099214)
A great warrior with the most powerful Google-fu can simply ask a question and command his unwitting legions to look it up for him.
Re:Incrementally migrating over one million lines of code fr... by nvr219 on Thursday February 07, 2019 @09:15AM (#19105318)
I came here for good advice and I got it. I trust hn comments more than Google (maybe this is wrong of me...)
Re:Incrementally migrating over one million lines of code fr... by N3cr0ph4g1st on Wednesday February 06, 2019 @11:54PM (#19103093)
python 3 all day
[dead]
Re:Incrementally migrating over one million lines of code fr... by klardotsh on Wednesday February 06, 2019 @02:25PM (#19098795)
I can't downvote, so instead I'll call you out publicly. This is neither a productive nor appropriate response.

We can discuss the merits of Python 3 over 2 (almost all of which I full-heartedly would agree with!) without resorting to name-calling of "the other camp".

Re:Incrementally migrating over one million lines of code fr... by sametmax on Wednesday February 06, 2019 @02:26PM (#19098802)
After 12 years since v3 came out and the annual python survey showing 84% v3, i think it's really disrespectful from anyone to advice v2.

But retard is not a convincing argument, even if i'm tempted to use it too.

Re:Incrementally migrating over one million lines of code fr... by mserdarsanli on Wednesday February 06, 2019 @02:45PM (#19099014)
They are quite different languages with similar names, like java and javascript
Re:Incrementally migrating over one million lines of code fr... by ben509 on Wednesday February 06, 2019 @02:57PM (#19099181)
I saw an interesting article about how a million line production codebase was able to run simultaneously in both python 2 and 3, so I don't see how you could call them "different languages with similar names."
Re:Incrementally migrating over one million lines of code fr... by cpburns2009 on Wednesday February 06, 2019 @02:50PM (#19099087)
Python 2 and 3 are nearly identical. Yes, there's some backward incompatible changes. It's nothing like the gulf between Java and JavaScript which are only related in that they use C-like syntax. Java and C# have more in common than JavaScript.
Re:Incrementally migrating over one million lines of code fr... by ageitgey on Wednesday February 06, 2019 @08:06PM (#19101982)
That is not correct at all. Python 2 and Python 3 have relatively few syntax differences. You could teach someone the key differences in like 10 minutes.

In fact, I would even say that the difference between Python 2 and Python 3 syntax is far less than the syntax difference between traditional javascript and the latest revisions to javascript (ES6+).