5 ms·
Programming languages have settled on '=' for assignment and '==' for equality comparison. Teaching people non-standard syntax because you think it might be eas
by Asooka 4y ago
Programming languages have settled on '=' for assignment and '==' for equality comparison. Teaching people non-standard syntax because you think it might be easier is just doing them a disservice. Everyone I know that started with Pascal was mostly pissed that they didn't learn a language actually used in industry and had to re-learn the syntax. It's not like mathematical notation is intuitive in some way either - humanity needed several thousand years before we came up with something ergonomic, plus '=' is used for assignment in math just as often too. At least I do not know of any mathematician who uses ':=' to denote assigning a value to a name.
- nequo 4y agoMost programming languages but not all. Three prominent examples are Pascal which you mention, OCaml, and the POSIX `test`/`[` command which all use `=` for equality. (More specifically, for structural equality, in the case of OCaml.) More intuitive to complete beginners and definitely not unheard of. In mathematics, I have seen both `:=` and `\equiv` for assignment. But Go and Pascal also use `:=`. Of these, I would consider Go quite widely used in the industry.
- IshKebab 4y agoGo only uses := for declare & assign. For simple assignment it's =, and equality is still ==. So I would say it is barely different to the norm. POSIX `[` is clearly insane so let's ignore that. Which leaves Pascal and OCaml both of which are quite niche. I think he's right. It's definitely not worth going against the grain with this syntax, and it's debatable if it's even that bad in isolation. I seriously doubt beginners struggle with it.
- nequo 4y agoThis is textbook bikeshedding. If you have a bias for C syntax, everything else will look niche, weird, or "clearly insane" to you. But there's no reason that we should prefer C's syntactic decisions for assignment and equality operators in a non-C language. Go itself deviated from them, and the authors were instrumental to C itself.
- IshKebab 4y ago> But there's no reason that we should prefer C's syntactic decisions for assignment and equality operators in a non-C language. Yes there is - because almost every language uses the same convention, and it's a totally reasonable one. You have to have a really good reason to go against that and I don't see one. > Go itself deviated from them Go didn't deviate from the C convention. It just added an extra shorthand operator to simultaneously declare and initialise variables. The meanings of `=` and `==` are the same in Go as in C. > or "clearly insane" to you I wasn't saying the use of `=` for equality is clearly insane. `[` is clearly insane for other reasons.
- joshspankit 4y agoYou’ve picked a poor example. ‘=‘, ‘==‘, and ‘===‘ constantly trip up new coders and have led to some not-insignificant bugs. A lot of style guides even had to include guards against the worst one: ‘if (variable = “string”)’ I think that putting guardrails there by making the assignment operator stand out was a smart move. Annoying to use, but smart.
- grumpyprole 4y ago> Programming languages have settled on '=' for assignment and '==' for equality comparison. Certainly not all. "=" is a poor choice for assignment as it has a totally different meaning in maths. Algol and Pascal got this right with ":=". Fortran got it wrong here. > plus '=' is used for assignment in math just as often too No it's a relational operator in math, so "x = x + 1" does not have the same meaning as assignment to a mutable variable.
- Animats 4y agoIn functional languages, you seldom replace an existing value. Verse, like Rust, is mostly single-assignment.
- firstlink 4y agoIn Verse there's no such thing as equality comparison. Assignment is the only thing that = does.If you want to do something if two things are equal, you attempt the assignment and whether this is logically consistent with the rest of the program determines whether the other things are executed.