Python is a good learning language precisely because it hides those details. This allows people to the learn the basics like variables, loops, strings, etc without getting overwhelmed with too much at once.
This absolutely provides a good foundation to learn lower level concepts later, although going bottom-up and starting with a language like C is also a valid path.
It’s also worth noting that a large proportion of developers will never learn C++, and will stick to higher level languages their entire career. And another chunk will only learn the lower level stuff much later when they have many years of experience to lean on.
If your goal is to immediately become a C++ developer, then you should learn C++, but that isn’t most people learning to program.
>>> Python is a good learning language precisely because it hides those details. This allows people to the learn the basics like variables, loops, strings, etc without getting overwhelmed with too much at once.
I wonder if whether this is a blessing or a curse depends on the person who is learning it. For instance, my first language was BASIC in 1981, and so my gut reaction to discussions about learning languages is that BASIC lets you at least imagine the workings of the machine that's running your program. The teacher can draw boxes on the blackboard to explain 10 LET X = X + 1
And we weren't far from the machine. There were not very many turtles on the way down to the level of logic gates. I also learned how a microprocessor worked, reading books as a high school kid, and articles in Byte Magazine, something that would be laughable for today's big CPU's.
That's a bottom-up approach. For others, a top-down approach might be better, e.g., seeing mathematical equations develop, in beautiful notation, without caring what the machine is doing under the hood.
Another comment in this thread mentions the ability to read code. Python has sprawled. I've been coding in Python for 10 years (as a "scientific" programmer) and recently took a Python skills quiz. I mentor beginners. Yet I scored barely at the top of "average." I can't read the code that's in a lot of the more elaborate Python packages.
A problem is motivating people to learn a learning language when they know that they'll outgrow it.
I'm not sure I understand what's missing in python compared with BASIC.
Sure, you can teach students to write `print(" ".join(str(x) for x in range(1, 11)))` to print numbers from 1 to 10... but you don't have to do that. In fact, `X = X + 1` works just fine. The old school BASIC style like `X = 1; while X <= 10: print(X); X = X + 1` still works in python. (sorry for the lack of indentation)
What am I missing? (besides the misguided social expectation that you need to teach the fancy generator stuff to a total beginner...)
That's a good question. What I'm thinking of (revealing my age) is something more like:
10 LET I = 1
20 PRINT I
30 LET I = I + 1
40 IF I <= 10 THEN 20
50 PRINT "DONE"
And because BASIC really is that primitive, you can talk about what each line of code is doing, without too much fiction. The mental virtual machine is not radically different from the real machine.
The teacher would draw the variables as boxes with numbers in them, and update the numbers in the boxes with the eraser and chalk (further revealing my age).
In contrast, Python starts with everything is an object, with properties and methods...
But I agree about the fancy generator stuff. I think you can teach Python in the same fashion by limiting yourself to a few basic (sic) features, and adopt the same virtual machine fiction while remembering that it's a few more layers of abstraction away from reality.
Do mean "GOTO 20"? Because if you don't that line either makes no sense or has a "magic" implicit goto that has to be explained. Assuming you meant that as a loop then the equivalent in Python is hardly difficult to understand:
i = 1
print(i)
while i <= 10:
i = i + 1
print("DONE")
Same number of lines of code, `while` has a clearer meaning than the magic of your goto-less line, and is still somewhat clearer (more comprehensible control flow) than the goto version of that line. The only missing thing is the explicit line labels, but that can become a presentation format when discussing the code. Every editor you'd start a student with can show line numbers (and many show line numbers by default).
You don't have to start with "everything is an object", but you will get there quickly. Teaching procedural programming centered on numbers and strings and basic control flow in Python is not a challenge for a competent teacher. And then the language can grow with the learner as they gain understanding of computing and programming.
While learning, hiding details is important, but Python overdoes the abstraction. `for` loops and iterator based loops have been merged into one thing, and I am sure people write `for i in range(10)` without a good understanding of what the `range` function does. Even strings blur the line between individual characters and actual strings. The lack of clarity at these basic concepts is precisely why Python is not suitable as a first language, since it hides concepts that are prevelant in all other mainstream languages. As a result, I have often seen students develop bad coding habits and poor mental model of why their code works. Instead of learning proper programming concepts, they just know the syntactic sugar and abstractions that Python offers.
I do agree that Python provides a very small startup cost to writing code, the details are sacrificed to acheive this. This may be useful to capture interest/generate motivation and get a quick prototype/"helloworld" out, learning Python is only good for learning Python, not for programming in general.
Frankly I think classic c-style for loops are a terrible abstraction for beginners. Iterator based loops make sense on a high level ("I don't care how it works, I only care what it does"). And while loops make sense on a low level ("I can see how each piece works"). To a beginner, c-style for loops are just an obscure, implicit syntax for while loops.
> Even strings blur the line between individual characters and actual strings
IMO that's better than what C++ does, where it pretends that a character is a single byte. Whereas most code nowadays is using unicode, which means that code will break as soon as they try to store a non-ascii character in it.
If you can understand the “for i in” part means then range should not be hard to grasp. I would argue that someone new to programming with even a modicum of logic might be able to guess what range does easily .
Range is horrific for beginners. Try explaining to a kid learning coding why his times table program needs to say ```range(1,13)```. There are excellent reasons for this construction, and to prefer half-open ranges, but providing a good on-ramp for kids ain't one of them.
This absolutely provides a good foundation to learn lower level concepts later, although going bottom-up and starting with a language like C is also a valid path.
It’s also worth noting that a large proportion of developers will never learn C++, and will stick to higher level languages their entire career. And another chunk will only learn the lower level stuff much later when they have many years of experience to lean on.
If your goal is to immediately become a C++ developer, then you should learn C++, but that isn’t most people learning to program.