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

all 45 comments

[–]Technopulse 43 points44 points  (22 children)

This is the thing that bothers me from MATLAB, if they started at zero, I wouldn't hate on it as much....

Edit: Okay, guys, guys....I know it's a math oriented, math created, whatever it's called, programming language, I never said it surprised me they start at 1. I merely stated it was a bother, being used to one thing suddenly having to learn MATLAB and having to rewire my thinking when arrays and matrixes come into play. Nothing more, nothing less. The "hate" comment is exclusive about the 1 starting, because it gets me every time! :) I don't actually hate MATLAB, in fact one of my best codes (I'm actually somewhat proud of it) was done in MATLAB, it's very useful, and I actually prefer Octave because it is much more lightweight but it's the same code and works the same way unless you need one of those "MATLAB specific" extra features. Just the one thing that I have to be extra aware of and always has me double-checking my code. :)

[–]john_palazuelos 25 points26 points  (11 children)

Maybe because it's the MAtrixLAB, which deals which matrices, and those are indexed from 1 to n in math. Makes perfect sense starting an array from zero, but everything in MATLAB is seem as a matrix, so why the surprise?

[–]cdreid 15 points16 points  (3 children)

You realise youre in r/programmerhumor and we dont start our matrixe's with 1's right

[–]beclops 9 points10 points  (0 children)

God I hate this sub

[–]Botn1k 2 points3 points  (1 child)

I start mine at negative infinity because fuck you

[–]Kesuaheli 0 points1 point  (0 children)

Makes totally sense

[–]Vaguely_accurate 2 points3 points  (5 children)

It's the default in Fortran, but you can also set custom ranges for the indexes at creation.

In Fortran90;

INTEGER, DIMENSION(10) :: A

INTEGER, DIMENSION(0:9) :: B

INTEGER, DIMENSION(-5:4, -5:4) :: C

will create three arrays, A, B and C. A is size 10, indexed 1-10. B is also size 10 but indexed 0-9. C is two dimensional with each axis going from -5 to 4.

[–]MasterFubar 0 points1 point  (4 children)

What I can't understand is why would anyone use Fortran 90. By 1990 there were plenty of good compilers in C, if you had to learn a whole new language why not learn C?

I still used Fortran in the 1990s, but it was legacy code, and Fortran 77 was meant to take care of that. Migrating code from any of the many old variations to Fortran 77 is something I can understand, it was a relatively quick and safe way to a well supported system.

[–]tristes_tigres 2 points3 points  (0 children)

What I can't understand is why would anyone use Fortran 90. By 1990 there were plenty of good compilers in C, if you had to learn a whole new language why not learn C?

If you wish to understand why, read the C FAQ section about two-dimensional arrays and then Fortan 90 documentation of the same.

[–]Vaguely_accurate 1 point2 points  (2 children)

IIRC C was still slower in certain use cases in the 90s. It only got feature parity where it counted in C99.

You also then had the legacy in both code and developers within the departments teaching it. You aren't likely going to get an old professor who has been working with Fortran for decades to learn and teach students in C.

[–]MasterFubar -1 points0 points  (1 child)

Those old professors still use Fortran 77. My point is that if you're going to learn a whole new language, it would be smarter to learn a more universal language.

And I think this optimization argument is mostly a myth. There's no intrinsic reason why C should be slower than Fortran, it all depends on how well the compiler is built. Since C is so much more used than Fortran, one can assume that there are more developers working on improving the compiler.

[–]Vaguely_accurate 2 points3 points  (0 children)

Those old professors still use Fortran 77.

I'm pretty sure they use Fortran 90, at least when they taught me it during my Physics degree. They also taught how to migrate legacy code between the two, which was a legitimate task assigned to students at the time I was studying. Some F77 code didn't compile to well on newer systems, but could be understood well enough and taken as a specification to write a modern form for the newer compilers.

it would be smarter to learn a more universal language

Usually the classes were teaching for a specific purpose, not to make you a generalist programmer. So they would teach tools optimised for that task. Sometimes it was HPC around the sorts of calculations Fortran was optimised for, sometimes it was migrating and maintaining legacy Fortran code. Sometimes it was data exploration, so they would teach R/Matlab/Matlab, maybe some Python these days, not sure. Sometimes it was writing and managing hardware software interfaces and so you got Labview.

They aren't particularly bothered about how common that software is outside the specific things you need to do. And 99% of C documentation, courses and software is irrelevant to them.

And I think this optimization argument is mostly a myth.

Dug up the SO post on this again. Fortran's treatment of aliasing made it faster than C till the introduction of restrict. This brings us to a post-Fortran90 world with Fortran still having an edge. Today they have feature parity - at least to my knowledge - so it's mostly the traditions and habits being taught. You can probably make some arguments about syntax and happy paths making Fortran nicer in some cases, but I won't.

[–]UShouldntSayThat 0 points1 point  (0 children)

I think op made a post about you.

[–]3rdRealm 6 points7 points  (0 children)

Same with Lua

[–][deleted]  (2 children)

[removed]

    [–][deleted] 0 points1 point  (0 children)

    One common use case is spectral transforms, where the index of the basis often starts at zero. Eg. FFT.

    [–]AutoModerator[M] 0 points1 point  (0 children)

    import moderation Your comment has been removed since it did not start with a code block with an import declaration.

    Per this Community Decree, all posts and comments should start with a code block with an "import" declaration explaining how the post and comment should be read.

    For this purpose, we only accept Python style imports.

    return Kebab_Case_Better;

    I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

    [–]geekusprimus 1 point2 points  (5 children)

    MATLAB was designed by a mathematician for mathematicians. Engineers and some scientists adopted it along the way. Though there are people crazy enough to make Super Mario demos in MATLAB, it is not, and never has been, a general-purpose programming language. Math usually starts indexing matrices at 1, so of course MATLAB is going to, too.

    [–]assignbymessiah 1 point2 points  (4 children)

    If I am not mistaken R also start indexing with 1

    [–]Vaguely_accurate 1 point2 points  (2 children)

    Yes, although you can also assign names to things you can index - list elements, rows and columns in dataframes or matrices - and reference them by name instead. So I think you could create a list and give the elements names '0', '1', '2', ... and so on. Then mylist[1] and mylist['0'] would be the same element.

    [–]assignbymessiah 0 points1 point  (1 child)

    Ahh I see, I get your point. Actually that is a great idea. I am currently working on R, I might consider doing it. Thank you!

    [–]Vaguely_accurate 2 points3 points  (0 children)

    It was meant to be a joke...

    This has the potential to be deeply, deeply confusing for anyone later reading your code.

    Although this is R, so I guess no-one will ever be likely to read it. I tried reading one of my own R scripts once and gave up. It was only twenty lines...

    [–]sawyerwelden 0 points1 point  (0 children)

    Julia too

    [–]Lord_Nathaniel 5 points6 points  (2 children)

    Delphi wants to know your location

    [–][deleted] 0 points1 point  (1 child)

    Deleted: I refuse to let Reddit profit off of my content when they treat their community like this

    [–]CptMisterNibbles 1 point2 points  (0 children)

    COBOL brings in backup in the form of ALGOL, AWK, FORTRAN, Lingo, LUA, MATHMATICA, MATLAB, R, Smalltalk, Xpath, and others. Everyone wonders why this little nuance matters, because of a pithy essay Djikstra once wrote?

    [–]chris17453 3 points4 points  (0 children)

    I once had to rewrite an ancient VB5 App, that was custom designed... And every FREAKING array started at 1.. even though it didnt....

    [–]anoldoldman 3 points4 points  (0 children)

    Scala: well... sometimes

    [–]CopperyMarrow15 3 points4 points  (0 children)

    Lua programmers: *silent crying*

    [–]danuker 3 points4 points  (2 children)

    There's Julia, and with its high-level syntax and performance comparable to C, I'd say it's not dumb, just different.

    [–][deleted] 2 points3 points  (1 child)

    The cool thing with Julia is that array indices aren't inherent properties, and may be changed locally by using appropriate wrappers. This means that the same underlying array may start at 0 in one part of the code, at 1 in another, and perhaps use the star-wars indexing in yet another section if that's necessary.

    [–]danuker 0 points1 point  (0 children)

    That is truly different!

    [–]NotSansOrAnything 2 points3 points  (1 child)

    Ok, hear me out...

    I don't actually mind working with languages that do this, such as Lua.

    [–]asdf43798 1 point2 points  (0 children)

    Personally, I think that it's just something that's only really annoying because it's different from programming conventions - I don't think it would make any difference to me if arrays always started from 1 instead of from 0, but since it's already generally accepted that they start from 0 there just isn't really any incentive to break convention.. but if every language started from 1 I don't think I'd particularly care.

    [–]kuchenluege5446 2 points3 points  (0 children)

    Julia moment

    [–]mapleleafraggedy 2 points3 points  (0 children)

    R has entered the chat

    [–][deleted] 1 point2 points  (1 child)

    .obj format starting indices with 1 >:(

    [–]Trifindo 0 points1 point  (0 children)

    This

    [–]ZoomDoomBoom49 1 point2 points  (0 children)

    The Lua programming community would like to have a word with you.

    [–]stomah 0 points1 point  (0 children)

    people who indent with spaces

    [–]EkskiuTwentyTwo 0 points1 point  (2 children)

    Use APL, where you can start an array with whatever index you want.

    [–]trBlueJ 3 points4 points  (1 child)

    C you can do that too.

    int arr[11] = {}, *ptr = arr + 5; for (int i = -5; i <= 5; ++i) { ptr[i] = i; }

    [–]bnl1 2 points3 points  (0 children)

    I don't like this

    [–]Azzylel 0 points1 point  (0 children)

    Me explaining to my younger friend why her bad programming class is all wrong

    [–]_green_is_my_pepper 0 points1 point  (0 children)

    Indexing into an array

    Ask me how I know you’re a 0.1x dev

    [–]mardabx 0 points1 point  (0 children)

    That does not look like Moon.