4 ms·
The author says: // to call it you'd do first_argument = 1; second_argument = 2; int three = add_numbers(); This is, I trust you all agree, terrible. This
by throw14082020 6y ago
The author says:
// to call it you'd do
first_argument = 1;
second_argument = 2;
int three = add_numbers();
This is, I trust you all agree, terrible. This approach is plain wrong.
I agree, but I don't think everyone agrees. Just have a look at the apple APIs, their configuration options are all objects you have spend time configuring, then pass as an argument. I don't know why everything with Apple development beats around the bush. It's almost too object oriented.
To be clear, Apple is more like this:
let argument = Argument()
argument.first = 1
argument.second = 2
let addRequest = AddRequest()
adder.add_numbers(with: arguments)
let mathRequest = MathRequest()
mathRequest.perform([addRequest])
if let results = addRequest.results {
// Do something with your results.
}
And yes though, Apple development makes me feel smart when I solve something that should've been documented.
- Macha 6y agoI think you're objecting to different things than the author. The author is complaining that there's no link or information that first_argument or second_argument are used by add_numbers. In comparison, in the Apple API example you've given, addRequest is explicitly provided to perform. What you appear to be objecting to is setting up potentially complicated config objects to pass rather than passing simpler arguments.