Guido on python3 for beginners
tjreedy at udel.edu
Thu Feb 18 03:40:07 EST 2016
On 2/18/2016 2:27 AM, Chris Angelico wrote:
> On Thu, Feb 18, 2016 at 5:47 PM, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
>> There are more features in Python 3, so in that trivial sense of "more to
>> learn", I suppose that it is objectively correct that it is harder to learn
>> than Python 2. But I don't think the learning curve is any steeper. If
>> anything, the learning curve is ever-so-slightly less steep.
> Let's see... changes in Py3.
> 1) Division of two integers now yields a float instead of flooring.
> For someone fresh to programming, that's a Py3 advantage, although it
> can cause surprises elsewhere. But since 1.0==1, it's not going to be
> a problem for a new programmer. Advantage: Py3.
> 2) Strings are Unicode text, and files etc may need to have their
> encodings declared. Definitely causes some issues in ASCII-only
> situations, where a lot of other languages (notably including PHP, for
> the people building web sites) let you be sloppy. Advantage: Py3 if
> you speak any language other than English; otherwise Py2 in the very
> short term, neither in the medium term, and most definitely Py3 in the
> long term (no more "funny characters break my program" errors long
> after deployment).
> 3) Laziness. When you explain to someone what the range() function
> does, Py2 makes a list, but Py3 makes... a range. It doesn't really
> answer the question at all. When you ask Py2 for a dictionary's
> keys/values, you get a list; Py3 gives you a thing that mostly acts
> like a list, only it isn't. If you map a function over a list, you get
> back a lazy thing that will eventually call that function. Py2 often
> has less levels of indirection, ergo less things to try to explain.
> Advantage: Py2; the benefits (lower memory usage, etc) aren't
> significant to new users.
> 4) Exception chaining. You get more information when errors cascade.
> Advantage: Py3, easily and without any question.
> 5) print statement/function. Py3 forces you to put parentheses on it,
> which is no different from C's printf() or Pike's write() or any
> number of other languages where console I/O needs no language support.
> Maybe a tiny TINY advantage to Py2 in the short term, but as soon as
> you introduce the less basic features, keyword arguments are way
> better than the magic syntax the statement needs. (Also, trying to
> explain the interaction between the print statement's "soft space" and
> other console I/O is not easy.) By the time you've really learned the
> language, the advantage belongs to Py3.
> 6) The fact that the name "python" may not invoke the interpreter you
> want. Advantage: Py2, if any; there'll be times when they're on par,
> but Py3 never comes out ahead.
> 7) Whether or not the interpreter comes pre-installed on your system.
> As of a few years ago, that was a clear advantage to Py2 (most systems
> would ship with both, or neither, or Py2 only), but that's shifting.
> It's only a small difference, though; on Windows, you generally get
> nothing, and on any system with a decent package manager, you should
> be able to request either version with ease.
> It's actually a pretty tough call. Most of the Py3 advantages aren't
> for the absolute beginner; it's not easier to write "Hello, world" in
> Py3, and aside from the change to integer division, most of the
> changes won't benefit small-to-medium scripts either. The biggest
> advantage (Unicode by default) really only shows itself by sparing you
> hassles later on - it's not going to make your life easier in the
> short term, ergo it's not going to make the language easier to learn.
> Py3 isn't so much easier as _better_. There are specific situations
> where it's massively better, but for the most part, they're about on
8. 2.x has two subtlely different types of classes. The 2.x docs do not
document the type of builtin and stdlib classes. I discovered that
tkinter classes are still old-style in 2.7 when I backported a patch
from 3.x to 2.7 and it mysteriously did not work. Py 3 wins here. To
me, this alone makes 2.x a bad choice for most beginners.
9. Two integer classes and the nuisance of 'L' suffix. Py 3 wins for
beginners, at least. (Mentioned by Inaki).
10. Two except-clause syntaxes in 2.7, just one in 3.x. -1 syntax is
+1 vote for 3.x
11. To test is something is text, isinstance s, c), where 'c' is one of
str, bytes, unicode, basestring, (bytes, unicode), (str, unicode). +1
12. 2.7 has two different open' functions, open and io.open. In 3.x
these are the same opjects. I believe there are other 3.x backports
13. 2.7 has two ways to apply arguments to functions: apply and *args.
3.x only has the latter.
To my mind, the numerous duplications and overlaps in 2.7 that are gone
in 3.x make 2.7 the worse version ever for beginners.
Terry Jan Reedy
More information about the Python-list