I recently realized why don’t I use tuples as much, and was wondering if others share the same thoughts?
This is totally based on a feeling I have, for which I don’t have empirical evidence. But strolling trough the std lib for example, the Ziggiest code AFAIK, there aren’t many return values as tuples. This seems like a good idea at first:
var v1, var v2 = function();
I tried using them in my projects, but as I’ve never seen a real life usage for them in public APIs, it kinda looks ugly to me. Especially when you want to be verbose with variable naming, you get into this ugly situation:
var verbosly_named_variable1, var verbosly_named_variable2 = function();
But the function also needs some arguments, so now it looks like this:
var verbosly_named_variable1, var verbosly_named_variable2 = function(argument1, argument2, argument3);
And if you need to handle errors, just don’t do it:
var verbosly_named_variable1, var verbosly_named_variable2 = function(argument1, argument2, argument3) catch |err| {handle(err);};
You can do it like this I guess:
var verbosly_named_variable1, var verbosly_named_variable2 = function(
argument1,
argument2,
argument3,) catch |err| {handle(err);};
We quickly run into a line of code you’d need a huge buffer for. And there is nothing really you can do. So more often than not I ditch tuples, especially as I use a pretty big font while coding, and have a small code buffer.
Also have in mind that the function definition will have a long return type struct {type1, type2}, and if you’ve came that far, you might as well declare it as a struct instead of a tuple, and use it elsewhere struct {value1: type1, value2: type2}
Is this the reason people don’t use them? Are regular structs almost always more practical?