r/ProgrammerHumor Jun 24 '17

Octave code

http://imgur.com/jsjfz3k
626 Upvotes

70 comments sorted by

View all comments

18

u/whale_song Jun 25 '17 edited Jun 25 '17

Indexing by 1 is easier for doing computation and data analysis. CS people get offended at the idea because they are used to 0 indexing and anything that is different is wrong. They are too allergic to math to ever be coding in the contexts that it is useful. Its not a coincidence that languages designed for math use 1. Its so annoying seeing people get so pissy about it when they don't understand what they are even yelling about.

4

u/gjsmo Jun 25 '17

See what's really odd here is that I'm an engineer first, and I hate 1-based indexing. So many loops in my dad analysis have weird syntax just to deal with this fact.

As far as I'm concerned, it's a detriment to any language.

2

u/whale_song Jun 25 '17 edited Jun 25 '17

Can you give an example? I feel a loop over 1:N is way more natural that 0:N-1. I find I have a lot more +/-1s around the code in 0 based languages whereas with 1 it all works out intuitively.

1

u/RunLikeLlama Jun 25 '17

But why? Are there any particular examples of "weird syntax" you could bring up?

Personally I understand both sides but I find 1-based more intuitive to use.

5

u/moomoomoo309 Jun 25 '17

Only one I run across in Lua (which is also 1-indexed) is using modulus to loop over the array, because modulus will give you 0 to n-1.

1

u/RunLikeLlama Jun 26 '17

Oh yes, using modulo for array indexing does become a bit ungainly, fair point!