Making sure a value is assigned
-
While modifing some javascript on a page I noticed this:
if(lblMessage.innerHTML == "Select Groups.")
lblMessage.innerHTML = "Select Groups.";
else
lblMessage.innerHTML = "Select Groups.";looking through the checkin history to see if there was a different version I found that it was changed from
if(lblMessage.innerHTML == "Required Field.")
lblMessage.innerHTML = "Required Fields.";
else
lblMessage.innerHTML = "Required Field.";Still didnt make much sense, check if its non plural then make it plural......
-
TRWTF is that you haven't optimized it to
if(true)
lblMessage.innerHTML = "Select Groups.";
elsealert("FILE_NOT_FOUND");
-
While the new one is a no-op and can be safely removed, the old one is not.
If it is pural it makes it not, but if it isn't it makes it plural. It's basically a state switcher that makes no sense, but due to refactoring can now be completly killed and all evidence removed.
-
@mott555 said:
TRWTF is that you haven't optimized it to
if(true)
lblMessage.innerHTML = "Select Groups.";
elsealert("FILE_NOT_FOUND");
var isFalse = true;
if (!isFalse) {}
else {
lblMessage.innerHTML = "Select Groups.";
}
-
In fact, in IE7, having a script that does
foo.innerHTML = foo.innerHTML;
may (if foo is the right div) trigger a relayout and therefore avoid some rendering glitches (like after replacing content of floats or content where floats float around via AJAX).
Of course, TRWTF is IE7 (Even in IE8 with IE7 compatibility mode, the rendering glitches cannot be reproduced.)
-
boolean mostlyTrue = Math.ceil(Math.random()) > 0;
-
@dhromed said:
@mott555 said:
TRWTF is that you haven't optimized it to
if(true)
lblMessage.innerHTML = "Select Groups.";
elsealert("FILE_NOT_FOUND");
var isFalse = true;
if (!isFalse) {}
else {
lblMessage.innerHTML = "Select Groups.";
}You mean:
if(!eval("lblMessage.innerHTML = 'Select Group.';") || eval("lblMessage.innerHTML = 'Select Groups.';")) lblMessage.innerHTML = 'Select Groups.'
-
@snoofle said:
boolean mostlyTrue = Math.ceil(Math.random()) > 0;
That is evil! So wonderfully evil! Throw that deep into some inconspicuous code before you leave...
-
-
@KattMan said:
While the new one is a no-op and can be safely removed, the old one is not.
If it is pural it makes it not, but if it isn't it makes it plural. It's basically a state switcher that makes no sense, but due to refactoring can now be completly killed and all evidence removed.
Are you really sure the "String" data type has only 2 possible values...?
-
@Anonymouse said:
Are you really sure the "String" data type has only 2 possible values...?
Yep - "empty" and "non-empty".
This is an Oracle board for Oracle people. We'll have no NULLS here!