471,317 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

Just letting off steam...

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.

--
Clive Tooth
www.clivetooth.dk
Jan 12 '06 #1
13 1125
"The Last Danish Pastry" <cl****@gmail.com> a écrit dans le message de news:
42*************@individual.net...

|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

--
Joanna Carter [TeamB]
Consultant Software Engineer
Jan 12 '06 #2
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 :)


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 12 '06 #3

The Last Danish Pastry wrote:
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.


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 Lard
Replies to group please

Jan 12 '06 #4
I think you're refering to http://thedailywtf.com/

"Larry Lard" wrote:

The Last Danish Pastry wrote:
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.


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 Lard
Replies to group please

Jan 12 '06 #5
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/ ?

--
Colin Neller
http://www.colinneller.com/blog
Jan 12 '06 #6
Hi!

The Last Danish Pastry wrote:
I came across this piece of C# code today in a real application... [...snip...] So far I have not been able to summon up enough courage to study the
rest of the program.

[...snip...]

After recovering from that shock, try having a look at
http://www.thedailywtf.com/
Be prepared...
Jan 12 '06 #7
smells of VB programmer to me

Jan 12 '06 #8
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.

"The Last Danish Pastry" <cl****@gmail.com> wrote in message
news:42*************@individual.net...
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.

--
Clive Tooth
www.clivetooth.dk

Jan 12 '06 #9
bob
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

"The Last Danish Pastry" <cl****@gmail.com> wrote in message
news:42*************@individual.net...
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.

--
Clive Tooth
www.clivetooth.dk

Jan 12 '06 #10
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
-------------------------------------------------------

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:Ou**************@TK2MSFTNGP10.phx.gbl...
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 :)


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Jan 12 '06 #11
bob wrote:
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

Jan 12 '06 #12
On Thu, 12 Jan 2006 13:09:43 -0000, "The Last Danish Pastry"
<cl****@gmail.com> wrote:
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.
Jan 12 '06 #13
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

Jan 13 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Brandon Potter | last post: by
1 post views Thread by Andre | last post: by
17 posts views Thread by Mike Labosh | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.