3 ms·
Why is ii better than i??? I may understand that instead of x,y it may be better to use px,py for positions and vx,vy for speed. Perhaps xx,xy for position. Bu
by gus_massa 2y ago
Why is ii better than i???
I may understand that instead of x,y it may be better to use px,py for positions and vx,vy for speed. Perhaps xx,xy for position. But I'd never use yy.
- lemonwaterlime 2y agoIf you’re doing any kind of scientific computing or electronics computations, “i” or “j” mean the imaginary number sqrt(-1). Some software, such as Matlab, have those letters reserved for the common case of imaginary roots of a polynomial, and “ii” and “jj” as variables is a common coding convention. Whether “i” or “j” is your letter for imaginary numbers depends on if you’re an electrical engineer or not.
- card_zero 2y agoI use i for the outer loop and ii for the inner loop, like they're Roman numerals.
- pxx 2y agoI've seen this specific example used to speed up find-next, but it's not like the false positives are frequent enough to bother.
- jmillikin 2y agoI use `ii' and `jj' etc for all my loop counters, because it's easier to search for in any editor. Searching for `i' requires learning the local editor's way of marking word boundaries, otherwise it'll highlight every instance of the letter `i' which is useless. Searching for `ii' has less noise because very few words have that sequence in them, and `jj' is even rarer.
- jraph 2y agoMany editors can search for whole words. Some editors like Kate highlight whole words by just selecting them (and it will not highlight letters in words). Some also do that just by placing the cursor on a word.
- arp242 2y agoYou can use \bi\b in most regexps. Or \<i\> in Vim (pressing "*" will do that for the word under the cursor). This is kind of basic stuff that was around in the 90s, possibly even 80s.
- greyfade 2y agoI would suggest that if you need to search every instance of the variable `i`, your loop is too large and needs to be refactored. Variables like this should only be used in a highly restricted scope that fits on your screen in 36-point font. If the scope is any larger, you need to search, and at that point, you have bugs.
- throw4950sh06 2y agoYou need better tooling. My editor can highlight all references using the type checker.
- evoke4908 2y ago> Someone shouldn’t have to use source inspection assistive coding tools to parse the code you write
- ruszki 2y agoThis is nonsense. You can parse every code with simple Notepad, if you have time. You don’t need to use even search, if you wish. Or you can make your life easier, and use tools which helps you. Once again, regardless of codebase.
- achierius 2y ago"If you have time" is the operative point here. The idea is to make it efficient to quickly search for occurrences. So then you get back to the LSP question -- but for larger codebases I can tell you, those don't always work as well as you'd hope. I don't use 'ii' but it's admittedly much easier to just `rg` for variables than hope my editor plugin decides to work today.
- strken 2y agoIn general I agree with you, but in the specific case of loop variables, how much code do you need to search through? How big is your loop if you need to reach for rg to understand it?
- chaboud 2y ago“You need better tooling” is inconsiderate of others. Sometimes you’re in a browser reading over a CR, or you’re sitting at someone else’s machine, or debugging an emergency via a smartphone. Whatever the case, is it really that hard to use a two-letter loop counter? Try it sometime. When building at scale, it just makes sense to be considerate of diversity and do the little things to that make life easier for others.
- andoando 2y agojust search for "int i", "let i", etc?
- pavel_lishin 2y agoThat finds the start of the loop, but not occurrences of that index inside the loop.