Hacker News new | ask | show | jobs
by romanovcode 3242 days ago
While I use `const` for a lot of my variables that I don't want to change it feels super-super wrong.
2 comments

What feels wrong about it?
You wouldn't declare your in-scope variables as `const` in C/C++/C#/Java wold you?
In C++ I always do, everything is 'const auto &' if it can be. C# const is different, it's more like C++ '#define'.

Why wouldn't you always go for the most immuatable declaration? Even in C++, where you can have 'const int f(const int y) const;' it's still worth using even though you have to type it a few times.

It's an incredibly verbose way to do what you'd prefer to be the default.

val or con would have been better.

Going way back to ancient Lisps `let` has been the const declaration in a lot of programming languages. It's too bad ES2015 decided to use `let` for `var`/`val`, because `let` should have been const.

That said, I've come to terms with const, even if I find I accidentally use let sometimes from time spent in Lisp and F#.

let is not a "const declaration" in most major dialects of Lisp, current and historic. In Scheme, Common Lisp, ISLisp, Emacs Lisp and others, it introduces mutable bindings.
Apologies, my Common Lisp is getting rusty.
Is there really much of a difference between "const" and "con"? I get that one is 66% longer than the other, but does it actually affect the readability of the code or the amount of time it takes to write it?
Can't we compromise half way? How about cons!

/whistle .../

Yeah, those 60% extra characters do bother me. And the uneven indentation.

I know some/most people don't care. I can't be one of them.

Maybe we'll get `val` in ES9.

They're not variables if they don't vary ;)