by hwpythonner · 1y ago · 0 comments
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.
I don't think we are near said dream, yet.
Functions with plain arguments and a struct both produce identical assembly output.
Here what happens with optimizations: https://godbolt.org/z/G18zd7chP
Look at the registers usages vs stack
https://rust-lang.github.io/rust-clippy/master/index.html#to...
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.