• Alex Papadimoulis (unregistered)

    Now that I look at it a bit further, this presents a bit of a logical quandry. You see, a lack of a statement would really be doing nothing. But by having a function that effectively does nothing, you actually are doing something ... even though it's nothing at all .... hmm ... whoa ... that's deep.

  • Derick Bailey (unregistered)

    Now the real question, Alex, is whether or not the C# compiler will recognize this as being empty, and simply remove it from the IL, thereby making it actually do nothing.

    On another note - i actually use this technique in javascript calls... i often find that "downlevel" and "alternate" browsers don't like it when when they have an A Href that points to "", so i'll create a simple javascript function exactly like this, to make sure my code works in all browsers.

  • Jeremy Davis (unregistered)

    I'm also impressed at the individual call to Validator3.Validate() right before Page.Validate(). Assuming he's done the Usual Thing(tm) with his validators, that's an even bigger waste of time than doing nothing.

  • Barry Etter (unregistered)

    In Oracle's PL/SQL language, you MUST have code in a BEGIN-END block or it won't compile, so you have to tell it to "NULL", even though NULL is more like a noun than a verb:

    BEGIN
    NULL;
    END;

  • The Langer (unregistered)

    Shouldnt DoNothing() be a public static function so that he can Do Nothing from anywhere?

    This way he will need to implement Do Nothing in every class that he wants to Do Nothing in...

    I guess he was afraid of getting into thread synchronization issues.

  • vbNullString (unregistered)

    That's a little better than...

    If SomeBoolean Then
    ' Do Nothing
    Else
    DoSomething()
    End If

    Hmm... Maybe not.

  • my name (unregistered)

    I saw that in some code yesterday, except the guy was trying to be funny.

    If Foo Then
    'Do Nuthin
    Else
    DoSomething()
    End If

    End Pain and Suffering?
    No.

  • Joseph Anderson (unregistered)

    Just for the record, I should state that this wasn't my code - just a gem from a coworker.

  • AndrewSeven (unregistered)

    It should be static ans accept a parameter of type Nobody.
    This would all it to do nothing with nobody all alone by itself.

    It reminds me of a book I had as a kid, Robert Paul Smith's "How to do nothing with nobody, all alone by yourself"

  • AndrewSeven (unregistered)

    typos... and accept; would allow it

  • Pietje Puk (unregistered)

    I suppose he deserves a little time Doing Nothing after all those superfluous Validates()

  • Tim Cartwright (unregistered)

    Hmmmm, I like two other facts beyond the DoNothing...

    1) He isn't short circuiting his if statement. Nothing like optimizing those
    boolean operations......

    2) He's comparing the text length to an empty string. Someone, correct me if I'm
    wrong, but even in C# it is still more efficient to look at the length and
    compare it to 0? Guess it depends on how C# stores strings in mem.

  • Tim Cartwright (unregistered)

    One more thing that disturbs me is that this is ASP.Net, and he is using the TextChanged event on a text box!!! That is truly disturbing... I LOVE a postback for every single keystroke......

  • Alex Papadimoulis (unregistered)

    Tim,

    Actually, a postback is triggered when the "onChange" event fires on the INPUT. This occurs when focus is lost AND the text has changed. Plus, this only happens if AutoPostBack is set to True.

  • Tim Cartwright (unregistered)

    Thanks Alex for pointing that out, I made an assumption, something I normally
    never do when it comes to developing, that the text change was similar to the
    winforms change event... Make sense that it is not. :-)

  • Wim Hollebrandse (unregistered)

    Err...and isn't he using a bitwise (&) AND operator instead of a logical (&&) one!?

  • No One Special (unregistered)

    Good catch Wim!

  • Warp (unregistered)

    What do you mean DoNothing()? The function is named wrongly. Of course it does something: It allows itself to be called! That's a whole lot! There are certainly things which do a lot less than that!

  • Wessel (unregistered)

    Maybe the donothing() is for setting a breakpoint or something?

  • TK (unregistered)

    If I found a function like that I would make it do something, while keeping the name of course. Free up memory or something else that will cause weird bugs if it's not done.

  • meh (unregistered)

    Two uses for a DoNothing() function:

    1. Some plugin loaded at runtime is given a function pointer to call. There are cases where you want it not to do anything, but it will call the pointer you give it no matter what. Thus, pass it DoNothing(). This might be done when changing an API.

    2. You have an address and you want to know roughly which function it's in. You keep an array of the pointers to every function, and check if this address is between any two. You need a dummy function at the end, to be the last function, so that you can tell if it's in the second-last.

    In this context though, it's a complete WTF. Also, "pointer" as a captcha, how appropriate.

  • (cs)

    Isn't a NULL function pointer a better idea then?

  • Spaghetti-code Greg (unregistered)

    All those Validate() methods ... I feel validated.

  • 3.14159 (unregistered)

    Maybe they were trying to do something like Python's "pass" statement.

  • Someone out there (unregistered) in reply to meh

    Two reasons for a DoNothing():

    Code Review Rule #1: You absolutely, totally must, with no exceptions and recourse to management, under pain of getting retroactively fired on the spot, write an Else clause in each, every and all If statement.

    Code Review Rule #2: You absolutely, totally must, with no exceptions and recourse to management, under pain of getting retroactively fired on the spot, write at least one statement in each, every and all Then, Else, While, Repeat, Loop, Case, Switch, Function, Catch, Begin, ...

    (Given the quality of coding rules out there, this explanation is as likely as any other.)

  • cbhacking (unregistered) in reply to Someone out there
    Someone out there:
    Two reasons for a DoNothing():

    Code Review Rule #1: You absolutely, totally must, with no exceptions and recourse to management, under pain of getting retroactively fired on the spot, write an Else clause in each, every and all If statement.

    Code Review Rule #2: You absolutely, totally must, with no exceptions and recourse to management, under pain of getting retroactively fired on the spot, write at least one statement in each, every and all Then, Else, While, Repeat, Loop, Case, Switch, Function, Catch, Begin, ...

    (Given the quality of coding rules out there, this explanation is as likely as any other.)

    In that case, wouldn't the correct behavior be as follows:
    private void DoNothing() {
      DoNothing();
    }
    </sarcasm>
  • Ander (unregistered)

    I could see this being used to explicitly remind the reader that nothing needs to be done in a case where the reader might expect that something actually needs to be done. Except, I would comment out the else clause: // else // DoNothing(); and not bother defining the DoNothing function. You could also use it during development to say, "Something may need to go here later."

  • Jack (unregistered)

    Someone is paid by number of lines of code

Leave a comment on “DoNothing()”

Log In or post as a guest

Replying to comment #:

« Return to Article