OP forgot an important tool: store as many variable as possible in one long array. When ever possible use predefined constants like "one," "first," and "superVar" to refer to the index of the desired value in the Array, make sure that all of the above mentioned constants have the same value and are defined in different parts of the code.
How to Write Unmaintainable Code – Naming
31–40 of 43 posts
Re: How to Write Unmaintainable Code – Naming
#32 $a = 'cat';
$$a = 'hello';
echo "$a"; // "cat"
echo "$cat"; // "hello";Re: How to Write Unmaintainable Code – Naming
#33When 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;”)
It's important to use this sparingly. When grepping is obviously broken, the adversary will adapt, most likely by writing a script to rewrite the Unicode, then it's back to business as usual. On the other hand, if grep has a 95% success rate, the adversary may well never notice, and build his or her mental model of the program on flawed understanding. That's when the real fun begins.
Re: How to Write Unmaintainable Code – Naming
#34I once worked on a project where every class was named after a martial arts weapon. As cute as that might have seemed, I quickly grew tired of asking questions like, "Should I be using the Shuriken or the Wazikashi here?" We ended up scrapping that code and doing a ground-up rewrite.
Particularly in the Rails and JavaScript package-spheres, every other library has an incomprehensible name that turns out to be an obscure reference to some pop-culture thing (and often some other library as well, to make it even more undecipherable).
I guess it's fun for the developers and makes their résumé look more interesting ("I made a process monitor called Stiglitz, it's named after a Tarantino character!"). But it's tiresome for the person who has to read the code where these characters go about their exciting adventures updating database records, concatenating strings and sending email.
Re: How to Write Unmaintainable Code – Naming
#35Earlier 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.
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 i…
Re: How to Write Unmaintainable Code – Naming
#36Reuse identifiers? Yes! If I've got a parameter foo that's a string, then I convert it into an int and never use the string again, why not rebind the identifier? It makes it clear the old foo is no longer in use, and prevents such use.
Re: How to Write Unmaintainable Code – Naming
#37Re: How to Write Unmaintainable Code – Naming
#38My favorite way of doing naming in JavaScript is using ಠ_ಠ as a variable (especially if I need to create some sort of quick "hack" to make some sort of urgent issue go away). Also fun is using reserved JavaScript keyboards inside of JavaScript objects which, while legal, rarely color correctly in code editors.
Re: How to Write Unmaintainable Code – Naming
#39Re: How to Write Unmaintainable Code – Naming
#40In 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.