3 ms·
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 “
by grzm 9y ago
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.
- runevault 9y agoClojure 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.
- setzer22 9y agoReplacing (first coll) by (nth 1 coll) in clojure happens to me more often than I'd like to admit
- synthc 9y agoI would not call Clojure 1-indexed though because of 'first', it uses 0-indexing for list, vectors, and arrays.
- grzm 9y agoTo 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.