The monthly WTF : You will execute

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?

Leave a comment ?

16 Comments.

  1. 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?

  2. Whouldn’t this method allways set e.CanExecute = true; regardless of the chained “if” blocks?

  3. 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.

  4. You… geniuses 🙂

  5. Doh! No return statement. I am blind.

  6. See also …( and make same mistake in good old VB6 times…)

  7. 🙂

    private string codFunctie;
    public String CodFunctie
    {
    get { return codFunctie; }
    set
    {
    if (codFunctie != value) { codFunctie = value; }
    }
    }

  8. 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 🙂

  9. 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)
    }

  10. Strofo, I feel your pain.. 😯

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.