Live data from Hacker News

How to Write Unmaintainable Code – Naming

mindprod.com

21–30 of 43 posts

Re: How to Write Unmaintainable Code – Naming

#21

In the interest of fairness, and in regards to the "Underscore, a friend indeed", I'll point to the existence of eg, $_ and @_ as built-in Perl magic variables (you can get away with not using $_, but not @_). I have also been know to use _ for a variable I will not use later (eg, if a function returns two values but I'm only interested in one). Additionally, in languages with pattern matching, '_' usually works like…

It's been a while since I did much perl, but FWIW I seem to recall doing (undef, my $foo) = do_stuff(). Perhaps modern perls have tightened up allowing undef as the target of an assignment.

Re: How to Write Unmaintainable Code – Naming

#22
Number 11 is unbelievably devious. I wonder how many compilers are OK with that?

----------------------------------------------- Use accented characters on variable names, e. g. --typedef struct { int i; } ínt; where the second ínt’s í is actually i-acute. With only a simple text editor, it’s nearly impossible to distinguish the slant of the accent mark.

Re: How to Write Unmaintainable Code – Naming

#23
post #19

Earlier quoted context omitted.

This is a weird one. Using i,j,k for loop values is fine, especially tight inner loops. I can't see that ii,jj,kk adds anything. And I don't see much point in using verbose names like innerLoopIterator or arrayIdx or whatnot for these type of variables either. Actually later on in rule 20 he implies (with negative logic of course) that i is actually a good inner loop variable name. So that's an inconsistency right th…

ii, jj, and kk, are easier to search for (although I have jj mapped to in vim...) index, jndex, and kndex, are preferred, obviously.

jj = changed my life; I'm not even joking. I even went so far as to put my zsh in vi mode and added jj there too. (WARNING: doing this will result in a pathological need to type jjk whenever you open a shell to start scrolling through history.)

Re: How to Write Unmaintainable Code – Naming

#27
post #19

Earlier quoted context omitted.

ii, jj, and kk, are easier to search for (although I have jj mapped to in vim...) index, jndex, and kndex, are preferred, obviously.

jj = changed my life; I'm not even joking. I even went so far as to put my zsh in vi mode and added jj there too. (WARNING: doing this will result in a pathological need to type jjk whenever you open a shell to start scrolling through history.)

I prefer mapping to . Hitting single keystroke. I quickly got tired of hitting 'jj' every time I need to escape.

Re: How to Write Unmaintainable Code – Naming

#28
post #27

Earlier quoted context omitted.

jj = changed my life; I'm not even joking. I even went so far as to put my zsh in vi mode and added jj there too. (WARNING: doing this will result in a pathological need to type jjk whenever you open a shell to start scrolling through history.)

I prefer mapping to . Hitting single keystroke. I quickly got tired of hitting 'jj' every time I need to escape.

I personally use 'kj', which is just a natural roll from my middle to my index finger. Have you tried this?

Re: How to Write Unmaintainable Code – Naming

#29
post #19

Earlier quoted context omitted.

This is a weird one. Using i,j,k for loop values is fine, especially tight inner loops. I can't see that ii,jj,kk adds anything. And I don't see much point in using verbose names like innerLoopIterator or arrayIdx or whatnot for these type of variables either. Actually later on in rule 20 he implies (with negative logic of course) that i is actually a good inner loop variable name. So that's an inconsistency right th…

ii, jj, and kk, are easier to search for (although I have jj mapped to in vim...) index, jndex, and kndex, are preferred, obviously.

If you have to search for loop index variable, your code has worse problems than naming.

I mean - I don't recall writing a loop longer than 2 screens in years. Usually a loop is less than half a screen long.

And anyway, you can search for [^\w]i[^\w] if you really need to.

Maybe it's aquired taste, but in array-heavy code (usually math-related) I much prefer A[i][j][k] * B[j][k][i] than the same with long names for index variables.

Re: How to Write Unmaintainable Code – Naming

#30
post #11

When you need to prevent quick grepping in Java, you can also take advantage of the fact that unicode escapes can occur everywhere in a java file, not only within quotes. So you can declare an int by writing “\u0069\u006e\u0074 \u0069 = 1;” (equivalent to “int i = 1;”)

An IDE should tackle this w/o any problem.
Post reply on HN