News for hackers. Stuff that matters.
Re:A Dictionary of Single-Letter Variable Names by gus_massa on Sunday October 13, 2024 @07:49PM (#41832770)
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.

Re:A Dictionary of Single-Letter Variable Names by jmillikin on Sunday October 13, 2024 @07:56PM (#41832818)
I 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.

Re:A Dictionary of Single-Letter Variable Names by throw4950sh06 on Sunday October 13, 2024 @08:29PM (#41833005)
You need better tooling. My editor can highlight all references using the type checker.
Re:A Dictionary of Single-Letter Variable Names by evoke4908 on Sunday October 13, 2024 @10:00PM (#41833506)
> Someone shouldn’t have to use source inspection assistive coding tools to parse the code you write
Re:A Dictionary of Single-Letter Variable Names by ruszki on Sunday October 13, 2024 @10:26PM (#41833668)
This 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.

Re:A Dictionary of Single-Letter Variable Names by achierius on Sunday October 13, 2024 @10:48PM (#41833763)
"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.

Re:A Dictionary of Single-Letter Variable Names by strken on Sunday October 13, 2024 @11:53PM (#41834030)
In 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?
Re:A Dictionary of Single-Letter Variable Names by chaboud on Monday October 14, 2024 @04:04AM (#41835299)
“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.

Re:A Dictionary of Single-Letter Variable Names by throw4950sh06 on Monday October 14, 2024 @06:10AM (#41836020)
When building at scale, it's not possible to rely on stuff like "everybody should name the iterators differently than it's normally done".

It's not inconsiderate, we are doing a job. If you can't do your job, you don't have place in my team. And properly using an IDE is definitely part of the job. What are you using that can't open web VSCode that has all these features?

Re:A Dictionary of Single-Letter Variable Names by chaboud on Monday October 14, 2024 @01:29PM (#41839722)
There's a big difference between "rely on" and "be considerate of". I'll take from the recently-created throw-away account that you know this already, and, based on this interaction, I don't think I mind not having a place in your team.
Re:A Dictionary of Single-Letter Variable Names by throw4950sh06 on Monday October 14, 2024 @02:13PM (#41840241)
As a manager of a large engineering organization, I'm unfortunately forced to not be considerate in order to make the org scale to dozens/hundreds of people. Proper usage of tools is crucial and I spend considerable resources to teach the engineers in my org about the tools we use. We took a great deal of effort to make the dev experience full featured, accessible and universal.

You click a button and get a web browser based IDE where you have everything ready, connected to a cloud computer with a full dev env that mirrors our prod env; that from any branch and the button is right there in pull request UI. There is no reason why someone in this org should require everyone to write double letter iterator var names just because they couldn't be bothered to play the video where I taught how to use the advanced code search and the feature could be available to them in less than a minute of fooling around if they tried.

On this scale, following standards is absolutely necessary. If my engineer has to stop and think "but wait, in this company they do it differently" - this times 150 people I currently manage - then I failed at my job.

Some devs hated me when I came into this (much smaller back then) company few years ago and the first step I did was to put a global linter and formatter there. They were angry about how they would format it better than the formatter. Well that's nice - but that doesn't scale to hundreds of people. People make mistakes, stop caring, have different opinions... And all these questions in their minds are again my failure at my job. It's my job to answer these once and forever and to make it easy to follow the rule.

While this is a personal anecdote, I was a large corporate principal engineer for many years and I am mirroring what I saw working there. I can't say this approach to making software engineering work at scale is uncommon.

Please note that here I'm talking about working at a job, usually for very good money. Nothing of this applies to personal projects, most open source projects and so on. In these cases I'm very much on your side.

Re:A Dictionary of Single-Letter Variable Names by andoando on Monday October 14, 2024 @11:16AM (#41838316)
just search for "int i", "let i", etc?
Re:A Dictionary of Single-Letter Variable Names by pavel_lishin on Monday October 14, 2024 @11:58AM (#41838755)
That finds the start of the loop, but not occurrences of that index inside the loop.
Re:A Dictionary of Single-Letter Variable Names by jraph on Monday October 14, 2024 @12:50PM (#41839303)
Many 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.

Re:A Dictionary of Single-Letter Variable Names by arp242 on Monday October 14, 2024 @02:23PM (#41840342)
You 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.

Re:A Dictionary of Single-Letter Variable Names by greyfade on Tuesday October 15, 2024 @04:11PM (#41852613)
I 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.
Re:A Dictionary of Single-Letter Variable Names by pxx on Sunday October 13, 2024 @07:55PM (#41832810)
I've seen this specific example used to speed up find-next, but it's not like the false positives are frequent enough to bother.
Re:A Dictionary of Single-Letter Variable Names by lemonwaterlime on Monday October 14, 2024 @09:16PM (#41843969)
If 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.

Re:A Dictionary of Single-Letter Variable Names by card_zero on Tuesday October 15, 2024 @01:50AM (#41845330)
I use i for the outer loop and ii for the inner loop, like they're Roman numerals.