Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: make "let" completely synonymous with "var" #12432

Closed
micampbell opened this issue Jul 11, 2016 · 7 comments
Closed

Feature Request: make "let" completely synonymous with "var" #12432

micampbell opened this issue Jul 11, 2016 · 7 comments

Comments

@micampbell
Copy link

No description provided.

@gafter
Copy link
Member

gafter commented Jul 11, 2016

OK, so you're saying you don't want a pattern-matching assignment statement, or a way of introducing readonly variables? You just want more keywords that do nothing new?

@micampbell
Copy link
Author

I'm not following your rhetoricals. I don't want more keywords as "let" already exists. And as far as I can tell, it serves the same function as "var" except just in LINQ statements.
My suggestion is to simplify the language by making these equivalent.

@HaloFour
Copy link

@micampbell

I'm not following your rhetoricals.

An expanded use of let has long since been proposed and worked into other larger language proposals. Specifically, pattern deconstruction and readonly locals. See Pattern Matching for C# - Destructuring Assignment. @gafter is probably trying to ascertain if you're proposal stands alone or is in reaction to those proposals.

And as far as I can tell, it serves the same function as "var" except just in LINQ statements.

Except that it's readonly, which does better align to one of the proposed forms of let above:

let x = 123;
x = 456; // compiler error

@micampbell
Copy link
Author

Okay, that's starting to make sense. I guess I should defer to you guys since you're computer language experts and since I just now poked my head in here with a random request.
but...
I am motivated by readability over compactness. If a local variable is meant to be readonly then maybe the readonly modifier should be added instead of using let. Again, I'm not as expert as you guys, but I have been coding a long time and love C#. I hate to see the scientific and engineering programming community drift to python just because it’s easier. Saying “let x = 1” is entrenched in mathematical thinking. It would be nice to use it synonymously with “var x = 1” and it (may) be bad if this implied readonly status.

@jmarolf
Copy link
Contributor

jmarolf commented Jul 12, 2016

today:

  • let x = 5 is readonly when it is used in linq query comprehension expressions
  • var x = 5 is mutable (can be changed), and cannot be declared readonly.

perhaps we could allow something like this in the future:

  • let x = 5 declares a readonly variable and can be used anywhere variable declarations are allowed, not just in linq query comprehension expressions.
  • readonly var x = 5 and const var x = 5 are allowed as alternatives to let for those that don't like writing type names twice, but still want to be explicit about the fact that a variable cannot be modified after the initial assignment.

@micampbell does this capture what you are thinking or am I missing something?

@HaloFour
Copy link

@micampbell

I am motivated by readability over compactness. If a local variable is meant to be readonly then maybe the readonly modifier should be added instead of using let.

That has been proposed as well. Having let be shorthand for readonly var was proposed for succinctness. #115

I hate to see the scientific and engineering programming community drift to python just because it’s easier. Saying “let x = 1” is entrenched in mathematical thinking.

Several languages have both var and let keywords which do different things, including JavaScript and Apple Swift. It's been proposed for Java as well, although they have not settled on the exact keywords. It's less usual for a language to have multiple keywords that do the exact same thing because that would be a largely pointless addition to the language.

I seriously doubt that anyone is flocking from C# to Python over whether or not the syntax matches mathematical notation, particularly something as insignificant as let variable declarations. Not a single language above Python on the TIOBE index has such syntax.

@micampbell
Copy link
Author

I am satisfied, and I concede. Thanks for the discussion and your time.
I hope others find this thread useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants