re: What The For Loop? VIEW POST

re: When is code too clever and when is it overly verbose? Once again, you're preaching to the choir and I agree re optimizing for readability, but in ...

extract isOdd out and you can now reuse it elsewhere. It also improves the readability of the for loop.

const isOdd = n => n % 2 === 1

for (let i=0; i<=20; i++){
  if (isOdd(i) {

isOdd should not need to be a function

Ruby has it as a method. ;-) And I think what Sean meant is exactly that: common functionality like this should be part of the core language, so people don't have to go and implement it themselves every time.

Hence "trivial examples are a bad basis for maintainability discussions". In the provided code there is no "elsewhere" so it really doesn't need to be a function at that time (YAGNI and all that, and Donald Knuth had strong opinions on this one too).

Anyway, in a language with a less poor standard library we wouldn't have to define simple functions to check an integer's parity, so I think this discussion has run its course.

Code of Conduct Report abuse