ruby_type_system icon indicating copy to clipboard operation
ruby_type_system copied to clipboard

alternative proposal for keyword arguments with type information

Open brandonzylstra opened this issue 2 years ago • 1 comments

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

brandonzylstra avatar Feb 08 '24 04:02 brandonzylstra

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.

brandonzylstra avatar Feb 08 '24 05:02 brandonzylstra