4 ms·
The pattern in rust is to use enums and structs instead. Design patterns are always needed when the language doesn't support a given construct but once it's use
by estebank 7y ago
The pattern in rust is to use enums and structs instead. Design patterns are always needed when the language doesn't support a given construct but once it's usefulness is established language designers incorporate to (the same or other) language.
The problem with named parameters as seen in Python is that then the name of the parameters become part of your APIs contract, making changes to your API harder. This has been remediated with patterns in Python 2 and explicit design in Python 3 by incorporating named only parameters so that you can't call them with both positional or named args.
- madhadron 7y agoThis isn't quite what the OP is referring to. In Smalltalk, all arguments are named all the time, including positional arguments. Object methods aren't named separately from their parameters. They are only their set of named arguments, i.e., So say I have a BankAccount class. In Python I would write a method to transfer to another account def transfer(this, to, amount): ... and invoke it as account.transfer(other_account, 500) In Smalltalk I would write transferTo: account amount: n [ ... ] and invoke it as account transferTo: other_account amount: 500. So it's not quite named arguments. It's that there isn't a distinction between name of function, argument name, and positional parameters. It just doesn't map to the function notation typical from mathematics.
- coldtea 7y ago>The problem with named parameters as seen in Python is that then the name of the parameters become part of your APIs contract, making changes to your API harder. Huh? How are APIs with mere positional parameters easier to change and more transparent to the callers when changed?