4 ms·
When there are 3-4 parameters it is too much trouble to write the names.
by codedokode 1y ago
When there are 3-4 parameters it is too much trouble to write the names.
- noitpmeder 1y agoNot OP, but I imagine he's arguing for something like python's optional named arguments.
- bsder 1y ago> When there are 3-4 parameters it is too much trouble to write the names. Sorry, I don't agree. First, code is read far more often than written. The few seconds it takes to type out the arguments are paid again and again each time you have to read it. Second, this is one of the few things that autocomplete is really good at. Third, almost everybody configures their IDE to display the names anyway. So, you might as well put them into the source code so people reading the code without an IDE gain the benefit, too. Finally, yes, they are redundant. That's the point. If the upstream changes something and renames the argument without changing the type I probably want to review it anyway.
- monkeyelite 1y agoMaking something longer doesn’t make it easier to read, especially in repetition.
- int_19h 1y agoMaking something explicit does.
- monkeyelite 1y agoWould it be better if you wrote out the type of every variable every time you used it? That would be more explicit.
- int_19h 1y agoThey aren't even necessarily redundant. If you have argument names as part of the function name, they can be overloaded on - and this is much more readable than type-based overloading because it's all explicit. Swift uses this to great effect, e.g. here are some different ways to construct a string: String(repeating: "foo", count: 42); String(cString: zeroTerminatedBuffer); String(42, radix: 16); String(contentsOfFile: "foo.txt", encoding: .utf8);
- bsder 1y agoOooh. Nice. I forgot about the Smalltalk / ObjC / Swift usage of keywords for messages.