Thread: Thought of the Day

  1. #1
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446

    Thought of the Day

    The best time to start optimizing your code is when you no longer plan to use it.

    Make no mistake. And I'm getting ready for a very harsh week because of that. There's really no level of optimization that we should apply beyond that which we do at the Design phase. After that, upgrading processors or increasing RAM will always become a cheaper alternatives to compromising your code maintainability. Don't do it. Remember, code maintainability is your only goal in computer programming. It's the only thing that makes it possible for you to code for reusability, or scalability, or easy of use, or whatever else are your requirements at the time.

    If this bothers you... next time, Design better.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    That works only if you consider algorithms with the wrong complexity to be bugs. You can't upgrade computers enough to make up for a quadratic algorithm where something better is possible. If the data grows, it won't scale.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I don't. On the other hand I probably would... if I was in the presence of a quadratic algorithm that could have been instead a linear or logarithmic one. Hard not to see a bug in that when, as you say, the algorithm needs to scale well.

    In any case, fixing mistakes or bugs is not what I had in mind.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I've wondered whether your quotation of me in your sig was meant to be sarcastic. I think the answer is pretty clear now
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Hehe. Nice way to put me against the wall. But I can assure you I'm not all about hiding deficiencies with processor power and memory. Just some.

    To be clear, the real problem comes when one starts to try to outsmart themselves and think that by optimizing stuff that affects early design decisions, they can predict the outcome of those changes better than when they were dedicating all their brain cells to the design of their system. Sometimes -- as was the case -- all for a mere milliseconds gain (**), one ends up sacrificing not only things like memory or bandwidth (that may or may not be important), but also a lot of their time either fixing early design decisions to come to grips with the new code, or the new code maintainability issues that were just created. I think this is a mistake once your project enters production. No optimization of this magnitude is worth that work and the risks that may come with it.

    In contrast, optimizing a large system purely for performance reasons by actually implementing it in another language is, for the lack of a better word, insane. I like that quote because a) it should give people (particularly the eager and energetic, and thus deluded) pause to think more carefully about their preconceptions, and b) it is actually how it works in the world out there. Say my bank Cobol subsystems.

    (**) it's more like a bit over half a second that was gained.
    Last edited by Mario F.; 06-09-2011 at 06:09 PM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Here's some food for thought, without qualification: I just was at BoostCon, where I talked to someone about software optimization vs machine upgrade. He gave me some interesting numbers about the costs of data centers (computer power and AC power, space rent, technician wages, ...). The bottom line was that making the program 5% faster could save thousands of pounds per year.
    It's easy to overlook some of the costs of additional hardware.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Also consider how many instances of "the hardware" there are.

    If you're doing bespoke software in-house for example, then your time is valuable. Spending money on the best hardware makes sense if you can be working on something far more critical (that can't be solved just by getting faster hardware).

    But if you're writing s/w for mass consumer electronics (say a phone), then if the company can choose a $1 component as opposed to a $2 component, for the want of a bit of programming effort (and still sell the result at the same price), then that's a cool $1M in the bank. The company can afford you to spend quite a bit of time on this, and still be sitting pretty.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Yup. I can no doubt agree hardware and hardware related costs should factor in. I wouldn't think being stubborn about code if the consequence involved upgrading a whole data center. That's a prime example where code exerts the most influence at the least cost. And thinking about mass consumer electronics, I can also also see the advantages here of leveraging your performance through code.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  9. #9
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    CornedBee's and Salem's comments are on the mark. I should point out that my comment (as seen in Mario's signature) was specifically said in response to someone who was proposing to reimplement a rather large piece of software from the ground up, in a different language, to achieve some speculative performance increase. Software which is deployed externally has a very different set of conditions.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  10. #10
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    I wasn't speaking of data center software or telecommunications software, or any mission/performance critical software for that matter. Maybe I made it look like I was?

    I don't develop for those areas. But anyways... if the necessary disclaimers about performance critical systems needed to be made, they have been made. (Good grief!)

    Edit:
    - The sky is blue!
    - Well no. It isn't at night.
    - Right.... (smartass)
    - What did you say?
    - Let's dance
    Last edited by Mario F.; 06-10-2011 at 10:32 AM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thought I would never say this...
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 41
    Last Post: 07-22-2008, 03:57 PM
  2. And here I thought it was just a joke...
    By 7smurfs in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-03-2006, 02:09 PM
  3. just a thought...
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 66
    Last Post: 05-25-2003, 07:46 PM
  4. Just thought of something
    By golfinguy4 in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 10-23-2002, 02:12 PM
  5. Interesting Thought....
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-02-2001, 06:44 PM