Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

let keyword looks noisy/redundant each time we need to define a variable/function:

let add = (a, b) => a + b

Is it possible to ditch it or at least make it optional? So the code gets better without it:

add = (a, b) => a + b

Purescript (Haskell), Coffeescript, Python do not use keywords to declare/define something which is nice.
So let looks more like legacy from OCaml.

You must be logged in to vote

Replies: 2 comments · 5 replies

Comment options

ReScript first and foremost tries to be familiar to JS developers. And while let in ReScript is immutable, it is at least a familiar keyword.
Also if you removed the let keyword, you probably want to remove rec and and as well, which are needed in ReScript for (mutual) recursion. Furthermore, it will create confusion if we then don't disallow shadowing. IMHO it will create confusion regardless.

There was already a discussion about this topic in the forum: https://forum.rescript-lang.org/t/let-keyword-needed/2899

You must be logged in to vote
5 replies
@bomzj
Comment options

Shadowing sounds not good, it's a gateway to unneeded bugs and as a result it will be harder to debug.

As to javascript developers the current let is not the same let they are used to, so it's safe and easy to get used not to use this keyword at all or use when appropriate.

Regarding rec and and we can still use let, but in other cases I would propose make it optional.

@glennsl
Comment options

Shadowing also prevents bugs by removing obsolete variables from scope, and avoids having to make up new names for variables with identical meaning. In a functional language where mutability is discouraged, that's quite convenient, and natural.

@bomzj
Comment options

In a functional language where immutability is discouraged, that's quite convenient, and natural.

But Immutability is the basis of functional programming, it should not be discouraged.
Overriding variables in a function seems more like a terrible design/habbit from imperative languages thus a way to produce poor code.

@glennsl
Comment options

Sorry, I mean mutability.

With a mutable variable you can update it, e.g. a = a + 1.

With an immutable variable and no shadowing you either need to create a new new name, e.g. let a''' = a'' + 1 (good luck getting the number of apostrophes right), or you skip the variable entirely and instead write large unreadable expressions. You're of course free to think this is good style, but you're not making a very good argument for it.

With shadowing you keep the name short and meaningful and remove the obsolete value from scope. No unwieldy variable names and no bugs from accidentally using obsolete variables.

@glennsl
Comment options

It might be nice to have shadowing disabled by default and have to opt in to it per definition though. But I haven't ever had a bug caused by shadowing, so I wouldn't personally give it much priority.

Comment options

It also requires making the language white-space sensitive, which is a massively invasive change. All the languages you mention are. There are "tokens" in all these languages similar to let that prevents ambiguous parsing, but they're invisible.

Not that I'm against white-space sensitivity, but it's a fundamental language decision that needs to be considered from the very beginning. Trying to shoe-horn it in afterwards will likely create lots of inconsistencies and confusion.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
💡
Ideas
Labels
None yet
3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.