Hacker News new | ask | show | jobs
by eMSF 1596 days ago
What I also noticed was one of the problems the author claims that "imperative" style loops have:

>Off-by-one bugs are more probable. For example, you might write i<22 instead, and then the loop would end at 21, not 22.

Ironically, their implementation of a function called "range" differs from the (likely) best known function by that name (that of Python), causing exactly this problem. (Also, the Pythonic range is probably a better fit for a language with 0-based indexing.)

1 comments

If anyone needs a typed JS version of Python's range, I prepared this code to be a 1:1 match with the Python API. It also uses generators: https://github.com/graup/pythonic-ts/blob/main/src/iterators...