5 ms·
> The x::xs example is bad because it's a widely used idiom, similar to using i as a loop counter. And IMHO bad for the same reason. I'd rather see "index" th
by gnaritas 14y ago
> The x::xs example is bad because it's a widely used idiom, similar to using i as a loop counter.
And IMHO bad for the same reason. I'd rather see "index" than "i" and I'd rather see "head::tail" than "x::xs", abbreviations for variable names are terrible; the English language is not running out of words and readability is more important than brevity. Of course, I'm a Smalltalker and we like to actually have readable code.
- eswangren 14y agoA loop counter named "i" is a problem for you? Really? I would hate to see every loop counter named "index". It's completely unnecessary and just adds noise to your code. "i" is not going to confuse anyone, not for one moment. Making that name longer just means you have to type more characters and, honestly, looks ametuerish.
- mich41 14y agoEverybody who has ever seen any C code has #define i index programmed deeply in his brain's CPP. Using i for loop counter never causes confusion and using index makes the for statement 12 characters longer for no reason.
- gnaritas 14y agoI'm sure they do, it's not relevant; using short meaningless variables names as a matter of habit eventually always causes confusion because of nested loops. If you can touch type, counting characters is an absurd reason to write obtuse code. Code is read far far far more than it is written; optimize for reading, not writing. I'm very well are "i" is idiomatic; I still think it's stupid, as are many such idiomatic hangovers. Idiomatic does not mean correct or good, it means popular. Well chosen meaningful variable names are always a plus and are a sign of a programmer that understands code is read far more than it is written and not always by those who know all the little idioms of a particular language.
- mich41 14y agoIf you count to 100 or iterate over some array, i, j, k, l are more readable than index1, index2, index3, index4 simply because they are shorter and still mean the same. And if you iterate over some collections of "meaningful" objects, meaningful names are more readable than either i or index. It never makes sense to use index over i.
- gnaritas 14y agoIf there were nested loops, I'd use meaningful names, and as a matter of course of using meaningful names, index beats i on a single loop. It's silly to sometimes use meaningful names and sometimes abbreviate because you're too lazy to type. Of course, these are personal subjective things, but if you allow the habit of abbreviation, it tends to spread where it isn't appropriate, better to simply not do it.
- Dylan16807 14y ago'index' just isn't meaningful. Use actual meaning or use shorthand. Don't waste verbosity.
- klibertp 14y agoOf course, it should be `aStreamPosition` rather than `index` - still not `i` ;)
- gnaritas 14y ago"index" is very meaningful, it tells me I'm indexing and not counting, otherwise I'd use "count". Confusion between those two often causes off by one errors, so yes it does actually matter and is actually meaningful. You might like "i" or "n" to convey the same meaning, but as I said, I want words not abbreviations.