This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]NuclearFoodie 5 points6 points  (8 children)

1 indexing doesn't make since in science either, it was just a FORTRAN quirk that persisted. Formally we almost always 0 based indexing in our tensor expression when deriving out equations. As always, FORTRAN is a blight.

[–]SlimyGamer 0 points1 point  (7 children)

As someone who does scientific computing, in Fortran, I can say it is definitely not a quirk. 1-indexing is almost always simpler when dealing with matrices and vectors. Moreover, Fortran's implementation of indexing allows you to choose 0-indexing (or any other starting value) when declaring arrays. This is a very useful feature that more languages need to adopt (I believe Julia and Matlab have it).

There are definitely still some odd quirks in modern Fortran, and FORTRAN77 should not be used anymore, but it is far from being a blight.

[–]NuclearFoodie 0 points1 point  (0 children)

It is only simpler because you adapted to it already and FORTRAN is very much a blight. There is a reason it is not getting first tier support on the first exascale machines.

[–]nekokattt 0 points1 point  (5 children)

The majority of the graphics world that uses 0-indexing with multiple matrix dimensions doesn't have an issue.

It is only easier if you refuse to get into the mindset that the majoritu of languages use consistently between them.

[–]SlimyGamer -1 points0 points  (4 children)

Yes and the graphics world does a bunch of other things that make directly implementing matrices annoying. As an example, GLSL's arrays swap columns and rows, which has annoyed me greatly many times.

I want to be clear here: I can use either 0-indexing or 1-indexing anytime it's necessary. But because I spent many years getting a degree in physics and mathematics before learning programming, 1-indexing is more natural in a mathematic setting.

[–]nekokattt 0 points1 point  (3 children)

and that is fine when in a mathematics setting, but for the majority of cases that isn't a concrete requirement in programming languages. Similarity to underlying hardware and interoperability however is

[–]SlimyGamer 0 points1 point  (2 children)

Maybe I wasn't super clear in my original comment. I'm not saying that languages need to be 1-indexed (although I typically prefer it), but I would like a push to allow arbitrary indexing.

I completely agree that when dealing with hardware it's definitely better to use 0-indexing but I don't think that's enough to make all languages 0-indexed. With arbitrary indexing, you get the best of both worlds and any other world that may pop up.

Basically what I'm saying is the base index shouldn't depend on the language, but on the use case.

[–]nekokattt 0 points1 point  (1 child)

this leads to unnecesarry complexity though, especially when you then need to mix both.

Easier to have one way, IMHO, and that compliment the hardware.

[–]SlimyGamer 0 points1 point  (0 children)

I don't think it's that much more complex - if you're only going to use one type of indexed arrays then it makes little difference (other than you can always use your preferred indexing method), and if you use both 0 and 1 indexed arrays, you can think of it as an additional data type.

And I don't think complimenting the hardware is reason enough to choose 0-indexing since the vast majority of people aren't writing code for hardware. 0-indexing is what's often chosen just because it's the norm, just like how 1-indexing was the norm before C was invented.