Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

While many languages follow a 0-indexed convention, as you see here, not all do. Another couple of cases I run into are Postgres arrays, and switching between “first”, “second”, and “nth” in Clojure.

If it helps, you can think 0-indexed as referring to the offset, and 1-indexed as referring to the position. It’s a shame to dismiss the entire language due to what one might argue is a minor aspect.



I would not call Clojure 1-indexed though because of 'first', it uses 0-indexing for list, vectors, and arrays.


To be clear, I’m not calling Clojure 1-indexed: I provided “nth” and “first” as examples of contrasting 0- and 1-based conventions; in this case within the same language.


Clojure being a lisp also has different enough syntax it is easier to jump back and forth because you're doing way more context switching. Lua looks enough like other c-style languages you can forget it is 1 based and make all sorts of nasty mistakes.

You can certainly argue it is unfair, but it is still something that increases the risk of mistakes.


Replacing (first coll) by (nth 1 coll) in clojure happens to me more often than I'd like to admit




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: