News for hackers. Stuff that matters.
Re:Julia 1.9.0 lives up to its promise by leephillips on Saturday May 13, 2023 @06:19PM (#35933337)
You should never write loops that way, at least in code you're going to share (assuming that you’re going to have some arr[i] in the loop body).

Assuming that arrays start at 1 is a source of occasional bugs in public packages. The existence of OffsetArrays means that arrays can start at any index (so for people who get nauseated by 1-based arrays, you can change it).

Instead, write "for i in eachindex(arr)".

In fact, Julia’s array syntax means you can loop over and manipulate arrays without using indexes much of the time, so don’t even need to know how they’re based.

There are no comments on this comment yet.