Funny little code optimisation

I'm in the middle of reviewing a developers code. This amused me…

Code

      var url='';      if(document.getElementById('file'+number))      {         url=document.getElementById('file'+number).value;      }      else      {         if (filename!='')         {            url=filename;         }      }

because it is exactly equivalent in behaviour to…

Code

      var url=filename;     [...]

If you find this interesting or useful please share this content:
  • Twitter
  • Facebook
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks

I'm in the middle of reviewing a developers code. This amused me…

Code


      var url='';
      if(document.getElementById('file'+number))
      {
         url=document.getElementById('file'+number).value;
      }
      else
      {
         if (filename!='')
         {
            url=filename;
         }
      }

because it is exactly equivalent in behaviour to…

Code


      var url=filename;
      if(document.getElementById('file'+number))
      {
         url=document.getElementById('file'+number).value;
      }

I saw this straight away, and then I thought "hey, that's actually quite a complex optimisation". Are any programmers reading? I'd be interested if this is the kind of thing other people notice, or am I just fussier about things?

pixelstats trackingpixel
If you find this interesting or useful please share this content:
  • Twitter
  • Facebook
  • Digg
  • Sphinn
  • del.icio.us
  • Mixx
  • Google Bookmarks

Related Posts


Fatal error: Call to undefined function yarpp_sql() in /home/hosting/public_html/wp-content/themes/convergence/single.php on line 56