473,326 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 1169
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Tim | last post by:
Dear Developers, Firstly, I'm not sure where this post should go so I apologise if this is in the wrong group or area. I'm currently interviewing for a vb.net developer who doesn't mind...
1
by: VM | last post by:
Is it possible for the bound data in a web datagrid to be displayed in links? The grid will show the client's first name and last name and, when the user clicks on the first or last name, I want...
1
by: Brandon Potter | last post by:
I'm having a bit of trouble figuring out how to let IIS 6 pass on default document requests for documents that don't exist to ASP.NET. In a simplified version of my application, all of the...
1
by: Andre | last post by:
I've set up the accessKey for my Submit button to 'S'. The usual Windows method for letting the user know would be to underline the 'S' in Submit on the button text. How do I do this in the Text...
19
by: | last post by:
Just seeking some advice (or solace)... Am I the only who's having trouble letting go of notation? Having extensive experience in C++ years ago (both before I jumped into VB3 in college and at...
17
by: Mike Labosh | last post by:
I can say this: int commandTimeout = Convert.ToInt32(ConfigurationSettings.AppSettings); but I can't say this: int commandTimeout = (int)ConfigurationSettings.AppSettings; Or maybe my VB...
18
by: Frank | last post by:
I'm using Sleep(100) and that works OK. However, it would be better if my app continued to receive and process keyboard messages. How can I pause the execution of code in one routine while...
0
by: =?Utf-8?B?U3Vl?= | last post by:
I need your help. I am a medical transcriptionist trying to start a new job. I have dowloaded the company's software (Chart Net) and when I try to open the voice files I get this ACM steam open...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.