Stupid programming

Just come across a stupid piece of JS program today in some web site:

function preselectSS(what)
{
  if (what == 1) document.getElementById("selSS").selectedIndex = 0;
  else if (what == 2) document.getElementById("selSS").selectedIndex = 1;
  else if (what == 3) document.getElementById("selSS").selectedIndex = 2;
  else document.getElementById("selSS").selectedIndex = 3;
}

Isn’t it a lot nicer to write it as

function preselectSS(what) {
    document.getElementById("selSS").selectedIndex = (what > 0 && what <= 3) ? (what - 1) : 3;
}

The world is full of stupid programmers writing stupid programs.

Advertisements

One thought on “Stupid programming

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s