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

alternative proposal for keyword arguments with type information #1

Open
brandondrew opened this issue Feb 8, 2024 · 1 comment
Open

Comments

@brandondrew
Copy link

Everything looked great until I got to this:

def b([key: String]: 'key', [value: String]: 'value'): String # this approach is up for debate, you can propose a better way in the issues section
  "#{key}: #{value}"
end

This looks very confusing to me. If the colon is to be used for both keyword arguments and type specifications, I think it would be better if the syntax didn't change so much when they are used together. I think this can be achieve like so:

def b(key: 'key':String, value: 'value':String): String
  "#{key}: #{value}"
end

Notice how there is always a space after the keyword's colon but never a space between the default value and the type. This would make it easier for both humans and parsers

@brandondrew
Copy link
Author

Another approach might be to use a different syntax for type annotations in general, not just in the case of keyword arguments. Here's on possibility:

def b(key: 'key' <String>, value: 'value' <String>) <String>
  "#{key}: #{value}"
end

I don't prefer this option, however.

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

No branches or pull requests

1 participant