Hacker News new | past | comments | ask | show | jobs | submit login

What it is about code written in languages that prefix variables with $ that results in unmaintainable code?

I'd personally vote for i and j

Mea Culpa: I've written my fair share of horrid code in PHP and Perl.




When you use i and j as loop indices, everybody knows what you're talking about. It's idiomatic. How is that bad variable naming if its the clearest thing for everyone?


> How is that bad variable naming if its the clearest thing for everyone?

The clearest thing for me would be:

    channel.open()
Which indicates to me that a channel is being opened.

Rather than

    i.open()
Which means nothing to me unless I find and read some other line.


Nobody's suggesting that i and j be used for anything other than loop counters: integers. In fact they come from FORTRAN, where a variable starting with a letter [i-n] was an integer, whereas variables starting with other letters were floats.

Personally, I much prefer the certainty of the current situation to the relative uncertainty of a free-for-all. That and for (counter = 0; counter < N; counter++) seems very longwinded.


> Nobody's suggesting that i and j be used for anything other than loop counters: integers

You're right, I missed the 'indices' part of your original comment. Unfortunately I've worked at a couple of places where they're used in every for loop.


Maybe this is just a personal thing, but it always struck me as odd that the recommended variable names for loop counters are the two letters that look most similar to a semicolon. I tend to use x and y.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: