4 ms·
> Also tuples. A tuple is just a makeshift struct. Think about it this way: by replacing it with a real struct, you're documenting your code.
by earthboundkid 14y ago
> Also tuples.
A tuple is just a makeshift struct. Think about it this way: by replacing it with a real struct, you're documenting your code.
- derefr 14y agoImagine if every function was only allowed to take a single parameter--and in order to write a function that takes multiple, what you really had to do was declare a struct of type "the set of parameters foo() takes" and then construct one whenever you called foo(). This is what it feels like going from a language with tuples, to one without :) (I would also say "imagine further that you had to do the same whenever you returned multiple values"--but you don't have to imagine ;)
- Evbn 14y agoGo has tuple return values and of course input values. The only thing missing is giving a tuples a name. But if you do that, you should make a struct, or you will forget which field is which and have bugs.