Suggestion for minimizing usage of var/let/fn/? keywords #2067
Replies: 3 comments 2 replies
-
I think it might make sense for |
Beta Was this translation helpful? Give feedback.
-
that's a great idea, but I think it will interfere with the function definition and parameters of a function. I am right with you just for multiple variables definition not for function |
Beta Was this translation helpful? Give feedback.
-
@L4stR1t3s I believe what you are requesting is roughly what Carbon landed on. You can use Tuple destructuring to define multiple variables at the same time.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am not fond of the Carbon syntax of declaring variables/constants/functions/? because of the var/let/fun/? keywords being used so much, but I do understand why they exist. I would like to suggest the following syntax however to minimize the usage of those keywords when declaring/defining multiple variables/constants/functions/?:
This can be used for classes as well when declaring/defining variables/constants/functions/?
The keywords var/let/fn/? immediately followed by a '(' indicate that until the matching ')' is found any root expression is the name of a variable/constant/function. So the compiler/IDEs/... are able to determine right away what they are dealing with.
[] are a possible alternative if this would work better or people would prefer it. {} are not a possible alternative because that would indicate a new scope.
I am not sure whether a semi-colon after the closing ')' would make sense. If this makes it easier to parse the code, definitely. Otherwise I guess it would depend on what people prefer. Personally I think I would prefer no semi-colon.
This syntax is optional so it is allowed to declare multiple sequential variables/constants/functions/? by prefixing them all with var/let/fn/? just like is done now.
An empty multi-declaration is allowed:
As well as a single declaration using multi-declaration:
EDIT: Forgot to mention that function declarations and definitions can occur in the same fn ().
Beta Was this translation helpful? Give feedback.
All reactions