News for hackers. Stuff that matters.
Re:Matt Godbolt sold me on Rust by showing me C++ by jsat on Tuesday May 06, 2025 @03:19PM (#43908667)
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.
Re:Matt Godbolt sold me on Rust by showing me C++ by kelnos on Tuesday May 06, 2025 @03:27PM (#43908741)
Yes, this is one of the few things that I think was a big mistake in Rust's language design. I used to do a lot of Scala, and really liked named parameters there.

I suppose it could still be added in the future; there are probably several syntax options that would be fully backward-compatible, without even needing a new Rust edition.

Re:Matt Godbolt sold me on Rust by showing me C++ by quietbritishjim on Wednesday May 07, 2025 @05:08AM (#43913577)
I suppose the sense it is backwards incompatible is that library authors have named their parameters without intended to make them part of the public interface that they commit to maintaining. Perhaps it could be made backwards compatible by being opt in function declarations but that would seem like a bit of a pain.
Re:Matt Godbolt sold me on Rust by showing me C++ by codedokode on Tuesday May 06, 2025 @03:57PM (#43908994)
When there are 3-4 parameters it is too much trouble to write the names.
Re:Matt Godbolt sold me on Rust by showing me C++ by noitpmeder on Tuesday May 06, 2025 @05:38PM (#43909925)
Not OP, but I imagine he's arguing for something like python's optional named arguments.
Re:Matt Godbolt sold me on Rust by showing me C++ by bsder on Tuesday May 06, 2025 @06:17PM (#43910187)
> 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.

Re:Matt Godbolt sold me on Rust by showing me C++ by monkeyelite on Wednesday May 07, 2025 @05:39AM (#43913742)
Making something longer doesn’t make it easier to read, especially in repetition.
Re:Matt Godbolt sold me on Rust by showing me C++ by int_19h on Wednesday May 07, 2025 @10:35PM (#43922571)
Making something explicit does.
Re:Matt Godbolt sold me on Rust by showing me C++ by monkeyelite on Sunday May 11, 2025 @03:59AM (#43952190)
Would it be better if you wrote out the type of every variable every time you used it? That would be more explicit.
Re:Matt Godbolt sold me on Rust by showing me C++ by int_19h on Wednesday May 07, 2025 @10:51PM (#43922634)
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);
Re:Matt Godbolt sold me on Rust by showing me C++ by bsder on Thursday May 08, 2025 @01:04AM (#43923215)
Oooh. Nice. I forgot about the Smalltalk / ObjC / Swift usage of keywords for messages.
Re:Matt Godbolt sold me on Rust by showing me C++ by sophacles on Tuesday May 06, 2025 @05:31PM (#43909858)
Why? In 2025 we have tooling available for most every editor that will annotate that information into the display without needing them present in the file. When I autocomplete a function name, all the parameters are there for me to fill in, and annotated into the display afterwards. It seems like an unnecessary step to reify it and force the bytes to be present in the the saved file.
Re:Matt Godbolt sold me on Rust by showing me C++ by skywhopper on Wednesday May 07, 2025 @08:37AM (#43914868)
So those editors could just insert the names for you. The bytes in the source file are not a serious concern, are they?