Just letting off steam...

  • Thread starter Thread starter The Last Danish Pastry
  • Start date Start date
T

The Last Danish Pastry

I came across this piece of C# code today in a real application...

--------------------------------------
if (boolVal == true)
{

return true;
}
else
return false;
--------------------------------------

I was impressed by the amount of sheer ineptitude that the author of
the code had managed to squeeze into just a few lines.

# Why the blank line before "return true;"?

# Why are there braces around the if-part but not the else-part?

# The variable name, boolVal, is wonderfully uninformative.

# Why did the author write "(boolVal == true)" rather than just
"(boolVal)"?

# And, of course, why didn't the author replace the whole thing by
"return boolVal;"?

So far I have not been able to summon up enough courage to study the
rest of the program.
 
"The Last Danish Pastry" <[email protected]> a écrit dans le message de (e-mail address removed)...

|I came across this piece of C# code today in a real application...

<snipped cause of amusement/> Aaaaaarrrrgghh !

| So far I have not been able to summon up enough courage to study the
| rest of the program.

I suggest applying for a temporary lobotomy to ensure that your good brain
cells don't suffer :-))

Joanna
 
Hi,

I was impressed by the amount of sheer ineptitude that the author of the
code had managed to squeeze into just a few lines.

It was kinda cool :) , you have to wonder what he was thinking when he
wrote it
# Why the blank line before "return true;"?
Probably it was due to formatting. you place the { , hit return this make
the next line properly formatted, but if you change of line you lose it, the
easier way to get it back, hit return and you will get it again, one line
below
# Why are there braces around the if-part but not the else-part?
Maybe there was something in the blank line and he simply cut it out
# The variable name, boolVal, is wonderfully uninformative.
well better than b believe me.
# Why did the author write "(boolVal == true)" rather than just
"(boolVal)"?
# And, of course, why didn't the author replace the whole thing by "return
boolVal;"?

too early in the day for these complex questions :)
 
The said:
I came across this piece of C# code today in a real application...

--------------------------------------
if (boolVal == true)
{

return true;
}
else
return false;

I once encountered a website where people could anonymously post
examples of real code they had met in the course of maintenance work,
for the amusement and amazement of others. That snippet would fit right
in. Can't find it now though.
 
Larry,
I once encountered a website where people could anonymously post
examples of real code they had met in the course of maintenance work,
for the amusement and amazement of others. That snippet would fit right
in. Can't find it now though.

Are you thinking of http://www.thedailywtf.com/ ?
 
Hi Clive,

Unless you have some compelling reason to study the rest of the program, I
would recommend passing on it. The code you posted demonstrates that the
entire program is poorly written, and likely to need a complete rewrite.
While it does what it is attempting to do, it exhibits a very poor
understanding of programming principles in general. I would expect the
entire body of code to be peppered with poorly written, and worse, poorly
designed code. Chances are, there are far worse things going on in there
than poorly-optimized code.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
Comments a bit harsh.- its fairly common code to see in an early code walk
through. Most likely cause is that there really was something to be done if
true and its not been added or its been removed - possibly the same for the
false state.

Not bad code just human, and if this is the worst you ever see - smile
you've been lucky !

and a good compiler will optimize it away (not sure if c# would ?)

Bob
 
There's probably a better explanation for this code. It's probably due to
maintenance or changing specs. For instance, the braces could quite possibly
have contained a lot of code that was suddenly yanked and the maintainer did
not bother to go back and clean up/refactor the code. That happens quite a
lot when deadlines have come and gone btw. You simply need to tell the last
person to go refactor the code. It's a polite approach and is
non-judgmental.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
 
bob said:
Comments a bit harsh.- its fairly common code to see in an early code walk
through.

Not in my experience. If I ever had to review code looking like that,
I'd be asking serious questions of the person who wrote it. It would
certainly never come up if you were using pair programming (with even
slightly competent developers).
Most likely cause is that there really was something to be done if
true and its not been added or its been removed - possibly the same for the
false state.

And the reason for calling the variable "boolVal"?

Not performing the obvious refactoring there is just lazy.
Not bad code just human, and if this is the worst you ever see - smile
you've been lucky !

I'd say it *is* bad code: it has an awful variable name which doesn't
convey any meaning, and is expressing something in a way which isn't
nearly as simple as it might be. Both of are indicators of bad code
IMO.
and a good compiler will optimize it away (not sure if c# would ?)

Even if it didn't, the chances of it being significant are tiny. The
problem isn't with the behaviour, it's with the readability and
maintainability etc.

Jon
 
I came across this piece of C# code today in a real application...

--------------------------------------
if (boolVal == true)
{

return true;
}
else
return false;
--------------------------------------

I was impressed by the amount of sheer ineptitude that the author of
the code had managed to squeeze into just a few lines.

# Why the blank line before "return true;"?

# Why are there braces around the if-part but not the else-part?

# The variable name, boolVal, is wonderfully uninformative.

# Why did the author write "(boolVal == true)" rather than just
"(boolVal)"?

# And, of course, why didn't the author replace the whole thing by
"return boolVal;"?

So far I have not been able to summon up enough courage to study the
rest of the program.

I would be concerned about the obvious lack of any critical review of
the release code. In turn I would wonder if the design was produced in
a similar manner.

The scent of "stream of consciousness coding" often indicates the
project won't pass the smell test.

regards
A.G.
 
I agree with Jon, not refactoring it makes for a lazy programmer. It's
like seeing large clumps of commented out source code left in when it's
redundent
 
Back
Top