Comment by mg
4 years ago
One thing that irks me about Javascript is "const". I think it should have been called "con". "var", "let", "con".
So the first thing I did here is look up the docs and see how variables are declared. Aaarghh.. "let" and "const" again :)
Why do you think this?
"const" seems clearer to me. "con" seems very open to misinterpretation: could mean many things.
Are there any advantages to "con" over "const"?
My guess is the OP dislikes the difference in keyword length.
I just always use let because it looks better. Const provides pretty much no value in js anyway.
1 reply →
I've thought about this a lot. I considered "con" for constants. I don't hate it. It also works as a double entendre-- "con" in Spanish means "with". So the following code could be read as "with name equal to Brad".
I can't help but feel that it's somewhat jarring though.
If I had my druthers, I think I would choose "var" and "def" to declare mutable and immutable variables, respectively.
Edit: After thinking about it some more, I think I prefer "const" over "con", but "def" over both.
Spanish native here. I would never read it like that.
I have programmed in a couple languages where every single keyword was in Spanish: Logo and some flavours of Visual Basic.
Either everything is in English, or everything is in Spanish. There's no middle ground with mixed keywords.
'Var' and 'def' both sound good to me.
> It also works as a double entendre-- "con" in Spanish means "with".
Triple even! In French it's the equivalent of "cunt".
And in English, to go full circle, a con is what a con man pulls; a confidence trick.
Hey BTW, is a JS "const" really constant, or can it (like in some other languages) be changed after all? Because if it can, then it isn't really const but more of a con...
1 reply →
Why does const irk you? const sounds a lot clearer than con. Is that your primary criteria for picking a language? ;)
I think it has three reasons:
The more often a construct is used in a language, the shorter I like it to be.
It groups variable definitions mentally by having them all the same length if they are "var", "let" and "con".
It would often make the code look more uniform which is more beautiful in my eyes. Example:
https://github.com/facebook/react/blob/cae635054e17a6f107a39...
I would prefer the lines 226 and 227 to start with "con" and "let". It would make the code visually more appealing to me.
As far as code being visually appealing, for me those two lines are the least of that code’s troubles.
I’m sympathetic to wanting code to have good aesthetics. If I was writing those lines I probably would have daydreamed for 5 minutes thinking of new names for map and record so that the equal signs would line up.
2 replies →
You are obviously right.
The 'const' nomenclature is an abomination before science and human progress. However, given the prior art, I don't think we can hold it against a new/emerging language.
Anders, help us! Do the right thing. You are the only one who can.
(Of course, 'const' could be grandfathered and still work forever. Right-minded people, please upvote this obviously-right person at least back to a neutral #000.)
Tbh, var is actually deprecated since v1, so any mention of var in the docs is a mistake. Are there any other languages using 'con' for constants?
No, but there should be!!
I've never used a language with a 'cons' keyword, but nevertheless that's what I'd assume your 'con' was, if you didn't tell me otherwise.
I'm no particular JS fan, but 'const' is much clearer, it's a complete syllable, just like 'var' or 'func'. Yes 'fun' is used, but I think that's awkward for the same reason.
Good idea IMO. That feature should be pretty easy to add (famous last words).
if we want to nitpick I hate the fact that many dynamic languages need keywords to express very little information.
If js was made with types then the syntax `any x` (yeah lose the colon too, who gives a shit) is suficient to express that x is a variable, then `number x` could mean variable of type number, and `const number x` could mean constant of type number.
Is the difference in length bothering you? In that case I find that let for immutable and var for mutable is pretty good, although for a language that's lose to JS that might not be a good idea. Maybe let for mutable like in JS, and val for immutable? (inspired by Scala).
Personally I don’t use any languages with reserved words
that limits the number of languages to a handful. like brainfuck and similar ones. doesn't it?
Lisps don't have reserved words, generally.
2 replies →
APL cheats by making everything a symbol.
Why should there should be a flag word before IDentifier, indeed the answer is.
[constant variable name] = value
is not the right thing?