News for hackers. Stuff that matters.
Re:N-Params vs. Single Param by hwpythonner on Thursday April 17, 2025 @03:09PM (#43720913)
Not an expert in JS, but maybe this makes sense in JS where everything is passed as objects anyway and having a single param is often more readable there.

But in native languages like C/C++/etc, this pattern usually hurts performance. Separate arguments go into registers (faster but depends on number of arguments), while structs often involve indirection, and sometimes alignment/padding issues. Also, passing a const struct doesn’t guarantee the fields inside are truly const.

That said, it's context dependent. If you're passing stuff through multiple layers or want a more stable function signature, using a struct can be cleaner. Just not something I’d generalize to any language or any use case.

Re:N-Params vs. Single Param by taeric on Thursday April 17, 2025 @03:16PM (#43720989)
I think the dream has long been that a compiler could optimize away any inefficiencies that can be mechanically described. As such, if there is a benefit to seeing the same structure in many places, using a struct would be ideal.

I don't think we are near said dream, yet.

Re:N-Params vs. Single Param by dicytea on Thursday April 17, 2025 @03:43PM (#43721279)
Doesn't seem to be a problem, at least for Rust: https://godbolt.org/z/fToxz3d7a.

Functions with plain arguments and a struct both produce identical assembly output.

Re:N-Params vs. Single Param by airstrike on Thursday April 17, 2025 @04:03PM (#43721545)
Also worth noting clippy will warn about writing functions with too many arguments for the same reason listed in TFA

https://rust-lang.github.io/rust-clippy/master/index.html#to...

Re:N-Params vs. Single Param by carlos-menezes on Thursday April 17, 2025 @03:54PM (#43721415)
Re:N-Params vs. Single Param by hwpythonner on Thursday April 17, 2025 @04:20PM (#43721777)
Try compiling with optimizations. I think by default this site doesn't add optimization flags.

Here what happens with optimizations: https://godbolt.org/z/G18zd7chP

Look at the registers usages vs stack

Re:N-Params vs. Single Param by carlos-menezes on Thursday April 17, 2025 @04:25PM (#43721818)
Got it! Thanks for the link.
Re:N-Params vs. Single Param by physicsguy on Thursday April 17, 2025 @03:57PM (#43721470)
If you add a third argument you get different assembly
Re:N-Params vs. Single Param by the_other on Thursday April 17, 2025 @05:53PM (#43722639)
I’ve seen some evidence it hurts performance in JS, too. If you’re doing something “a lot”, like media qstreaming, or realtime updates, ordered params are likely faster.

I agree with others that the destructuring is a nice syntax to read and write. Yet, I have started to feel it’s an overused pattern, deployed by habit rather than consideration (in my code anyway). I can’t put my finger on why. It’s possibly a gut-feel that my functions would be better taking feeer arguments.

Re:N-Params vs. Single Param by oneoverten on Thursday April 17, 2025 @07:33PM (#43723382)
Yes. This is true for JS too, object-wrapping parameters just to make them named will add runtime overhead.
Re:N-Params vs. Single Param by fenomas on Friday April 18, 2025 @04:06AM (#43726015)
Not in current chrome, at least for simple cases (like a short function with a single argument). It benchmarks the same with it without the param wrapper.