187 Comments
- Pottypotsworth, on 07/28/2008, -3/+84i name all my variables after Star Trek characters because i am extremely cool
- diadem2, on 07/28/2008, -0/+62The article can be summed up in one sentence; "don't do stupid *****."
- Darkaged, on 07/28/2008, -9/+66This is actually good news, seeing as 2 of my friends died from badly named variables.
- crazyjake, on 07/28/2008, -2/+38god i hate going through code and seeing variables like "vrujk" or "drmww" (actual examples) and worse, there are no comments at all!!
- pixelfishfood, on 07/28/2008, -0/+31My worst variable naming stories:
In college, offered to help my boyfriend debug some code for an introductory programming class. When I looked at the code, I realized that he had named all of his variables in Japanese, which I don't know. Even if I did a search and replace all on the each of the variables, they lost their original Japanese meaning.
Also, a friend of mine deliberately obfuscated some code that he had to give to a competitor by renaming all of the variables with zeros, capital Os, lowercase Ls, and uppercase Is like this:
0IIO0III
0llOOIIl
OIl00lll - GMorgan, on 07/28/2008, -7/+33Everyone does it wrong. My variables are always called 'Ni', 'Peng' or 'Neee-wom'. If I need another variable then I use 'Ecky-ecky-ecky-ecky-pikang-zoop-boing-goodem-zoo owli-zhiv'. Also all my programs have the global definition 'FIVE = 3'.
- CobaltBlue, on 07/28/2008, -2/+28Couldn't you have chosen better examples? I mean, drmww is a standard variable for Digital Rights Management for World of Warcraft
- hwy9nightkid, on 07/28/2008, -3/+29I just got done with a project where my partner, who I will keep nameless, named variables such as sleepingBeauty, magicCarpet, and other various BS names. I'm sick of trying to figure out how to .wake() the princess..
Name things properly, and most of all COMMENT COMMENT COMMENT...
I agree with everything there, except #4, in essence..I add tempXXX as a var name for a temporary ID or tempThread... - jnuffnuffnomnom, on 07/28/2008, -0/+20If you have a girlfriend then there is hope for us
- pixelfishfood, on 07/28/2008, -0/+19yeah, they were probably more like this:
I0IIO0III
l0llOOIIl
lOIl00lll
happy? - jnuffnuffnomnom, on 07/28/2008, -3/+22Learn how to program [insert language here] in 21 days, 1st page.
- sukimashita, on 07/28/2008, -0/+17lOl
- HAKdragon, on 07/28/2008, -0/+16As the joke went during my programming courses, "Hey, this was hard to write, it should be hard to read!"
- sjmulder, on 07/28/2008, -0/+15The thermostat UI coders forgot that the backend uses Celcius. (rule #2)
- CosmicJustice, on 07/28/2008, -2/+16Microsoft's IDE is exceptionally good.
- Narishma, on 07/28/2008, -1/+13Single letter variable names are ok if you use them only in loops or small functions.
- Murdats, on 07/28/2008, -0/+11so are you trying to say that you are too egotistical to use a good IDE? are you worried you will lose your bragging writes by no longer coding in c in plain text?
- fas2, on 07/28/2008, -4/+15This list is really not helpful. He basically says what he likes, not what really is good practise. In practise, no one really cares if it's callback or callBack.
Also he assumes that everyone uses some sort of IDE. He forgets, that there are tons of developers out there using vi, emacs and the sort.
"Make your variable names long and descriptive". This should just be "Make your variable names descriptive". If it is short and I understand it, I'm good.
Temp is a valid name for not only swap files, but everything short code block that uses a temporary variable, e.g. to swap two references or something. It just should not be used over pages of code.
I totally agree with i in short loops.
All in all, a really useless post. There are much better style guides out there. - sjmulder, on 07/28/2008, -0/+11Isn't that second one illegal?
- redundant, on 07/28/2008, -6/+16int this, that, theOther;
if (this > that)
{
theOther = this;
this = that;
that = theOther;
} - stretch611, on 07/28/2008, -0/+9Everyday I see real world code and everyday I see stupid ***** in code. (Occasionally, it is even code that I wrote and I wonder WTF I was thinking at the time.)
- CobaltBlue, on 07/28/2008, -0/+9You really should change those to Ni, Peng, Neee_wom, and Ecky_ecky_ecky_ecky_pikang_zoop_boing_goodem_zoo owli_zhiv. Much easier to read and type.
- Murdats, on 07/28/2008, -1/+10try managing 2000 files in vim and lets see how well you manage remembering all the library references and changing between numerous files. its not only about remembering file names, having it auto complete class paths comes in very handy aswell as listing the various parameters to functions.
and no one denies its a resource hog, but when those resources are being used to increase your efficiency its a worthwhile trade, otherwise why did you buy your computer? why not use a 800mhz computer with 256mb of ram? - ElFredo, on 07/28/2008, -0/+9How To Write Unmaintainable Code:
http://freeworld.thc.org/root/phun/unmaintain.html
"Cd wrttn wtht vwls s mch trsr
When using abbreviations inside variable or method names, break the boredom with several variants for the same word, and even spell it out longhand once in while. This helps defeat those lazy bums who use text search to understand only some aspect of your program. Consider variant spellings as a variant on the ploy, e.g. mixing International colour, with American color and dude-speak kulerz. If you spell out names in full, there is only one possible way to spell each name. These are too easy for the maintenance programmer to remember. Because there are so many different ways to abbreviate a word, with abbreviations, you can have several different variables that all have the same apparent purpose. As an added bonus, the maintenance programmer might not even notice they are separate variables. "
Someone took this article too seriously! - billizm, on 07/28/2008, -0/+9Try going though real old code written on mainframes, when they had to conserve disk space. They even abbreviate things like "facts" to "fax" and "phone" to "fone" - if your lucky enough to see variables that resemble words.
- cornflakepirate, on 07/28/2008, -0/+8duh, so use j?
- Spuy767, on 07/28/2008, -2/+10"When I was at uni some 10 years back now, I remember one of my lecturers telling me not to make variable names too long because you would get "pain in your fingers"
He probably said that before you could get a text editor with a programming function to finish most variable names automatically, with the current generation of IDE, you can have ridiculously long variable/method names and not worry about having to type too much. It pains me greatly that he had to mention Microsoft's IDE which is like training wheels for coders, but whatever. Best to be descriptive. Better to name a variable theSumOfTheSquaresOfTheLegsOfARightTriangle than trying to figure out what the ***** a random num1 is in the middle of a long code block. - TEMM, on 07/28/2008, -1/+9That probably wont work in alot of OO languages because this is used to refer to the object that is the owner of a method.
- stevekwan, on 07/28/2008, -0/+7I fondly remember reviewing the line of code:
IF SEXIST THEN
After a bit of confusion, I realized that SEXIST was some deranged abbreviation for "string exists." - dood, on 07/28/2008, -0/+7http://digg.com/tech_news/Digg_We_Have_a_Problem_P ...
- thespiff, on 07/28/2008, -0/+7But but but Lean Software Design Principles say you should not use comments in code. The code should speak for itself...ugh.
- SSUK, on 07/28/2008, -1/+8There is no hope. There never is...
- FLarsen, on 07/28/2008, -0/+7I program in windings.
- Murdats, on 07/28/2008, -1/+7@tehdoctor
based off your comments I would figure that program as a hobby or are a sys admin but dont work on any large scale projects, for small scripting tasks or relatively small projects I agree the likes of vim are great, but its when you are dealing with very large projects that visual studio really pays off.
I do all of my scripting and text editing in vim, but use visual studio for developing proper applications. - thespiff, on 07/28/2008, -0/+6I get where people are coming from with this opinion, but it breaks down when you have theSumOfTheSquaresOfSensorAData and also theSumOfTheSquaresOfSensorBData and theSumOfTheSquaresOfSensorCData and so on. You end up with this whole pile of garbage variable names that are only differentiated from each other by a few characters buried in the middle of the string. And code completion won't make it much easier to pick the right one. You should really aim for minimizing the length of a name while still being sufficiently descriptive...
- Evdog, on 07/28/2008, -0/+6I think his point was that "temp" is okay if that's it's actual use (for example in a swap, or maybe like you said, a temporary Id/thread/file and I'm sure there's other valid times), but don't use it unnecessarily. I remember a while back debugging some guy's code where he had these nested loops and every variable was named temp1, temp2, temp3...
I just deleted it all and started again rather than give myself the headache.
I know it sounds obvious but some people need it spelled out for them. - tigreblanco, on 07/28/2008, -0/+6Spuy - while I can't agree with you more about being as decriptive as possible in variable names, the reason you stated is not good design in the first place.
If you're in the middle of a long code block, you should be more worried that you're not refactoring that method into smaller, easier-to-test methods instead. - marx2k, on 07/28/2008, -0/+6At least i don't use Type Prefixes.
String strRetarded = "You mean like this?"; - uways, on 07/28/2008, -0/+5RedundantRedundancy
- jlebrech, on 07/28/2008, -0/+5i is pretty much defacto for loops, so is ii, j and jj.
so now you'e not that bad. - benologist, on 07/28/2008, -4/+91. Make your variable names long and descriptive
You still have to fit 60 or whatever lines of code on your screen so why devote half a line to a variable name? Names can be *short* and descriptive and context tells the rest of the story.
2. Put units in your variable names
In some scenarios this is fine. But context is better, so write intelligent code with intelligent comments and the next guy to read it won't wonder if something is 3000 metres or 3000 millimetres.
3. If you are using Camel Case, don't capitalise commonly hyphened, or combined words.
Every single part of that 'rule' is subjective including whether a lot of words should be hyphonated, combined or left seperate.
4. Never, ever use the variable name temp.
Never, ever. Except it's okay sometimes. Name your variables whatever makes sense, and if a value needs to be held temporarily for an immediately obvious purpose temp makes sense.
5. int i is perfectly valid in a small loop.
Duh. So is j, k, l, m, counter and whatever else you want to use. What kind of tip is that anyway? An integer is okay to use when you want to do something x times? - inactive, on 07/28/2008, -3/+8Lately I've been seeing this "2 of my friends died" thing, where did that originate? Sure is popular on /digg/
- FLarsen, on 07/28/2008, -2/+7"i" is easier and takes up less space. It's also common so it won't confuse people.
- ripter, on 07/28/2008, -0/+5A company I worked for hired a contractor to do some website programming. Nothing worked quite right and they wanted me to fix the code. Her variables where in different languages. Like she had a sort loop that was written in German, and then the authentication was written in french. That was a huge pain to fix.
- ripter, on 07/28/2008, -0/+5That's awesome! I'm going to start naming my variables like that at work.
- eggsovereasy, on 07/28/2008, -1/+6@TehDoctor
I do .NET programming for my job and use VS2005. I understand what you are saying, I mainly use it like a text editor. I only pause to look at the intellisense when I'm unfamiliar with a class and want to look through its methods (just like I would look at the documentation) or at the parameters for a method (again just like I would at documentation). However, this is minor, I could just as easily look at MSDN.
Where VS really pays off and improves my productivity enormously is managing the files and namespaces in large projects and the really big one is debuging. VS makes debuging very quick. - Stavrosian, on 07/28/2008, -0/+5That was me. I do it deliberately to ***** with more competent people who have to fix my *****.
- marx2k, on 07/28/2008, -0/+5"Occasionally, it is even code that I wrote and I wonder WTF I was thinking at the time."
*It's 4:55PM, it's Friday. Hot date + beer* - rblancarte, on 07/28/2008, -1/+6most people believe this - it is wrong. They will still fire you.
- skinrock, on 07/28/2008, -0/+4Annoying? You mean doesn't work at all?
-
Show 51 - 100 of 188 discussions



What is Digg?
The Digg Toolbar for Firefox lets you Digg, submit content, and keep track of Digg even when you're not on the Digg site. Download the official