logoalt Hacker News

cameldrvlast Wednesday at 3:47 PM2 repliesview on HN

IMO Python used to be a great first language, but it's gotten much more complicated over the years. When I'm teaching programming, I want an absolute minimum number of things where I have to say "don't worry about that, it's just boilerplate, you'll learn what it means later."

In particular, Python having generators and making range() be a generator means that in order to fully explain a simple for loop that's supposed to do something X times, I have to explain generators, which are conceptually complicated. When range() just returned a list, it was much easier to explain that it was iterating over a list that I could actually see.


Replies

ziml77last Wednesday at 4:32 PM

It's probably best to act like more complex things are just syntax at the start. Leave the fact that something like range is just a normal function that returns a generator for later on.

Like if range was used like this:

    for i in range 1 to 100:
        pass
No one is going to ask how that works internally, so I don't think it's necessary to treat range(1, 100) any differently. For this usage it makes no difference if it's a generator, a list (excepting performance on large ranges), or if the local variable is incremented directly like a C-style for loop.
pjmlplast Wednesday at 8:38 PM

Python has made it into my toolbox around version 1.6.

It was already much more powerful than most people writing simple shell script replacements were aware of.

Thing is, very few bother to read the reference manuals cover to cover.