by weinzierl · 2y ago · 0 comments
If there is one thing that is for sure, it is that we have too many names for "collection of name to value mappings".
In my book the term record is not what first comes to mind when thinking of unordered mappings. All of the usages of the word I can think of imply the possibility of access by name while retaining order. Sometimes this allows easy indexed access (database rows used to be called records) sometimes it doesn't (C structs which also used to be called record types).
Also in C++:
struct A { int x; int y; } a;
struct B { int y; int x; } b;
template<class C> concept has_x_y = requires(C c) {
{ c.x } -> std::convertible_to<int>;
{ c.y } -> std::convertible_to<int>;
};
int sum(has_x_y auto z) { return z.x + z.y; }
...
sum(a);
sum(b);As two structs that have same names at different places in the struct still need to conform to the generic record type
Access by name is not even truly necessary and the difference between tuples and records is minimal (you could build something looking exactly like field access on top of tuples with functions and would get as a result something indistinguishable from an actual record).
The existence or not of an order is then totally accessory and it's generally straightforward to build an order on both provided the data types they contain is orderable by ordering the field and then using a lexicographic order.
The iteration order seems arbitrary to a human, but that is exclusively because function(name, insertion_id) is not optimized for a human. It seems strange to call the collection “unordered” because of how it appears to a human.