• (cs) 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"

    I once worked with a guy who randomly renamed variables with direction indicators (left, right, up, down, in, out, ...) I spent more time undoing his damage than doing my own work.
  • Dr. Evil (unregistered) in reply to Capt. Obvious
    Capt. Obvious:
    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.

    It adds value, by definition.

  • Jeremy Friesner (unregistered) in reply to Booboo

    First off, indenting code properly takes seconds, not months. You can even have it done for you automatically by your dev tools, if you like.

    Secondly, "that kind of thing" is what keeps the code maintainable, and if you fail to do it, you'll eventually end up with a mess that you no longer understand, and your customers will "really appreciate waiting extra months" for new releases of your program, since you'll be spending weeks and weeks debugging obscure problems that would have been obvious if your codebase was readable.

  • (cs) in reply to mbv
    mbv:
    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?

    No, you can code in a functional Style in Java. Just imagine

    interface Lambda
    {
        public Object function(Object params);
    }

    You are welcome to define more interfaces for more parameters. There might be a C#

    params
    equivalent in Java so use that.

    Keep imagining

    public static void main(String[] args)
    {
        // create function here
        Lambda l = new Lambda()
        {
            public Object function(Object params)
            {
                System.out.println("Hello World");
                return null;
            }
        }
        // call functional function here
        l.function(null);
    }

    You could even pass the functional function to another method that takes a parameter of type Lambda.

    In reality this was necessary for AWTs events.

  • iToad (unregistered) in reply to ObiWayneKenobi
    ObiWayneKenobi:
    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.

    We take the graded approach to software quality assurance. This approach determines how critical the application is, based on the consequences of failure. Software is graded into one of four levels, and the quality gets a lot stricter as the grades go up. The levels are:

    Level 1 - Not critical. Who cares if it fails?

    Level 2 - Business critical. If the application fails, you're going to stop doing business.

    Level 3 - Health/Safety critical. If the application fails, you're going to allow something genuinely dangerous to happen.

    Level 4 - Life critical. If the application fails, one or more people die.

    As others have stated, professionals should not develop Level 2 business-critical applications to Level 1 standards.

  • (cs) 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.
    I'd rename it "Enable". That makes it painfully obvious when you're looking at just the prototype what it does.

  • Smrt (unregistered)

    Too lazy to make sure 15 of you hven't said this yet....

    The REAL WTF is that the "...CEO finally conceded..." (sic)

  • One Guy (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?

    It was music software, and it's spelt 'minim'

    (Actually, I have found more recently (for consistency) that it's better to start from Button000, Button001 - I've never exceeded a Thousand yet (Actually, I've never exceeded 100 yet - but it pays to be prepared). Numbering buttons in sequence like this helps when you need to be able to find the most recently added component)

    Thanks Again, though, I wouldn't be where I am if it weren't for you.

  • Smee (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.

    Hahaha

    Search and replace is great, until you realise that when you replaced s1 with FirstName, you created a FirstName0, FirstName1... (from s10, s11 etc). In itself, not so much a problem. Then you need to replace all the answers to expressions (which we cleverly labelled e0, e1, ....).

    So we end up with FirstNamAns, FirstNameVal...etc....

    Search and Replace is your friend, not always....

  • Joops (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.

    Ain't that the truth - most people who do have code worth stealing are arrogant enough to think that they'll be able to recognise their own ideas no matter how much you morph them. (Often they're right, actually)

  • Luke (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.

    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.

    I think you hit a very good point - people who know nothing technical should not make technical decisions without consulting their technical resources. Catch-Phrase Kings are great at picking the worst product or worst technology for a job.

  • Fel (unregistered) in reply to Franz Kafka
    Franz Kafka:
    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.

    And I didn't realise that it takes months of extra effort to indent code as you go (in fact, I've always found it more time consuming taking the indenting that my IDE puts in back out of the code).

  • (cs) in reply to tragomaskhalos
    tragomaskhalos:
    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".

    I ran into the same thing in the project I'm working on. In code reviewing someone's code I noticed he left a member variable in a different state that it was in before the code change. The author was using the member variable as one of these "temp" variables, so he didn't understand why I was questioning it. After realizing he was using the member variable was a "temp" variable, I asked him why he didn't just use a local. "Oh I didn't want to create a local." Why? Performance wise it is the same thing, as both times he was creating a new list. I don't know exactly how C# works, but I imagine a local isn't much different in C# that in C++, just decrement the stack pointer a bit. The worst part about it is you won't throw away the temporary list. He said "sure the garbage collector will throw it away when you stop using it." Well actually no it won't because you don't really stop using it until the class is destroyed.

  • (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?

    Not necessarily. But a good habit to get into is naming the index, so you know what it indexes. This is more useful with nested loops. Sure, it is obvious what i indexes when you say foobar[i], but is it as obvious when you say value = foobar[i] + foobar[j]/2.

  • Deke (unregistered) in reply to Madox
    Madox:
    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.

    True, but the "insane amount of hard work" is much easier if you start off with someone else's idea and codebase.

  • fry (unregistered) in reply to Madox
    Madox:
    How idiots view reality 1) Idea 2) A little bit of work 3) Guaranteed Profit
    1. Underpants
    2. ??
    3. Profit!
  • Franz Kafka (unregistered) in reply to chrismcb
    chrismcb:
    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?

    Not necessarily. But a good habit to get into is naming the index, so you know what it indexes. This is more useful with nested loops. Sure, it is obvious what i indexes when you say foobar[i], but is it as obvious when you say value = foobar[i] + foobar[j]/2.

    The problem goes away with the for foo in Collection<Foo> - you always have a handle to the current Foo you're messing with

  • Bob (unregistered)

    If you sell people a toaster that sometimes burns the toast, sometimes barely even heats it, and every now and again is moderately acceptable, you'll be out of business in a week, if you're lucky. If you sell some half-baked crappy software that causes your users to feel too stupid to qualify for the special olympics, they'll happily blame themselves and keep throwing money at you.

    These companies will keep limping along until users realise that they're actually not getting the best possible product they'ld get if they were buying from someone with standards.

    Also, on occasion, they're limping along working the typical 16-20 hour days that you get when you start a business, and they never move the company income beyond "just enough to pay the founder's salary" and so they can't hire someone competent, and can't build up from "all the costs of a business and none of the perks of being an employee" up to "actually owning a genuine business." Forget telling them to get out of business - most of these small companies aren't a real businesses to start with.

    How to tell if you own a business or are merely an employee with less job security than a janitor at Enron: go on holiday for six months. If the money keeps coming in, congratulations - you own a business. If you're broke 2 weeks later, you're an employee and your boss is an idiot.

    Strangely, the average "consultant" has a similar scheme: even when they're good at their job, being in the service industry means you get all the costs of "being employed" and don't really have much opportunity to grow your business beyond "providing a service for no more than 168 hours a week", and you won't keep that up for long. If you develop into a company, that means hiring other people to do the employee stuff, so you're not stuck doing the employee stuff yourself and can go on holiday for 6 months.

  • Buzzard (unregistered) in reply to Giskard
    Giskard:
    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.

    Should not have written it in Java in the first place.

  • (cs) in reply to chrismcb
    chrismcb:
    The worst part about it is you won't throw away the temporary list. He said "sure the garbage collector will throw it away when you stop using it." Well actually no it won't because you don't really stop using it until the class is destroyed.
    Doesn't destroying a class require deleting the source code? Or is there a new definition of "class" these days?
  • Chris (unregistered) in reply to Kermos
    Kermos:
    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?

    There are various optimizers/byte-code cachers available for PHP (the language in question). We use eAccelerator on all of our web servers that run PHP. With large frameworks (like ADODB), the difference can be huge (scripts execute 10x faster cached than uncached). It's a pity that it's not built into the open-sources PHP core, but installing the additional module is trivial.

    I am a total speed freak and love to speed up and optimize code any chance I get, but the idea that using shorter variables saves any appreciable amount of machine cycles in an interpreted script is ridiculous. I have severely chided other programmers on my team for using _c, _p, and _f as variable names in complex routines without comments.

    Single-character variables names (and de-facto single character names) suck. :(

  • wolfsnipes (unregistered)

    In school another student was supplied with an Excel spreadsheet demonstrating an computational geometry algorithm to be applied in Java, so he copied and pasted the Excel cell variable names (eg. K2 = (A4*B3)+U25) for an entire application) into his java code. Somewhere he made an error and couldn't figure out why no-one wanted to help him debug his code...

  • Nick (unregistered)

    "after a few weeks happily coding away, the new forum up and running."

    You accidentally a word.

  • (cs) 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

    That's not really bad coding.

    I'd probably use b instead of x.

    And I too put all my single-statement get/set methods on a single line each.

    public void setSpeed(int iSpeed) { Speed = iSpeed; }

    I'd probably also add this to it, if I needed to debug something:

    if(debugmode) System.out.println("New speed set: "+iSpeed);

  • Chewbacca (unregistered) in reply to Smee
    Smee:
    Jay:
    I once worked on a system where all the integers [..HACKSAW MODE...] one sometimes.

    Hahaha

    Search and replace is great, until you realise that when you replaced s1 with FirstName, you created a FirstName0, FirstName1... (from s10, s11 etc). In itself, not so much a problem. Then you need to replace all the answers to expressions (which we cleverly labelled e0, e1, ....).

    So we end up with FirstNamAns, FirstNameVal...etc....

    Search and Replace is your friend, not always....

    s/s1 /FistName / perhaps?? Of course, if there's a lot of "s1=" you also have to do s/s1=/FirstName=/

    Planning a file-wide search-and-replace is half the job ^__^

    captcha: inhibeo Hey!? Are you calling me a tool?!

  • (cs) in reply to chrismcb
    chrismcb:
    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?

    Not necessarily. But a good habit to get into is naming the index, so you know what it indexes. This is more useful with nested loops. Sure, it is obvious what i indexes when you say foobar[i], but is it as obvious when you say value = foobar[i] + foobar[j]/2.

    i,j,k & l are perfect for local functionality, loop counters etc.its like when mathematicians always use p,q,r & s.

  • (cs) in reply to swordfishBob
    swordfishBob:
    chrismcb:
    The worst part about it is you won't throw away the temporary list. He said "sure the garbage collector will throw it away when you stop using it." Well actually no it won't because you don't really stop using it until the class is destroyed.
    Doesn't destroying a class require deleting the source code? Or is there a new definition of "class" these days?
    Thank you o' fountain of pedantry.
  • katastrofa (unregistered)

    My company let some go for (among other things) using variable names like "local1", "local2", etc.

  • chipsambos (unregistered)

    it took a few weeks to install and configure some open source forum software?

  • Georgem (unregistered) in reply to CSK

    I'd say not. Meaningful variable names are A Good Thing, but if a developer can't work out what the variable 'i' does within a loop, he's not worth employing

  • Georgem (unregistered) in reply to One Guy
    One Guy:
    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?

    It was music software, and it's spelt 'minim'

    (Actually, I have found more recently (for consistency) that it's better to start from Button000, Button001 - I've never exceeded a Thousand yet (Actually, I've never exceeded 100 yet - but it pays to be prepared). Numbering buttons in sequence like this helps when you need to be able to find the most recently added component)

    Thanks Again, though, I wouldn't be where I am if it weren't for you.

    Without looking, tell me what minim38 is/does

  • (cs) in reply to Smee
    Smee:
    Search and Replace is your friend, not always....
    Globals like x, i, word (yes, really), and code with no friggin' spaces ! e.g. x=word/i+x;

    That was not a nice experience.

  • Giskard (unregistered) in reply to Buzzard
    Buzzard:
    Giskard:
    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.

    Should not have written it in Java in the first place.

    University project => no choice.

  • Peter (unregistered) in reply to snoofle
    snoofle:
    I once worked with a guy who randomly renamed variables with direction indicators (left, right, up, down, in, out, ...).
    Did he by any chance use variables called "charm" and "strangeness" too?
  • Dan (unregistered)

    I bet these developers wrote all their Word documents in 3pt font because it took less space on the hard drive and therefore loaded faster.

  • (cs) in reply to DOA
    DOA:
    swordfishBob:
    chrismcb:
    The worst part about it is you won't throw away the temporary list. He said "sure the garbage collector will throw it away when you stop using it." Well actually no it won't because you don't really stop using it until the class is destroyed.
    Doesn't destroying a class require deleting the source code? Or is there a new definition of "class" these days?
    Thank you o' fountain of pedantry.
    I'd say that destroying a class just takes blowing up some explosives under the teacher's chair.
  • (cs) in reply to equex
    equex:
    chrismcb:
    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?

    Not necessarily. But a good habit to get into is naming the index, so you know what it indexes. This is more useful with nested loops. Sure, it is obvious what i indexes when you say foobar[i], but is it as obvious when you say value = foobar[i] + foobar[j]/2.

    i,j,k & l are perfect for local functionality, loop counters etc.its like when mathematicians always use p,q,r & s.

    I have stumbled over the global-search-and-replace problem plenty of times to avoid single or double letter variables like the plague. I always use idx and jdx for loop counters. That way I am sure I can find them using my favorite editor's "Find" function.
  • (cs) in reply to Peter
    Peter:
    snoofle:
    I once worked with a guy who randomly renamed variables with direction indicators (left, right, up, down, in, out, ...).
    Did he by any chance use variables called "charm" and "strangeness" too?
    Truly beautiful.
  • josh (unregistered)

    usualy before i wear sunglasses i smoke a bowl pack

  • Herby (unregistered) in reply to equex
    equex:
    chrismcb:
    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?

    Not necessarily. But a good habit to get into is naming the index, so you know what it indexes. This is more useful with nested loops. Sure, it is obvious what i indexes when you say foobar[i], but is it as obvious when you say value = foobar[i] + foobar[j]/2.

    i,j,k & l are perfect for local functionality, loop counters etc.its like when mathematicians always use p,q,r & s.

    You forgot the letters M and N, which when included with the previous (I, J, K, L) are always integers!

    Didn't you study that in your FORTRAN class?

  • Wyrd-Mr.CantTellJokeFromSeriousToday (unregistered) 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.

    I can't tell if you're serious or not. Your footnote seems to negate your main comment. Anyway, yeah, for interpreted code it makes a difference, but don't most interpreters do something akin to just-in-time compilation these days? I mean don't they at least compile to a byte code of sometime?

    If speed is so important that you've gotta use single letter variables and eschew proper indentation, you'd probably be better off working with a compiled language, or possibly even an assembler.

    But I think you knew that already because of the footnote thing. I just can't tell for sure.

    -- Furry cows moo and decompress.

  • Smithwick (unregistered) in reply to Giskard
    Giskard:
    tragomaskhalos:
    ...
    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.

    Can anyone tell me why the following would not be a reasonable solution to your problem?

    public class Emulator {
       BigExpensiveObject reused = new BigExpensiveObject();
    
       public void doSomething() {
          BigExpensiveObject usefullyNamed = reused;
          ...
       }
    }

    In java, I believe the penalty would be a new reference and the obvious gain in readability. Not to mention, the java compiler optimizations might even address the new reference.

  • Rumsfeld (unregistered) in reply to Dennis

    or unknownunknowns

  • Youngling (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.

    I guess that's actually a very good reason to use real names for variables. This swapping re-use of variables could make unforseen bugs.

  • (cs)

    Depending on the original forum software's license, the "optimizers" might have violated it either by selling it commercially or by removing the copyright notices or copy of the license from the code. I certainly wouldn't hesitate to let the original authors know so they could look into it further.

  • GameFreak (unregistered)

    Anybody else remember coding on the Ti-83 where you were forced to use 1 letter variable names?

  • Someone out there (unregistered) in reply to equex
    equex:
    i,j,k & l are perfect for local functionality, loop counters etc.its like when mathematicians always use p,q,r & s.

    Mathematicians do, but then they are in their own world.

    But assume you are in C++, and you iterate over a list of customers. What name should you use for the iterator? i? iter? That's thinking from the implementation up.

    An iterator references one of the customers in the collection (or none). You dereference the iterator to access that customer, so why not use a name like aCustomer or thisCustomer? Much more expressive.

    for (CustomerCollection::iterator thisCustomer...)

    if (thisCustomer->hasNotPaid()) ...

  • (cs)

    DEFINT I-N

  • (cs) in reply to Kermos
    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?

    The question is, how many reasonable runtime interpreters exist? Or, in this particular context, what is the definition of 'reasonable'?

    I've talked with interpreter purists, for example, who claim parsing the code to bytecode (like Commodore BASIC does, for an ancient example) moves the language engine from 'interpreter' part of the way to 'compiler'.

    Admittedly, I'm of the opinion that it moves it from 'mindbogglingly useless' closer to 'potentially worthwhile'.

    That being said, even some tokenizing interpreters don't convert the variables. For example, on the Commodore (VIC-20, 16, 64, Plus 4, 128, possibly the PET), variables were limited to two characters of significance. However, the whole variable name was stored, and it would read through the entire variable name every time it encountered it. (However, it did only compare the first two characters. Any characters beyond that were just scanned for end of identifier so it could find out what came after.)

Leave a comment on “Rise of the Optimizers”

Log In or post as a guest

Replying to comment #265602:

« Return to Article