Support global warming with code!

You don’t like global warming? Well, me neither. But I see often code that does support global warming. How? Really easy:

int myLittleValue = 0;
if (myLittleValue != null && int.Parse(myLittleValue.ToString().Substring(0, myLittleValue.ToString().IndexOf("."))) == 0)
{
  myLittleValue = 1;
}

Nobody will write such code? Oh yes, some do.

  • They use initializers with default-values (take a look with reflector: this will be executed as an assignment).
  • They test for null with non-nullable value types (an int cannot become null)
  • They even use string operations to do math!

All of this I have seen in code that I did review (internal for junior developers and external for customers). And each time I see such code I shout out: “Yeeehaaa – support global warming!” This way I hope someone will take a minute, think about what the code she/he did just wrote will do and transform it into something anybody can read without banging her/his head against the wall.

Don’t misunderstand me – I don’t think the people that write such code are dump or idiots …. most of them are really clever – some of them also good developers – they simply don’t think about what they are doing. And I hope I can prevent some CPU  from being burned down by simply converting and jumping from here to there, allocating and deallocating memory for the temporary strings in “somestring.ToString()” statements, checking values for null that simply cannot be null etc. etc.. There are so much ways to do “innovative” garbage in code – may be I’ll write down some other things I found or that were reported to me.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Sylvio's Infobox

Aktuelle Themen rund um SQL Server, BI, Windows, ...

Meredith Lewis

Professional Digital Portfolio

Vittorio Bertocci

Just another WordPress.com weblog

ScottGu's Blog

Just another WordPress.com weblog

AJ's blog

Thoughts and informations I think worthwhile to share...

Outlawtrail - .NET Development

Architecture & Design

SDX eXperts Flurfunk

Just another WordPress.com weblog

%d bloggers like this: