Hacker News new | ask | show | jobs
by lkjlakjsdlfkj 3031 days ago
"let" is more elegant IMO.
3 comments

I always found 'let' to be such a strange name. What on earth is appealing about it?

The usual variable declaration syntax is <type> <name>; it's not a stretch to imagine the type as 'var', a catchall type. But 'let'? Let is a verb; it should be in a place where functions, not types, go. It makes sense in "let x in {}" type expressions, and it kinda makes sense in Lisp, but I don't see any argument for it in a C-like language.

It's math-y. As in "let n be a natural, ...".
> I don't see any argument for it in a C-like language.

The inventor of the C-like languages B and NB (which then inspired C) agreed and used the more intuitive auto.

  {
    auto x = 1; /* x is implicitly an integer */
  }
Now it's back in vogue in the C-like language C++. It doesn't mean "automatic storage", though.
>It makes sense in "let x in {}" type expressions

Without jumps, all code can be rewritten to be a series of "let x = ... in <expression>"

The fact Java has statements instead of everything being expressions is a design flaw and should be rectified not glorified.

Er. Why do you think that?
It's essentially what SSA is.
do you mean the word itself? or some implementation detail is more elegant?
let as a drop-in replacement for var, or something semantically different?
Generally in languages that have a let, it means const var.
In JavaScript it defines a local variable or something like that, so there’s that…
on BASIC, not