4 ms·
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
by mg 5y 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 :)
- somebee 5y agoTbh, 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?
- veidr 5y agoNo, but there should be!!
- amalantony06 5y agoWhy does const irk you? const sounds a lot clearer than con. Is that your primary criteria for picking a language? ;)
- mg 5y agoI 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/cae635054e17a6f107a39d328649137b83f25972/packages/react-fs/src/ReactFilesystem.js#L226 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.
- jazzyjackson 5y agoAs 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.
- deleted 5y ago[deleted]
- CRConrad 5y agocon map = ... let rec = ...
- scns 5y agoGood idea IMO. That feature should be pretty easy to add (famous last words).
- lucideer 5y agoWhy 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"?
- mstade 5y agoMy guess is the OP dislikes the difference in keyword length.
- cgag 5y agoI just always use let because it looks better. Const provides pretty much no value in js anyway.
- jsf01 5y agoIt is useful for code readability. When you’re skimming and trying to understand a large chunk of code, if almost all the variables are declared with “const” and then you come across a “let”, you immediately know to look for where it will be mutated elsewhere.
- Zababa 5y agoIs 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).
- jazzyjackson 5y agoPersonally I don’t use any languages with reserved words
- therufa 5y agothat limits the number of languages to a handful. like brainfuck and similar ones. doesn't it?
- jhgb 5y agoLisps don't have reserved words, generally.
- jazzyjackson 5y agoNot even cons and defun?
- jhgb 5y agoDepends on what you mean by "reserved word". In Common Lisp, you can define your own cons and defun, provided that you're not attempting to mutate the respective symbols from the COMMON-LISP package. That can be achieved by either defining your own cons and defun and shadowing the cons and defun from the COMMON-LISP package (typically for function or macro bindings), or just straight up using cons and defun from the COMMON-LISP package in "legal" ways - for example (let ((cons 1) (defun 2)) (list cons defun)) is legal and evaluates as '(1 2) since using those two symbols as names for lexical variables doesn't break the running Lisp in any way. In the former case (of defining your own functions/macros accessed as "unqualified" cons or defun from your own code) it's up to you if you consider cons and defun to be "reserved words" based on their package or not (packages for reserved words being something that languages explicitly recognizing the concept of a reserved word don't seem to have, so it's not clear how this should qualify). In Scheme, a Lisp-1, it's kind of free-for-all, especially in R5RS where you don't even have to bother with hiding standard bindings.
- jazzyjackson 5y ago
- OJFord 5y agoI'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.
- deleted 5y ago[deleted]
- veidr 5y agoYou 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.)
- __ryan__ 5y agoI'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". con name = '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. def PI = 3.1 def degreesToRadians = degrees => degrees * (PI / 180) var degrees = 180 var radians = degreesToRadians(degrees) Edit: After thinking about it some more, I think I prefer "const" over "con", but "def" over both.
- Zababa 5y ago> It also works as a double entendre-- "con" in Spanish means "with". Triple even! In French it's the equivalent of "cunt".
- CRConrad 5y agoAnd 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...
- Zababa 5y ago> 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... It's constant for things like numbers, but if you declare an array const, the only const things is the reference, the array can still mutate. con might be a good name for that.
- Shorel 5y agoSpanish 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.
- nsonha 5y agoif 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.
- lyrachord 5y agoWhy should there should be a flag word before IDentifier, indeed the answer is. [constant variable name] = value is not the right thing?