3 ms·
But if you want better arrays you want operator overload to be able to use these arrays as 1st class citizens without having to use array_get(arr, 3), array_len
by simias 7y ago
But if you want better arrays you want operator overload to be able to use these arrays as 1st class citizens without having to use array_get(arr, 3), array_len(arr), array_concatenate(arr1, arr2) etc... You want to be able to write "arr[3]", "arr.len()", "arr1 += arr2" etc... To implement operator overload you might need to add the concept of references.
If you want your arrays type-safe you'll need dark macro magic (actually possible in the latest standards I think) or proper templates/generics.
If you really want to make your arrays convenient to use you'll want destructors and RAII.
Then you'd like to be able to conveniently search, sort and filter those arrays. That's clunky without lambdas.
And once you get all that, why not move semantics and...
Conversely if you don't want any of this what's wrong with:
struct my_array {
my_type_t *buf;
size_t len;
}
I don't think it's worth wasting time standardizing that, especially since I'd probably hardly ever use that since it doesn't really offer any obvious benefits and "size_t" is massively overkill in many situations.
- loeg 7y ago> But if you want better arrays you want operator overload to be able to use these arrays as 1st class citizens without having to use array_get(arr, 3), array_len(arr), array_concatenate(arr1, arr2) etc... You want to be able to write "arr[3]", "arr.len()", "arr1 += arr2" etc... I don't think that's true at all. 1. "arr[3]" syntax can just be part of the language. 2. For length, we already have the "sizeof()" syntax, although admittedly it is a compile-time construct and expanding it to runtime could be confusing. I am ok with using a standard psuedo-function for array-len and would absolutely prefer it to syntax treating first-class arrays as virtual structs with virtual 'len' members. 3. I don't think any C practitioner wants "arr1 += arr2" style magic. So I don't buy that there is a need for operator overload; the rest of your claims that this is basically an ask for C++ follow baselessly from that premise.
- apotheon 7y ago> Conversely if you don't want any of this what's wrong with: As I suggested, adding a(n optional) constraint such that "buf" can be limited by "len" in such a struct is a possible approach to offering safer arrays. Such a change seems like it kinda requires a change to the language.