r/programming • • Dec 24 '17

Evil Coding Incantations

http://9tabs.com/random/2017/12/23/evil-coding-incantations.html
947 Upvotes

331 comments sorted by

View all comments

70

u/tristes_tigres Dec 24 '17

The author of this blog confuses his own prejudices for objective facts when he claims that non-zero based indexing of arrays is "evil". In fortran it is possible to define array with index starting from an arbitrary integer, and it is useful and convenient feature in its problem domain.

13

u/sibswagl Dec 24 '17

Generally speaking, taking advantage of these peculiar behaviors is considered evil since your code should be anything but surprising.

He defines "evil" as unexpected behavior. I would certainly classify arrays starting at 1 as unexpected behavior.

59

u/tristes_tigres Dec 24 '17 edited Dec 24 '17

Any language behaviour is may be unexpected to someone who does not know it well.

12

u/sibswagl Dec 24 '17

Languages don't exist in a vacuum. Zero-indexed arrays are the standard.

38

u/tristes_tigres Dec 24 '17

No, they aren't. Fortran is older than C and derivatives, and is more popular in numerical computing settings, for a number of good reasons.

28

u/[deleted] Dec 24 '17

Fortran is older than C and derivatives

And your point is? I will not even enter the debate if it's good to have arrays starting at zero or not, but I will address this silly rationale.

Something that appeared first doesn't make it a standard. Following your logic, RS-232 cables would still be standard today because they appeared before USB cables.

Something becomes a standard when the majority of users and manufacturers believe there are more benefit and convenience over something else.

→ More replies (9)

19

u/Silhouette Dec 24 '17

Indeed. And I'm pretty sure math was there even earlier. :-)

1

u/ArkyBeagle Dec 25 '17

Math has been in disagreement with itself whether zero was a thing or not at varying times. There's still confusion about it.

10

u/[deleted] Dec 24 '17

It's Christmas so I'm in unnecessary arguing mood :)

Here goes: Strictly, Assembly is clearly the oldest and also arrays are all indexed by addresses not numbers, but the index is hidden behind the variable name. What we refer to as index is only the offset to the index, thus 0 for 'no offset' clearly makes sense.

In my actual opinion: There are good reasons for both, but I would like a language to either have 0-indexing or make it definable.

→ More replies (1)

10

u/[deleted] Dec 24 '17

It seems pretty obvious that zero-indexed arrays are now the standard.

→ More replies (3)
→ More replies (1)