askql icon indicating copy to clipboard operation
askql copied to clipboard

[askscript] Should we implement (pre) incrementation?

Open czerwinskilukasz1 opened this issue 4 years ago • 3 comments

Javascript has both pre- and post-incrementation, useful in loops, e.g.:

  let result = [];
  for (let i = 1; i <= m; ++i) {
    result.push(n*i);
  }

How about we implement preincrementation (++i)?

czerwinskilukasz1 avatar Jul 09 '20 19:07 czerwinskilukasz1

@mhagmajer

czerwinskilukasz1 avatar Jul 09 '20 19:07 czerwinskilukasz1

I think i = i +1 is fine for now. I know that a lot of C programmers (me included) are used to ++, however it is more difficult to read than i = i + 1 while not offering little advantage (given the current performance limitations). If I remember correctly, the popular AirBnB preset for eslint actually forbids i++ and prefers i=i+1. Therefore I would hold on with this until we have better performance where it actually matters how this operation is done (i++ vs ++i)

mhagmajer avatar Jul 10 '20 09:07 mhagmajer

I guess in scripting languages like Javascript ++ is no longer about program performance, it's about programmer's convenience.

czerwinskilukasz1 avatar Jul 10 '20 10:07 czerwinskilukasz1