• Cro (cs)

    First!

    This sounds like the project I'm currently working on...

  • Fubar (unregistered)

    Hey, I'm an embedded coder.

    Hey, I have a brother.

    Thankfully, if I EVER tried ANYTHING close to that. He'd ground and pound me before I got the words 'single letter variables' out my mouth.

  • Charles400 (cs)

    What do you mean, "Add a comment?"

  • Kermos (cs)

    The whole variable naming thing reminds me of this one guy at a company I worked at. He did exceed 1 letters in his names, usually but this names were still not any more useful.

    Generally, they looked like this:

    button1 button2 button3 button4 ... button20 (no, I'm not kidding).

    That is assuming they were even spelled correctly in the first place. Really a pain to work with someone's code when they can't even spell the word 'minimum' right and have several variables with varying spellings throughout their code.

    Luckily he was eventually let go and I replaced him and completely replaced all his code with non-WTF code.

    Sadly, he thanked me later as because of this he got hired somewhere else at twice my salary. Is there no justice in this world?

  • That Troper (unregistered)

    I have "x" as a parameter in a couple functions in the media player I'm working on:

    setShuffle (bool x) { shuffle = x; cout << "Shuffle was set" << endl; }

    Only because it's super-obvious what the function does.a

  • Capt. Obvious (unregistered) in reply to Fubar
    Fubar:
    Hey, I'm an embedded coder... and pound me before I got the words 'single letter variables' out my mouth.

    That's because you're using compiled source code. Variable name length doesn't matter (up to a limit imposed by the compiler... 32 chars for C?). But for an interperted runtime, single-letter variables are faster*. And whitespace, indentation and whatnot, is just extra characters that have to be processed*.

    If you grew up watching clock cycles, you too would know this.

    *Sure, the amount of saved time will be next to negligable, or the code can be compiled to an optimized/obfuscated form while keeping a modifiable version somewhere else. But why not get right in there with the 1s and 0s.

  • Joseph (unregistered)

    tchbo

    Translation: This comment has been optimized.

  • Sven (unregistered) in reply to That Troper
    That Troper:
    I have "x" as a parameter in a couple functions in the media player I'm working on:

    setShuffle (bool x) { shuffle = x; cout << "Shuffle was set" << endl; }

    Only because it's super-obvious what the function does.a

    And replacing x with something like "value" would hurt nothing and make the code even more super-obvious.

  • Wonz (unregistered) in reply to Sven
    Sven:
    That Troper:
    I have "x" as a parameter in a couple functions in the media player I'm working on:

    setShuffle (bool x) { shuffle = x; cout << "Shuffle was set" << endl; }

    Only because it's super-obvious what the function does.a

    And replacing x with something like "value" would hurt nothing and make the code even more super-obvious.

    But then you would have to type 8 extra characters!!!

  • Capt. Obvious (unregistered) in reply to Sven
    Sven:
    That Troper:
    setShuffle (bool x) { shuffle = x; cout << "Shuffle was set" << endl; }
    And replacing x with something like "value" would hurt nothing and make the code even more super-obvious.

    A good coding standard would have a way of naming a temporary variable. Mine says that "in the case of only one variable of that type, just the [Apps] Hungarian wart is acceptable". Others I've seen specify ndx, ndy, etc. and still others Temp1, Temp2.

    Value is a perfectly acceptable usage, but it's hard to see how that adds anything.

  • Kermos (cs) in reply to Capt. Obvious
    Capt. Obvious:
    Fubar:
    Hey, I'm an embedded coder... and pound me before I got the words 'single letter variables' out my mouth.

    That's because you're using compiled source code. Variable name length doesn't matter (up to a limit imposed by the compiler... 32 chars for C?). But for an interperted runtime, single-letter variables are faster*. And whitespace, indentation and whatnot, is just extra characters that have to be processed*.

    If you grew up watching clock cycles, you too would know this.

    *Sure, the amount of saved time will be next to negligable, or the code can be compiled to an optimized/obfuscated form while keeping a modifiable version somewhere else. But why not get right in there with the 1s and 0s.

    Wouldn't any reasonable runtime interpreter, regardless of whatever language, be written intelligent enough to keep a cache of the code it has previously executed to avoid reparsing the source file?

  • Harold (unregistered) in reply to Kermos

    [quote user="Kermos"][quote user="Capt. Obvious"][quote user="Fubar"]Hey, I'm an embedded coder... and pound me before I got the words 'single letter variables' out my mouth.[/quote]

    ...

    Wouldn't any reasonable runtime interpreter, regardless of whatever language, be written intelligent enough to keep a cache of the code it has previously executed to avoid reparsing the source file?

    [/quote]

    Absolutely not. Code I am looking at has a major performacne problem because it does not have nay such optimization. "hardware is cheap"

  • Omroth (unregistered)

    The interpreted language I use has a stringtable for almost everything... so length of variable names doesn't matter. I don't think.

  • Anon (unregistered) in reply to Kermos
    Kermos:
    Is there no justice in this world?

    No. Justice belongs in a "theoretical course on the computer science" and has "no application in the real world".

  • Jay (unregistered)

    I once worked on a system where all the integers were named n1, n2, n3, etc, and all the strings were s1, s2, etc. I spent hours figuring out what variables really held. Finally I realized that the smart thing to do was, each time I opened a new module, spend a couple of hours figuring out what the variables really were and do a search-and-replace to change the names to something meaningful. Except ... I quickly discovered that while at the top of the program s1 might be the customer name, later on s1 might be used for the product description. Apparently the original author thought it would be a waste of memory to create a new variable when he had this one sitting around that he wasn't using any more. While renaming the variables could be done with a quick search-and-replace, trying to untangle these re-used variables was a huge job. After all, if I got confused and renamed "s1" to "customername" when it was really the product name, the program would still work. But if I renamed it to "customername" up here and "productname" down there, and got one reference wrong, now it could be broken.

    I still wake up screaming over that one sometimes.

  • #NA (unregistered)

    <00000000cffbe0b0> The text of this comment has been optimized out.

  • AndyL (unregistered)

    In my experience, anyone who is paranoid that you're going to "steal their idea" and go "make a fortune" with it, does not have a single idea worth stealing. Ever.

  • DStaal (unregistered) in reply to Jay

    I had a boss that coded like that.

    The code itself was amazing, and worked really well. He never could understand why I didn't want to mess with it, and left it up to him. (It was his company, founded on the code...)

  • Paul W. Homer (unregistered)

    I've seen way too many startups that precisely match this position. There is a distinction between being able to write some working code and actually being able to build big working systems, that always seems to be missed.

  • tragomaskhalos (unregistered) in reply to Jay
    Jay:
    I once worked on a system where all the integers were named n1, n2, n3, etc, and all the strings were s1, s2, etc. I spent hours figuring out what variables really held. Finally I realized that the smart thing to do was, each time I opened a new module, spend a couple of hours figuring out what the variables really were and do a search-and-replace to change the names to something meaningful. Except ... I quickly discovered that while at the top of the program s1 might be the customer name, later on s1 might be used for the product description. Apparently the original author thought it would be a waste of memory to create a new variable when he had this one sitting around that he wasn't using any more. While renaming the variables could be done with a quick search-and-replace, trying to untangle these re-used variables was a huge job. After all, if I got confused and renamed "s1" to "customername" when it was really the product name, the program would still work. But if I renamed it to "customername" up here and "productname" down there, and got one reference wrong, now it could be broken.

    I still wake up screaming over that one sometimes.

    This reminds me of the "eliminate all local variables and instead use member variables (usually called "m_temp1" etc)" antipattern. Funnily enough, also usually defended by the clueless author as being "more efficient".

  • schmitter (unregistered) in reply to Kermos
    Kermos:
    The whole variable naming thing reminds me of this one guy at a company I worked at. He did exceed 1 letters in his names, usually but this names were still not any more useful.

    Generally, they looked like this:

    button1 button2 button3 button4 ... button20 (no, I'm not kidding).

    That is assuming they were even spelled correctly in the first place. Really a pain to work with someone's code when they can't even spell the word 'minimum' right and have several variables with varying spellings throughout their code.

    Luckily he was eventually let go and I replaced him and completely replaced all his code with non-WTF code.

    Sadly, he thanked me later as because of this he got hired somewhere else at twice my salary. Is there no justice in this world?

    No.

  • CSK (unregistered)

    I use i,j and k for loop counters (integers only and always in local scope to the current method) but I'll admit that I'm a bit of a neophyte in regards to working on team projects. I have to ask, is that going to land me on this site one of these days?

  • A Gould (unregistered) in reply to Capt. Obvious
    Capt. Obvious:
    Value is a perfectly acceptable usage, but it's hard to see how that adds anything.

    Well, obviously it adds VALUE!

  • Alin (unregistered)

    $W-$T-$F

  • Madox (unregistered) in reply to Kermos
    Kermos:
    The whole variable naming thing reminds me of this one guy at a company I worked at. He did exceed 1 letters in his names, usually but this names were still not any more useful.

    Generally, they looked like this:

    button1 button2 button3 button4 ... button20 (no, I'm not kidding).

    And is this coder's name "Visual Basic"?

  • ObiWayneKenobi (cs)

    The most disheartening thing about this, and all the stories like it, is that the company remains in business. Seriously - I want all these lame-ass, shit companies run by clueless CEOs and owners who want to pretend that they're a business owner to just go away. It's a travesty that all these shitty businesses who cut corners every which way on everything and anything imaginable still manage to flounder around in the business world, or sometimes even turn a profit, instead of just closing up.

    Also, at my current job I have to maintain a cesspit of spaghetti Classic ASP where all of the recordset objects are named some variation on "rsTemp" (e.g. rstmp, rstemp2, restemp3, stmp, rtmp) and sometimes get reused immediately following a database call.

  • SCB (unregistered) in reply to Jay
    Jay:
    I once worked on a system where all the integers were named n1, n2, n3, etc, and all the strings were s1, s2, etc. I spent hours figuring out what variables really held. Finally I realized that the smart thing to do was, each time I opened a new module, spend a couple of hours figuring out what the variables really were and do a search-and-replace to change the names to something meaningful. Except ... I quickly discovered that while at the top of the program s1 might be the customer name, later on s1 might be used for the product description. Apparently the original author thought it would be a waste of memory to create a new variable when he had this one sitting around that he wasn't using any more. While renaming the variables could be done with a quick search-and-replace, trying to untangle these re-used variables was a huge job. After all, if I got confused and renamed "s1" to "customername" when it was really the product name, the program would still work. But if I renamed it to "customername" up here and "productname" down there, and got one reference wrong, now it could be broken.

    I still wake up screaming over that one sometimes.

    You could have gone with "customerorproductname"

  • Madox (unregistered) in reply to AndyL
    AndyL:
    In my experience, anyone who is paranoid that you're going to "steal their idea" and go "make a fortune" with it, does not have a single idea worth stealing. Ever.

    One thing that successful entrepreneurs realize that most idiots don't is that business ideas are cheap; it's all in the execution. So some nut might think "If anyone finds out, they'll get rich off my idea". But of course there's a whole lot of question marks between 'idea' and 'profit'.

    How idiots view reality

    1. Idea
    2. A little bit of work
    3. Guaranteed Profit

    Reality

    1. Idea
    2. Insane amount of hard work. Dedication. Risk taking.
    3. Possible profit. Or lose everything in the process.

    Captcha: distineo - It's not about the distineo, it's about the journey.

  • Leak (cs) in reply to Omroth
    Omroth:
    I don't think.
    Still - you might want to try it once in a while. It's really useful sometimes... *g,d&r*

    np: Warren Suicide - Picnic On A Minefield (Strike 100 (Disc 1))

  • zoips (unregistered) in reply to Harold
    Harold:
    Kermos:

    Wouldn't any reasonable runtime interpreter, regardless of whatever language, be written intelligent enough to keep a cache of the code it has previously executed to avoid reparsing the source file?

    Absolutely not. Code I am looking at has a major performacne problem because it does not have nay such optimization. "hardware is cheap"

    I'm pretty sure that fails the "reasonable runtime interpreter" test, which makes whatever WTF you are working with irrelevant. The least reasonable would be to parse the source to build an AST and execute from that, eg old Ruby. More reasonable is to compile and interpret bytecode like most scripting languages.

  • Giskard (unregistered) in reply to tragomaskhalos
    tragomaskhalos:
    Jay:
    ...
    This reminds me of the "eliminate all local variables and instead use member variables (usually called "m_temp1" etc)" antipattern. Funnily enough, also usually defended by the clueless author as being "more efficient".

    To be fair... I've actually done that once. But it was for a simulator project written in Java that would throw away a handful of objects per simulation step (a fractional millisecond of sim time). After a bit the garbage collector would be invoked nearly constantly to try and clean up all the temporary objects been created and destroyed by the simulator and it would slow down to less than real time.

    Re-wrote all the classes I used to work with member variables and fixed sets of classes and prevented the gc from being invoked and it was a very noticeable gain.

    That being said... I still wouldn't do that for anything that goes into my daily code.

  • Crash Magnet (unregistered) in reply to CSK
    CSK:
    I use i,j and k for loop counters (integers only and always in local scope to the current method) but I'll admit that I'm a bit of a neophyte in regards to working on team projects. I have to ask, is that going to land me on this site one of these days?

    It just did.

    But I do the same thing.

  • Kermos (cs) in reply to Madox
    Madox:
    Kermos:
    The whole variable naming thing reminds me of this one guy at a company I worked at. He did exceed 1 letters in his names, usually but this names were still not any more useful.

    Generally, they looked like this:

    button1 button2 button3 button4 ... button20 (no, I'm not kidding).

    And is this coder's name "Visual Basic"?

    Actually his name was MFC.

  • Booboo (unregistered) in reply to AndyL
    AndyL:
    In my experience, anyone who is paranoid that you're going to "steal their idea" and go "make a fortune" with it, does not have a single idea worth stealing. Ever.
    Firstly, it wasn't their idea that could have been stolen, it was the source code of their software... which could have been pinched if it was any good.

    Secondly, I love how the ones scared of having their code stolen were the ones who stole someone else's forum software in the first place.

  • Dennis (unregistered) in reply to SCB
    SCB:
    Jay:
    I once worked on a system where all the integers were named n1, n2, n3, etc, and all the strings were s1, s2, etc. I spent hours figuring out what variables really held. Finally I realized that the smart thing to do was, each time I opened a new module, spend a couple of hours figuring out what the variables really were and do a search-and-replace to change the names to something meaningful. Except ... I quickly discovered that while at the top of the program s1 might be the customer name, later on s1 might be used for the product description. Apparently the original author thought it would be a waste of memory to create a new variable when he had this one sitting around that he wasn't using any more. While renaming the variables could be done with a quick search-and-replace, trying to untangle these re-used variables was a huge job. After all, if I got confused and renamed "s1" to "customername" when it was really the product name, the program would still work. But if I renamed it to "customername" up here and "productname" down there, and got one reference wrong, now it could be broken.

    I still wake up screaming over that one sometimes.

    You could have gone with "customerorproductname"

    "customerandorproductname" more completely captures the uncertainty.
  • Dragnslcr (cs) in reply to CSK
    CSK:
    I use i,j and k for loop counters (integers only and always in local scope to the current method) but I'll admit that I'm a bit of a neophyte in regards to working on team projects. I have to ask, is that going to land me on this site one of these days?

    I doubt it. Using those single letters for loop counters is generally considered acceptable practice. The reason that it's acceptable is that loop counters usually don't have any real meaning beyond an array index. A lot of the time, you're probably only using the counter variable once or twice the loop, such as having value = values[i]; at the beginning of the loop and assigning a modified value back to the array. If the loop counter has a more significant meaning than being just an array index, you should probably give it a more significant name.

  • Damian (unregistered)

    I worked with a guy that used those type of variable. We are using java and every variable is one and two letters. 20,000 line of source code in hundreds of classes all with variables like sp, ss, cc, em... and he would use the same ones in every file he wrote

    Plus he pretty much used java as a functional language instead of objects.

  • Booboo (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    The most disheartening thing about this, and all the stories like it, is that the company remains in business. Seriously - I want all these lame-ass, shit companies run by clueless CEOs and owners who want to pretend that they're a business owner to just go away. It's a travesty that all these shitty businesses who cut corners every which way on everything and anything imaginable still manage to flounder around in the business world, or sometimes even turn a profit, instead of just closing up.
    Yeah whatever. Because the code is absolutely the most important part of any business. Nevermind attracting investment and customers and providing an application which works well enough, the absolute most important thing is having really well indented code. Users really appreciate waiting extra months for that kind of thing.
  • Franz Kafka (unregistered) in reply to Booboo
    Booboo:
    ObiWayneKenobi:
    The most disheartening thing about this, and all the stories like it, is that the company remains in business. Seriously - I want all these lame-ass, shit companies run by clueless CEOs and owners who want to pretend that they're a business owner to just go away. It's a travesty that all these shitty businesses who cut corners every which way on everything and anything imaginable still manage to flounder around in the business world, or sometimes even turn a profit, instead of just closing up.
    Yeah whatever. Because the code is absolutely the most important part of any business. Nevermind attracting investment and customers and providing an application which works well enough, the absolute most important thing is having really well indented code. Users really appreciate waiting extra months for that kind of thing.

    If you've noticed, the company doesn't make a profit, has an awful codebase that frustrates new features, and the CEO is clueless. They shouldn't be in business.

  • Code Dependent (cs) in reply to Harold
    Harold:
    ...has a major performacne problem...
    Performacne (n): skin blemishes produced as a result of stage fright.
  • Code Dependent (cs) in reply to Jay
    Jay:
    I quickly discovered that while at the top of the program s1 might be the customer name, later on s1 might be used for the product description. Apparently the original author thought it would be a waste of memory to create a new variable when he had this one sitting around that he wasn't using any more.
    How very COBOL of him.
  • sameasiteverwas (unregistered)
    Comment held for moderation.
  • Capt. Obvious (unregistered) in reply to Code Dependent
    Code Dependent:
    Jay:
    Apparently the original author thought it would be a waste of memory to create a new variable when he had this one sitting around that he wasn't using any more.
    How very COBOL of him.
    I've reused variables to prevent GC in high-level languages. The object creation/deletion was a measurable bottleneck, and it had to be done to make the program run quickly enough.

    Now, I named the variables in ways that indicated what was being done, and commented their usage well. Ex:

    ExpensiveObject* pLocalObject = g_pPermenantObject;  // Local object actually points to a permenant object.  This is necessary to prevent object creation/deletion from becoming a performance bottleneck. 
    pLocalObject->Reset();  // Reset the global object's state to that of a new ExpensiveObject. 
    
    //Do Stuff
    
    pLocalObject = NULL;  // Local object actually points to a permenant object.  This is necessary to prevent object creation/deletion from becoming a performance bottleneck.  As such, the "local object" should not be deleted, and, since it is no longer being used, is set to NULL to prevent accidental reuse/misuse/deletion later on.
    
  • mbv (unregistered) in reply to Damian
    Damian:
    I worked with a guy that used those type of variable. We are using java and every variable is one and two letters. 20,000 line of source code in hundreds of classes all with variables like sp, ss, cc, em... and he would use the same ones in every file he wrote

    Plus he pretty much used java as a functional language instead of objects.

    I'd love to see how he does that. As far as I know you need different languages to use functional, although someone made a functional language that compiles into java class files.

    I assume you meant procedural language?

  • jojo (unregistered) in reply to Franz Kafka
    Franz Kafka:
    If you've noticed, the company doesn't make a profit, has an awful codebase that frustrates new features, and the CEO is clueless. They shouldn't be in business.

    Maybe he's not as clueless as he seems if he's able to keep his company in business despite all that...

  • Andrés Medina (unregistered) in reply to Joseph

    lol, the "tchbo" comment was a perfect example about why naming variables that way is not good.

  • ObiWayneKenobi (cs) in reply to jojo
    jojo:
    Franz Kafka:
    If you've noticed, the company doesn't make a profit, has an awful codebase that frustrates new features, and the CEO is clueless. They shouldn't be in business.

    Maybe he's not as clueless as he seems if he's able to keep his company in business despite all that...

    No, I'm sure he is. Remember all it takes to run a business is money to keep pumping into it; you don't have to actually know jack shit about what you're doing.

    I'm sure this "CEO" just has a lot of money and figures that his idea is great and that because he's John Smith he deserves to make millions, and rather than admit defeat continues to pump money into a losing business. You'd be surprised at how many businesses seem to run under that model; the owner is too egotistical to be anything other than a business owner even though they don't understand anything, and gleefully pump money into the business so they can stay "the boss".

    Code isn't the most important thing, but there is NEVER any benefit in rushing out garbage and cutting corners when software is the very lifeblood of your company. That's just asking for trouble, and if you're idiotic enough to think that you can do things better/quicker by avoiding paying for quality, then you don't deserve to be in business.

  • wee (cs) in reply to Jay
    Jay:
    I quickly discovered that while at the top of the program s1 might be the customer name, later on s1 might be used for the product description.

    Holy jumping jebus that is a colossal WTF. Globals are bad enough, but re-using them? Add to that the entire program was in one file, and... just wow.

    I feel your pain, man, but never want to really experience it.

  • Dazed (unregistered) in reply to Dennis
    Dennis:
    SCB:
    Jay:
    Except ... I quickly discovered that while at the top of the program s1 might be the customer name, later on s1 might be used for the product description.

    I still wake up screaming over that one sometimes.

    You could have gone with "customerorproductname"

    "customerandorproductname" more completely captures the uncertainty.
    Or use the Java convention: customerNameAtTheTopOfTheCodeAndProductNameFurtherDown
  • Cooksey (unregistered)

    This is exemplary of how to optimize your way out of profitibility.

    Efficient code is easy to maintain and runs fast enough to not sandbag the host machine.

    If the code takes hours just to devine its actions then the project has been sabotaged by bad programmers and poor management of the bad programmers.

    When you directly reap the benefit of your developmental and maintenance efforts you quickly cop to a 20%+ comment metric and meaningful variable names (and I dont mean lpdw!).

    If the code is difficult to maintain then you lose profit which to me has always been the point of the game.

    Of course assembler programmers always have a certain level of disdain for writers of high level languages where you get to say something more expressive then MZE.

    Oh well. NOP.

Leave a comment on “Rise of the Optimizers”

Log In or post as a guest

Replying to comment #:

« Return to Article