by deepsun · 4y ago · 0 comments
1. Types in Python are implicit. It's really hard to explain that they need to always think about what type something is, especially when they haven't grasped the concept of types yet.
2. Indentation as part of the language. I thought it's a great thing for beginners, but it's actually confuses beginners that empty space affects your program, e.g. they think that spaces around assignment or arithmetic operators should affect their program too, which is not the case.
3. Ranges for iteration -- they just memorize the syntax blindly :(
So I started to wonder whether Pascal is better to learn for beginners -- you have to list all the types at the beginning, and no implicit conversions are done.
But now I think what about TCL? Maybe it'd be even easier for total beginners?
But once you accept that there are rules to follow, and that they are somewhat arbitrary, languages do differ wildly in the amount and obscurity of syntactic forms you need to learn just to get started. Just count the amount of different syntactic concepts in this simple program:
#include <stdio.h>
int main(int argc, char **argv) {
printf("Hello world\n");
return 0;
}
and compare it to the Python version.People are used to the idea of explicit delimiters, at least to some extent, thanks to punctuation. People are not at all used to whitespace having syntactic meaning. You can put as many spaces as you want between words, or sentences, or paragraphs, and it might look weird but it still means the same thing.
Semantic whitespace isn't a reduction in syntax, it just hides the syntax to fool you into thinking it isn't there, until it goes wrong and you suddenly have to debug it.
It's not a problem, it's just a tradeoff. Like 97 percent of all the other differences between programming languages. As to whitespace in Python -- it was counterintuitive at first, but once I grokked the rationale behind it, I've never been tripped up by it (to an extent that it would slow my thinking for more than a second or two).
Every language has random $foo that you have to get used to and step around once in a while. If you don't like Python, fine, go back to C and bash. They'll be happy to welcome you back with open arms.
it doesn't seem simpler, and any argument that it's faster or easier to type seems to fall apart the first time you need to paste code across different indentation levels, right? what's the upside?
You can put as many spaces as you want between words, or sentences, or paragraphs, and it might look weird but it still means the same thing.
No -- whitespace definitely has meaning in natural languages. It doesn't usually change the meaning much -- but it does affect it (where meaning of course includes tone and consideration for the reader's experience). Especially when it comes to the use of space between sentences and paragraphs.
As any good writer will tell you.
Later she taught programming. The first thing she told students was: "Computers are dumb. They will only do exactly what you tell them."
10 REM Computers are never wrong
20 PRINT "Please type a number"
30 INPUT A
40 LET A = A + 1
50 PRINT "The number you typed was"
60 PRINT A
After a few paragraphs of explanation I learned that computers do what you tell them to do, not what you want them to do. main()
{
printf("Hello world");
}
Some details are hidden by the compiler, but Python isn’t exactly pure machine language either.Semicolons and bracket are conceptually equivalent to significant white space (but more obviously explicit) and main is also a concept in Python (that is much more syntactically brutal than even its verbose c equivalent) that is hidden by the interpreter — which you also have to explain to beginners.
Compare with Python:
import sys
def main(args):
print("hello %s" % (args[0]))
sys.exit(0)
if __name__ == "__main__":
main(sys.argv[1:])
Which (of course) breaks when cut and pasting onlineI agree, and I think the problem you mention is a special case of the difficulty some people have to grasp the concept of definition in the mathematical sense.
Unlike "dictionary" definitions, they can be arbitrary: if I say "let S be the set of prime numbers greater than 13" you pretty much have to accept it, as long as it's well-formed and consistent.
On the other hand definitions need to be very precise. Natural language relies on "you know what I mean", which is a feature for most human-to-human communication, but it's not how mathematics and computer science work!
The differences do start to diminish if you add some requirements like "print out the name of the script and the passed arguments then some message to stderr".
Though it also showed the problem with teaching languages: The students were not that eager on it. They would have preferred a languages with better job prospects.
As motivation is the key for success to learning, yeah sometimes the language that offers the quickest benefits is a good choice. The strength of Python is that it has great libraries in very trendy fields that allow to get stuff done with very little knowledge. That is why both Python and JS (easiest to get a job) are good beginner languages. (That really hurts me to write as learning should not be solely focused on external rewards but such is the world currently)
That said, if I were to choose a language to teach programming then Lua would be the perfect candidate. It avoids the syntax pitfalls of Python as well as having much lower complexity while still being very powerful. Plus really great for gamedev so many motivating examples.
E.g. if they learn carpentry, and the classes teach them how to do dining chairs (proper tools, wood characteristics, drilling and gluing techniques). But in real world they'll have to make tables. Does it really matter if they learned to make chairs not tables?
And we shall not discuss the horrors of its build and dependency system, which I appreciate isn't the "language" but what good is a programming language if one cannot compile it?
- Go is also inspired by Pascal, but it has more of a foothold today, it shares the simplicity and the syntax is more natural and convenient than C and similar.
- It's a light language. You can approach it in terms of just functions (procedures) and data, as opposed to say Java (which unfortunately is one of the most used languages in to teach programming).
- The tooling is approachable, it compiles fast, there is no friction when it comes to automated testing, you get a static binary out of it etc.
- The std library is comprehensive and very easy to use. You can teach a ton of concepts with just that without ever having to worry about third party dependencies. A full web server, a CLI etc.
- It's low level enough so you can teach a bunch of important concepts such as pointers and constructs around pointers, allocation etc.
Nitpicks:
> compiles fast
That is totally irrelevant for beginners, as their programs <100 lines long. The best would be not having to compile at all.
> as opposed to say Java
Not really a big problem, actually. I watched how people learn Java in college (I was a pro at the time so helped them) -- they usually get main() definition from professor, and then just copy that file around. They write everything right in main() or in other static methods, so not a biggie it's all wrapped in some mystic "class Main {...}". But I think it's much better that:
1. They have to write types for all variables and no implicit conversions made.
2. If it's not in autocomplete -- it doesn't exist. Compare that to Pythons "len()", or Go's "append()" (and explain why result of append() needs to be assigned if it works without it).
Those who break past "the wall" and achieve any fluency at programming, can and will learn to start thinking in layered abstractions. And their programs will start to get bigger. Then it's time to move away from BASIC.
I moved to Pascal. Today, Python. But I agree with the above and about Python, that you are forced to handle abstractions, almost from the git-go. Perhaps what saves it is the ease of trying things, so if the functioning of a loop like "for i in range(10)" is confusing, just try it with a print() statement in there.
BASIC was also preferable on a timeshare machine. Waiting 10 seconds per line for a response seemed more tolerable than waiting 10 minutes for an entire program to compile and link.
LOGO has real depth, an elegant syntax, and there's an alternate universe where it has Python's niche as everyone's favorite scripting language. But it's effectively a toy language so there's nowhere to go from "learning".
Here's my hot take: before you teach anyone "the basics of programming", teach them how to enter formulas in a spreadsheet.