5 ms·
I've seen beginners, especially those without a very strong maths background, struggle with the concept of syntax. The idea that you need to put the thing you w
by codeflo 4y ago
I've seen beginners, especially those without a very strong maths background, struggle with the concept of syntax. The idea that you need to put the thing you want the program to do into a very specific form. That any deviation is an error, even though "it's clear" to humans. I think that's something fundamental beginners need to learn, regardless of the language they use.
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.
- qsort 4y ago> struggle with the concept of syntax I 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!
- analog31 4y agoWhen my mom was learning to program, she was annoyed that the computer did not recognize that "O" means zero, and "l" means one. Her old manual typewriter didn't have 0 and 1 keys. So her typing habit resulted in a lot of errors. Later she taught programming. The first thing she told students was: "Computers are dumb. They will only do exactly what you tell them."
- mvaliente2001 4y agoI was lucky and that was also the first thing I learned about programming (with the amazing 80's "The Home Computer Course" magazine). I still remember the first program I read: 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.
- tyingq 4y ago>and compare it to the Python version. 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".
- fijiaarone 4y agoThis is also perfectly valid c: 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 online
- brundolf 4y agoThe problem is that Python encourages this "it's all cool, man" syntactic mindset. "Just indent your code the natural way, don't worry about all that extra syntax like curly braces." And then it comes back to bite you when your "formatting" causes syntax problems. 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.
- akhmatova 4y agoThe problem is that Python encourages this "it's all cool, man" syntactic mindset. 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.
- smegsicle 4y ago> rationale behind whitespace in Python 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?
- akhmatova 4y agoWhich, given the universal consensus to use 4-space indentation in mature projects, basically never happens. What's the upside? Readability. And freedom from silly debates about which indentation style is best.
- 4y ago