How to concatenate a number to a string.
-
Here's some Javascript. Definitely unconscious coding.
eval( "someFuncFromOurLib('a_dynamically_numbered_title_"+ number +"')" );
On various occasions I've straightened out interns and fulltime codemonkeys producing this drivel, but something always slips through.
-
What, only one layer of eval?
-
Heh heh. I happened to meet a guy who thought he knew a more clever way to do this -- in C. See here: http://forums.thedailywtf.com/forums/t/8878.aspx
-
@dhromed said:
Here's some Javascript. Definitely unconscious coding.
eval( "someFuncFromOurLib('a_dynamically_numbered_title_"+ number +"')" );
On various occasions I've straightened out interns and fulltime codemonkeys producing this drivel, but something always slips through.
Geez... if not for the single quotes (i.e. if they needed to pass in a variable called a_dynamically_numbered_title_number rather than a string with that value) , this would be almost forgivable (still wrong, and any design that would require that is a WTF, but understandable). I have to wonder though wtf they were thinking in this case.
-
A rule of thumb for novice programmers:
Never use eval.
-
@merreborn said:
A rule of thumb for novice programmers:
Never use eval.
Or, as Google programmers always say, ...
Do no eval.
-
@D0R said:
Heh heh. I happened to meet a guy who thought he knew a more clever way to do this -- in C. See here: http://forums.thedailywtf.com/forums/t/8878.aspx
As hard as it is to believe, that link actually works if you remove the trailing space.
-
My apologies. Here's the correct link: http://forums.thedailywtf.com/forums/t/8878.aspx
-
@merreborn said:
Or new Function("string containing source code") - or setTimeout("string containing source code",time) - in fact, literally everything you can do that involves a string containing source code has the same problems as eval.A rule of thumb for novice programmers:
Never use eval.