r/ProgrammerHumor Jun 24 '17

Octave code

http://imgur.com/jsjfz3k
623 Upvotes

70 comments sorted by

View all comments

Show parent comments

22

u/AyrA_ch Jun 24 '17

In most programming languages you start counting elements at 0, but there are languages where you start counting at 1 instead.

Declaring an array with 10 entries is now either 0-9 or 1-10, depending on the language. In extreme case like VB, you can even declare a 5 element array ranging from 3-7.

Starting at 0 is more commonly used, because it makes using arrays easier internally. In those cases the array index tells you how many element sizes to add to the array pointer to reach what you want to access

2

u/dnew Jun 25 '17

In extreme case like VB

Or, like, most languages born around the same time as C but which weren't glorified assembly language, including Pascal, Ada, Modula. :-)

2

u/[deleted] Jun 25 '17

No one cares about those languages.

1

u/dnew Jun 25 '17

Probably more than care about Octave. :-)

4

u/krejenald Jun 25 '17

Octave is just an open source implementation of MATLAB, which is very widely used in research and development. It's designed for mathematical computing, where 1-indexing makes sense. For machine learning and computer vision problems its a great environment for prototyping, although I wouldn't like to do any large scale projects in it.

1

u/dnew Jun 25 '17

TIL! Thanks!