Remix.run Logo
▲ saagarjha 2 hours ago

> Like indexing a vector panicking instead of returning a Some(T) in case the index is out of bounds.

If you are doing this then you've made a mistake in your code. Rust is consistent in catching these early.

▲uecker 2 hours ago | parent [-]

There is also the idea that the language is so good because such things are caught at compile time via the type system. (But this is generally not done for the same reason it is not done in C.)

▲pjmlp 2 hours ago | parent [-]

As shown in PL/I or NEWP, C could have done it both ways, checked and unchecked when really required, e.g. PREFIX(SUBSCRIPTRANGE), PREFIX(NOSUBSCRIPTRANGE).

Likewise regarding the storage for the length, if one is willing to go the way C went down a few years later, declare a pointer and make the array storage be pointer based, e.g. BASED(MY_ARRAY_PTR).

▲uecker 2 hours ago | parent [-]

Can you explain what you mean by "make the array storage be pointer based"?

▲pjmlp 9 minutes ago | parent [-]

In PL/I you can declare arrays with a length descriptor, thus allocating storage for the length, like in mostly safe systems languages.

Alternatively when allocating the array storage define its access to be pointer based.

This means no length descriptor will be stored alongside the array, and the access to array elements will be done via the given pointer.

It is up to the programmer not to mess up then.

Unfortunately C authors never added a way to do the former, given their experience with PL/I and Multics.

I am aware we are finally going into that direction.