7 ms·
> Pascal and Smalltalk were just too weird A huge reason why C syntax is "not weird" is because its weirdness has been normalized. I didn't realize how absolu
by pyjarrett 5y ago
> Pascal and Smalltalk were just too weird
A huge reason why C syntax is "not weird" is because its weirdness has been normalized. I didn't realize how absolutely bizarre some of the things in it were until I was an undergraduate teaching assistant for a C programming class for Math and Engineering majors.
The big problems I remember:
- Why {} braces?
- Why A = B? They're not actually equal. This can be a huge conceptual stumbling block.
- Why is this function returning "void"? This makes no sense, that's not a function.
- Why A.B()? Period gets read as a sentence terminator and that function is being called with no parameters, which makes no sense.
- Why do we use square brackets [] and not parentheses () for arrays?
- Why do we need a ';' at the end?
- Lots of confusion over `&&` and `||`.
- Problems understanding `+=` and similar.
Old Smalltalk editors did some things to make the language more understandable, such as turning `:=` into an leftward pointing arrow and `^` into an upward arrow. Once I saw this in practice, it made a lot more sense to me. Not that Ruby and Rust both have the `|vars|` syntax.
Pascal-family languages like Ada look "too weird" because most people learned a C family language early on. It'd be like saying Russian or Japanese is a weird language because you only know Romance languages.
- formerly_proven 5y ago> - Why is this function returning "void"? This makes no sense, that's not a function. Personally the distinction between subroutines and functions always struck me as overly math-centric thinking, because it's not an interesting difference as soon as non-local state exists, which is almost always the case. > - =, += I don't quite get why this remains contentious; even in math these are somewhat overloaded ("=" in equations vs. "<=>"/"=" for equality of equations, for example); code simply is not math. Why would the symbols mean exactly the same thing in a different context? > - Why {} braces? Big braces have always been used to group stuff together (e.g. case distinctions, summaries etc.), so it kinda makes sense to use that for groups of lines, i.e. code blocks. > - Why do we need a ';' at the end? C/UNIX was originally written using actual teletypes, so not only does ";" make it easier to parse, but it also gives you a very explicit marker that you definitely reached the end of the statement. That matters when every line you're looking at when interactively editing a file uses up some paper.
- Jtsummers 5y ago> - =, += It's related to the same problem with = as assignment, note GP's context: Math and engineering majors. They have been taught, assuming they paid attention, that = is not an assignment but a relational statement. If they've never programmed before, having = as a thing that changes the system state is still new to them. This is a common issue I've seen in tutoring over the years, where students' mental model is closer to Excel than to <standard programming languages>. That is, if you do this: a = 10; b = 20; c = 3*a+c; printf("%d\n", c); // prints 50 They aren't surprised, but then they do this: a = 20; // this demonstrates part of their confusion, they half-get that it is an assignment printf("%d\n", c); // prints 50 ?!?!? They expected 80. So they haven't fully internalized that `=` means assignment and is not establishing a relationship between the thing on the left and the formula on the right. One of the key things that helps is teaching them to "read" a program, and to read `a = 10` as "a gets 10" or "10 is assigned to a". > Why would the symbols mean exactly the same thing in a different context? When you have one mental model that you've been taught for 12+ years and are 18-20 years old and don't have a ton of experience, this is confusing. That it is not or was not confusing to you is either because you had a learning experience that specifically targeted this confusion, you made the connection more readily (maybe closer to the top of your class than average), or are looking back on your past and neglecting how far you've come since you were that age and had that level of understanding.
- Dylan16807 5y agoI understand the confusion with = for assignment, but isn't the solution usually to use symbols like := or <-? So shouldn't += and friends be on the easy side of things to teach?
- Jtsummers 5y agoIt's hard to use := or <- as notational conventions when teaching C-syntax languages to novices. If you do, you're teaching them two things: The logical representation and the actual representation. They already have a lot in their heads so this only creates more confusion, "Why do I get a syntax error when I write 'a := 10'?" "Because that's just for the notes, not the code...". The problem with += (IME) is with the incomplete and incorrect model that students have, += is one of the situations that can force a realization that = in C-syntax languages is assignment and is not a relational expression. But if they haven't grokked that yet, it's jarring.
- jcelerier 5y ago> A huge reason why C syntax is "not weird" is because its weirdness has been normalized. I didn't realize how absolutely bizarre some of the things in it were until I was an undergraduate teaching assistant for a C programming class for Math and Engineering majors. To give another PoV: I've taught javascript to absolute beginners (graphics design students coming from humanities studies with pretty-much zero programming or general "scientific" ability) and the syntax, fairly close from C, was very much not an issue for them, unlike the maths required ; I had to spend much more time explaining how transformations in a 2D plane, vectors, etc... do work, than correcting syntax mistakes. In ~20 hours of class they were pretty much all able to write small programs with for-loops, conditions, etc. which did nice visual effects in p5.js so I'd say that teaching the basics of programming is an entirely solved problem in 2021 ; whatever the topic, you cannot expect to teach stuff faster to a whole classroom.
- futharkshill 5y ago> - Why A.B()? Period gets read as a sentence terminator and that function is being called with no parameters, which makes no sense. What C syntax is this referring to?
- arcticbull 5y agoYou can do that, with a structure and a function pointer. struct a { void (*B)(); } struct a A = { .B = ... }; A.B();
- futharkshill 5y agoGreat example, especially considering op found that he added that example as a mistake :D
- pyjarrett 5y agoI severely overloaded a reference to C-family syntax and should have provided multiple examples instead. I erred, by trying to avoid C, C++, Java etc. specific comparisons. What I should have written: - Why is "Foo()" a function is being called with no parameters, which makes no sense. - What is "A.B" Period gets read as a sentence terminator. I learned C++ and Java very early on in life and had never considered A.B to be an issue.
- futharkshill 5y agoI think the only "hard" part about the syntax of C are pointers. Reading e.g. i++ *a->b[0]