Follow

Unpopular opinion: 0-based arrays are an artifact of the C array implementation details and not some One True Way Arrays Shall Be Indexed In Code. I appreciate languages that try to overcome it, both old like Pascal and new like Julia.

@Amikke, do you also appreciate the fact that the year immediately preceding 1 CE is 1 BCE? xP

@mgorny not that xD But it kinda makes sense if we consider the point in time on the edge between CE and BCE the 0 point, with 1 CE being first year after and 1 BCE being first year before. There's no 0th year after all.

@Amikke, that's just a convention that makes computation difficult.

@Amikke

They reflect more of how the machine thinks than what a higher level language might manage.

@amerika @Amikke yes, this. Array index values can be converted quite easily to an address (or for much older processors, an index) register, leading to more efficient ops for the processor to run.

Remember, C was (and should still be) high-level, cross-platform assembly. If you want your hand held, there are other languages for that.

@amerika @Amikke and this to say nothing of the fact that arrays are just pointers with style 😎

@coldacid @Amikke

I like the way C++ gives you efficient control over what the machine is doing, and you can expand the language with libraries to have just about any high-level function you desire.

The world probably should be re-coded in C++ and Perl.

@amerika @Amikke Perl? You're crazy!

Also I used to like C++ but I've become more of a classic C purist. If I need objects and all that I'll use Obj-C or just go .NET with C# and forget C itself.

@coldacid @Amikke

> .NET

It's powerful but aesthetically it makes me squirm.

I am good with classic C as well. Some aspects of Pascal might be wisely implemented in libraries in addition.

But Perl, Perl is the perfect do-anything language below the applications level. More people should speak it. It is pure brilliance.

@amerika @Amikke interestingly, one of my favourite uber high level programming languages, K, chooses to index from 0, rather than 1, because of the interactions with the boolean datatype and various language primitives it has.
@Amikke porque no los dos

: (index) ( ptr index -- ) over length over < if abort" array index exceeded!" then cells + ;
: index (index) @ ;
: th 1- index ;
@Amikke in forth, you build arrays from scratch :D
and you inevitably end up using raw memory access like @, not the (index) word i created there, and you end up not using 1index because you are directly interfacing with the machine
Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.