Imo named tuples via records are better than tuples provided at the primitive level. They provide a ton more context for the next reader about what this thing actually is.
Right until there’s no more context than “this returns 2 elements” and you end up with 15 different Pair types and more verbosity for no value.
Named tuples are not better than tuples, they’re complementary, both are useful tools.
Not usefully so. If you’re splitting a collection in two, whatever context you add is almost certainly worthless overhead not worth the extra type.
var p: (int, int) = (0, 0);
var q = p.0 + p.1;
type Point(x: int, y: int) #unboxed { }
var p = Point(0, 0);
var q = p.x + p.y;
Both will generate identical machine code with no allocations. It requires no escape analysis or assumption of non-identity (both tuples and data types have structural equality).There's a bit of unnecessary overhead in having to externally declare and import the return type.
public [K key, V value] getElement(int index);
This really comes down to the dynamic vs typed argument, and to me the answer is "minimise the boiler-plate, maximise the guarantees.".But I wouldn't expect that to be the common use case - I'd generally expect that the caller would just be implicitly importing and using the type effectively declared in the method header.