As I wander free upon the large fields of code in this world I sometimes come upon interesting things. The wonder, the joy, the mysteries that I encounter I must share with all of you, otherwise it would be selfish of me.
I will, therefore, start a series (it surely will be a series) of such posts called “The monthly WTF”.
Today I present you :
private static void CanWhatever(object sender, CanExecuteRoutedEventArgs e) { if (SomeString.IsNotNullOrEmpty()) { if (Repo.AllowSingleSignOn) { e.CanExecute = false; } } e.CanExecute = true; }
Notice anything special?
Not really. I would have extracted SomeString in a local variable and CanExecute is probably true so you don’t need to set it, but other than that (and maybe some business logic I didn’t understand) this seems ok. What am I missing?
Whouldn’t this method allways set e.CanExecute = true; regardless of the chained “if” blocks?
Well I guess Alex nailed it. The original intent was to set CanExecute to false if SomeString are null (or empty) and single sign-on is allowed.
But in the actual form the CanExecute property will ALWAYS be set to true regardless of the fact that it might have been set to false a few lines of code above.
You… geniuses 🙂
Doh! No return statement. I am blind.
See also …( and make same mistake in good old VB6 times…)
🙂
private string codFunctie;
public String CodFunctie
{
get { return codFunctie; }
set
{
if (codFunctie != value) { codFunctie = value; }
}
}
this being an ‘WTF’ that you encountered? 😕
yep, today I had to review some bug in the code left behind from some colleague. needless to say that all properties are like that.
Post more “goodies” if you can! 😀
I think he couldn’t figure why this code was not working. It’s a simple js file “SaveData.js” that holds the following lines:
function AskToSaveData(mesaj) {
// alert (document .getElementById ("ctl00_ContentPlaceHolder1_HD_IsDataToSave").value) = true;
if (document.getElementById("").value == "true") {
doSave();
}
}
and of course the aspx page 🙂
<%----%>
function AskToSaveData(mesaj) {
// alert (document .getElementById ("ctl00_ContentPlaceHolder1_HD_IsDataToSave").value) = true;
if (document.getElementById("").value == "true") {
doSave();
}
}
Maybe someone told him that it’s best practice to keep all you js outside the code. But never told him how 🙂
your blog is breaking the code that I wrote!
Sorry about that, it’s just the default WordPress settings..
and the winner is:
switch (this.toBeDeleted)
{
case true:
//ta.Delete(this.Id);
//TODO DELETE EXTENDED PROPERTIES
break;
default:
observatii.IDObject = this.IDActivitate;
observatii.Save();
// (and other not posted code)
}
I give you the money to buy yourself a gun. You should defend yourself against these monsters.
Strofo, I feel your pain.. 😯