- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.
Admin
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.
Admin
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.
Admin
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;
Admin
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.
Admin
That's a little better than...
If SomeBoolean Then
' Do Nothing
Else
DoSomething()
End If
Hmm... Maybe not.
Admin
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.
Admin
Just for the record, I should state that this wasn't my code - just a gem from a coworker.
Admin
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"
Admin
typos... and accept; would allow it
Admin
I suppose he deserves a little time Doing Nothing after all those superfluous Validates()
Admin
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.
Admin
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......
Admin
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.
Admin
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. :-)
Admin
Err...and isn't he using a bitwise (&) AND operator instead of a logical (&&) one!?
Admin
Good catch Wim!
Admin
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!
Admin
Maybe the donothing() is for setting a breakpoint or something?
Admin
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.
Admin
Two uses for a DoNothing() function:
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.
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.
Admin
Isn't a NULL function pointer a better idea then?
Admin
All those Validate() methods ... I feel validated.
Admin
Maybe they were trying to do something like Python's "pass" statement.
Admin
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.)
Admin
Admin
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."
Admin
Someone is paid by number of lines of code