by hartator · 7y ago · 0 comments
sig {params(person: Person).returns(Integer)}
def name_length(person)
Not sure if I dig the syntax. Furthermore arguments seems to be the official names for method arguments, not parameters. eg, `ArgumentError`. `params` also feels like it's linked to Rails `params` variable in controllers. It can be confusing.Something like this will also feel more Rubyist:
def name_length person: Person, return: Integer
But it probably requires a deeper hack or a change in MRI.We used `params` because Method#parameters was what they called it in the standard library. I actually had it as `args` originally until someone pointed this out. https://ruby-doc.org/core-2.6.3/Method.html#method-i-paramet...
As for the syntax change, we are actually on our 8th iteration of the syntax. We really wanted this to NOT be a fork of Ruby so finding something compatible was very important. For example that's why it has the weird `sig {` syntax too, we didn't want to have to cause load-time and cyclic dependencies from adding type signatures.
Super interesting. We should probably have being consistent for naming parameters vs. arguments in stdlib. It's too late though!
def name_length(person)
steve = Person.new
name_length(steve)
Here, 'person' is a parameter, and 'steve' is an argument.Most programmers use them interchangeably.
ArgumentError is still consistent with this definition (it's an error with the value you passed, not with the definition). However, params in a Rails controller does violate this definition.
`ArgumentError` is consistent with an error during call time.
As far as ruby goes, though, it would conflict with keyword arguments.