Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
What's wrong with this block of code??? Buellerrrrr, Buellerrrrr

All, just came across some 'interesting' code today.  Can anyone point out what is wrong with this?


public bool SomeMethodNameHere( bool someParamNameHere )
{
    if ( this == null )
    {
        return true;
    }
        else
    {
          ....
    }
}



        
 


Posted 05-04-2007 9:51 AM by Derik Whittaker
Filed under:

[Advertisement]

Comments

Christopher Bennage wrote re: What's wrong with this block of code??? Buellerrrrr, Buellerrrrr
on 05-04-2007 11:30 AM

Wow.

Jeff Perrin wrote re: What's wrong with this block of code??? Buellerrrrr, Buellerrrrr
on 05-04-2007 11:32 AM

It's existentialist code.

RoryBecker wrote re: What's wrong with this block of code??? Buellerrrrr, Buellerrrrr
on 05-04-2007 11:35 AM

This is nearly correct.

The only way that "this" could be nothing is if the author intended for this to be an "extension method" for a type.

They have either forgotten to use appropriate c# syntax to indicate the "extension method" nature of the code or alternatively they don't understand that if you're checking if you exist, then you must exist in order to do the check :)

I reckon the later :)

Derik Whittaker wrote re: What's wrong with this block of code??? Buellerrrrr, Buellerrrrr
on 05-04-2007 11:43 AM

Rory,

I did not think of your extension method angle, but since this is 2.0 code, this cannot be the case....

Your right, it is the 2nd i think.

More over i think at some point there was a bug and this was the 'fix' yikes....

Jayson Knight wrote re: What's wrong with this block of code??? Buellerrrrr, Buellerrrrr
on 05-04-2007 11:58 AM

A simple test case would help the author see that this will always execute whatever code is in the else block. Yikes!

Derik Whittaker wrote re: What's wrong with this block of code??? Buellerrrrr, Buellerrrrr
on 05-04-2007 12:31 PM

Jayson,

You are so right, too bad this app does not really have any tests (something myself and a few others new to the team are working on changing).

Billy McCafferty wrote re: What's wrong with this block of code??? Buellerrrrr, Buellerrrrr
on 05-04-2007 1:08 PM

I love Mr. Perrin's comment; existentialist indeed!

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)