3 ms·
Show me any tool and I'll show you a horrible use of that tool. That doesn't make the tool horrible. ELSE statements don't kill. Drunk programmers kill. Thi
by edw519 17y ago
Show me any tool and I'll show you a horrible use of that tool. That doesn't make the tool horrible.
ELSE statements don't kill. Drunk programmers kill.
This reminds me of something I once ran into:
Junior Programmer:
if (m==1){Month="January")}
if (m==2){Month="February")}
if (m==3){Month="March")}
if (m==4){Month="April")}
if (m==5){Month="May")}
if (m==6){Month="June")}
if (m==7){Month="July")}
if (m==8){Month="August")}
if (m==9){Month="September")}
if (m==10){Month="October")}
if (m==11){Month="November")}
if (m==12){Month="December")}
Senior Programmer:
switch(m)
{
case 1:
Month = "January"
break;
case 2:
Month = "February"
break;
case 3:
Month = "March"
break;
case 4:
Month = "April"
break;
case 5:
Month = "May"
break;
case 6:
Month = "June"
break;
case 7:
Month = "July"
break;
case 8:
Month = "August"
break;
case 9:
Month = "September"
break;
case 10:
Month = "October"
break;
case 11:
Month = "November"
break;
case 12:
Month = "December"
break;
default:
Month = "unknown"
}
Lazy Programmer:
MonthNames == ["","January","February","March",...]
Month = MonthNames[m]
- kelnos 17y agos/Lazy/Smart/ The code is much more compact and much easier to read. (Of course you'd do bounds checking on 'm' before the assignment, but that's not a huge burden.)