3 ms·
The article makes a clear case for keyword arguments, without mentioning it at all. In Smalltalk you would write something like: calculateTax: percentage tran
by galaxyLogic 11y ago
The article makes a clear case for keyword arguments, without mentioning it at all. In Smalltalk you would write something like:
calculateTax: percentage transferValue: value
This has the advantage over the proposed solution that where-ever you CALL such a method, the meaning of the passed-in arguments is clear ALSO in the calling context. Just having meaningful names for FORMAL arguments does not do anything about how the ACTUAL arguments are named, in the (often more than one) places where the method is called. Meaning, it is hard to know whether a given method-call has its arguments in correct order without a) Checking the method-definition for their expected order b) Checking from the calling context the meaning of the variables you pass in to the call. Do they agree? Takes some figuring out.
That requires of course that your language supports keyword arguments. In languages that don't you can simulate them by using a single object as the only argument. That may seem like extra work but it helps, especially when there are many "arguments". It also allows you to have default-arguments without requiring that they are at the end of the argument-list. I think this pattern is called "Argument Object".
- deleted 11y ago[deleted]