Hacker News new | ask | show | jobs
by SoftTalker 14 days ago
Reminds me of a place I worked at where a "naming committee" had to approve variable names. And no, you could not use "i" as an index in a one-line loop.
2 comments

Being able to specify word boundaries in search is a basic feature for any developer tool. Vim has *, #, and /\<i\>. grep also has \<i\> and the -w option. LSPs have jump to definition and find references features.
i and j etc is bad though, but for a different reason than usually claimed. it's suboptimal because it's hard to search for. just use ii, jj, kk, etc
If you need to search for a variable named i - you should have named it something else (and no, jj is NOT an improvement in that case).

One letter variables are supposed to be used in scopes that fit on the screen completely. You might as well search for "for"

TL; DR: it's on purpose.

> One letter variables are supposed to be used in scopes that fit on the screen completely.

Exactly, and ideally in less space than that. If you have something like:

  for (i=0; i<10; i++) {
      foo(i);
      bar(i);
  }
There is no point in using a "descriptive" name for the index. It's completely obvious what's going on. Anything more verbose would just hamper readability.
Also the fact that every search function since the dawn of interactive computing can search for whole words only (like -w in grep or C-w in emacs).
\<i\>