-
Notifications
You must be signed in to change notification settings - Fork 2k
Stop enforcing parameter name uniqueness #3986
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
Comments
Nope, the above isn't allowed in strict mode, and that's why it was disallowed in CoffeeScript. |
You might also be interested in #3972 and the following syntax:
|
(that syntax is also mentioned in #1002) |
thanks for the links, i didn't realize it's not allowed in strict mode! it would be nice to make an exception for pattern matching style (transpiling |
The Party Line™ on this is that it's better to name your variables, even if you aren't going to use them. You might want to use them later, and it's better to document what they are, instead of being mystery meat free variables floating around. |
@jashkenas many functional languages (scala, haskell, f#, ...) disagree. param names don't tell you much about what the variable is anyway. you need docs (jsdoc/jsig/flow), type annotations, or to look at context and consumers to get a good idea of what a param is for. the name by itself is not enough to conclude much, unless it's an idiomatic param name (like |
@bcherny just as you said – you don't have those annotations in coffee. |
exactly. i'm arguing that param names are not usually useful otherwise. # useful:
# (bar: number) => number
fn = (_, bar) ->
bar + 1
# useful:
# (foo: number, bar: number) => number
fn = (foo, bar) ->
bar + 1
# less useful:
fn = (foo, bar) ->
bar + 2
# equally less useful:
fn = (_, bar) ->
bar + 1 it's annotations that are useful, not param names. not only that but |
If you have so many positional parameters that you need to omit their names, it's time to use named parameters (passing an object and using destructuring). |
Currently enforced on this line -
coffeescript/src/nodes.coffee
Line 1431 in 769f02e
This is already enforced by linters (eg. http://eslint.org/docs/rules/no-dupe-args), and is not CoffeeScript's responsibility. Instead, we should have a smarter variable naming scheme that doesn't rely on uniqueness of param names.
A side effect of enforcing this from within CoffeeScript is that pattern matching syntax doesn't work. Eg. I can't do:
But the above does work in JS.
The text was updated successfully, but these errors were encountered: