←back to thread

611 points LorenDB | 8 comments | | HN request time: 0.428s | source | bottom
Show context
jsat ◴[] No.43908667[source]
I see an article about how strict typing is better, but what would really be nice here is named parameters. I never want to go back to anonymous parameters.
replies(3): >>43908741 #>>43908994 #>>43909858 #
1. codedokode ◴[] No.43908994[source]
When there are 3-4 parameters it is too much trouble to write the names.
replies(2): >>43909925 #>>43910187 #
2. noitpmeder ◴[] No.43909925[source]
Not OP, but I imagine he's arguing for something like python's optional named arguments.
3. bsder ◴[] No.43910187[source]
> 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.

replies(2): >>43913742 #>>43922634 #
4. monkeyelite ◴[] No.43913742[source]
Making something longer doesn’t make it easier to read, especially in repetition.
replies(1): >>43922571 #
5. int_19h ◴[] No.43922571{3}[source]
Making something explicit does.
replies(1): >>43952190 #
6. int_19h ◴[] No.43922634[source]
They 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);
replies(1): >>43923215 #
7. bsder ◴[] No.43923215{3}[source]
Oooh. Nice. I forgot about the Smalltalk / ObjC / Swift usage of keywords for messages.
8. monkeyelite ◴[] No.43952190{4}[source]
Would it be better if you wrote out the type of every variable every time you used it? That would be more explicit.