Typed indexes in Zig

30 points by lvig 21 hours ago on lobsters | 7 comments

tomekw | 7 hours ago

So it's like Ada's:

type Column is range 0 .. Max_Column;
type Row_Index is range 0 .. Max_Row;

but ~35 years later?

andrewrk | 5 hours ago

Is this a question or a statement?

tomekw | 5 hours ago

Oh, now I noticed my comment could be read as passive-aggressive. I'm sorry about that. Don't get me wrong: I love both Ada and Zig, and the work you're doing!

What was presented here reminds me of Ada. I feel like, still, Ada is a goldmine of great ideas. Anyway, I am personally happy Zig is moving in this direction.

Student | 6 hours ago

It is Ada’s Java moment to be reinvented with better marketing and more free tooling

mgriffin | 10 hours ago

I frequently find myself wishing for languages/standard-libraries to build-in the ability to say "this array is indexed by that integral (new-)type". You can build it yourself, but because the syntax is heavier at definition and use sites I often don't.

Admittedly, I do a lot of low-level performance-y work. If you're not worried about performance then your language's Map type is usually a way to get that type safety.

pervognsen | 9 hours ago

In Pascal (1970) an array's index type can be any bounded ordinal type, which includes enumerated types and subranges of an enumerated type.

jo3_l | 9 hours ago

If I recall correctly, Ada's arrays support this kind of thing. I'm not sure if any other remotely mainstream languages do (though it sure would be nice, as you say), though I'm sure someone will chime in with more examples.