Hacker News new | past | comments | ask | show | jobs | submit login

Kind of unrelated, but I find it interesting that I've only used 'let' a handful of times over the past 4-5 years and then I see projects like this where it's the rule, not the exception. Am I in a minority that thinks 'let' is a code smell?



No, quite the opposite - `let` should be used by default (due to better scoping rules (block rather than function) for most cases) and `var` only used when necessary.


IMO, `const` should be used by default, `let` in rare instances and `var` never.


Let is syntactic sugar.

To me, the code smell is the syntax from BASIC (and later C) that goes:

<code> x = y </code>

I've always disliked that notation; it looks like the statement "the value of x is the same as the value of y". So "let" turns the code into something that makes sense when read aloud.

I don't think syntactic sugar is a code smell.


Syntactic sugar is syntax that makes it easier ("sweeter") to do something the language can already do. For example, async/await is syntactic sugar for promises.

let isn't syntactic sugar — it's the only way to declare a reassignable block-scoped variable (as opposed to const, which can't be reassigned, and var, which is function-scoped or globally-scoped).


The way to redefine a const is to define an object who's values are mutable. I strongly prefer that as I can couple the mutating behavior in a single object.


Thanks. I was thinking in BASIC, I guess.


The core problem with the BASIC syntax isn't the lack of a keyword, it's that stupid = sign. Assignment almost kind of means equals, except it actually totally doesn't, which is the absolute worst kind of resemblance. Oh, and now you also have to invent some other construct like == for actual equality!

I'm admittedly not sure what symbol should be used instead. I'd suggest <= except it reads as "less than or equal to".


Why would it be?

A lot of JS in the wild favors putting everything in objects (maybe not explicitly, but they end up doing it a lot anyway) so gets away with a lot of "const" use that still lets them mutate the values of those objects. If you're dealing with primitives you're going to need "let" a lot more.


That is kind of my point, I don't often work with primitives that need to be redefined. I'd rather operate on an object where I can mutate its value rather than redefine the whole thing.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: