|
If there were nothing other than functions called in sequence, then one could use:
{
if (operation1())
return -1;
else if (operation2())
return -2;
else if (operation3())
return -3;
return 0;
} which is I think nicer than using the flag. The place the flag is helpful is when there are things going on other than the simple operations, e.g.
if (!error)
{
setup_for_operation2();
error = operation2();
}
I'm not a particular fan of using the && operator; if one wants to put each operation on one line, one could code it as
if (!error) error = operation3(); which is clearer than the && version, is more versatile when zero is error case (the error flag will hold the particular error code returned, instead of having to hold zero or one), and may yield more efficient code if 0 is error and 1 is success (a statement like ok = ok && operation3(); is likely to perform a redundant write to ok when it's equal to zero.
|
|
|
|
|
How about
try
{
hr = Operation1();
if (!SUCCESS(hr)) throw hr;
hr = Operation2();
if (!SUCCESS(hr)) throw hr;
hr = Operator3();
if (!SUCCESS(hr)) throw hr;
}
catch (HRESULT hErr)
{
}
?
|
|
|
|
|
kingsimba0511 wrote: I hope you have a 22 inch above screen.
I don't have it
|
|
|
|
|
And it fits my 20" monitor just fine. Even with the 8-SPACE indenting and large font.
|
|
|
|
|
I have 17" monitor
|
|
|
|
|
kingsimba0511 wrote: I hope you have a 22 inch above screen.
It's not the diagonal, it's the resolution. That fits comfortably on my 18" 1600x1200 CRT. I suspect it would fit on my 1400px wide laptop LCD as well.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
And the font, I use 8-point.
|
|
|
|
|
I use browser default. I've never seen a font only scaling that didn't fubar page layouts at least somewhat. Opera's zoom probably comes closest but there're some video plugins it doesn't scale.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
This developer might not be as stupid as we think. Just think how impressed a business user ( with no concept of programming) must be when this code is shown to him/her. A business person will think that a developer that can write code that looks like this (extremely complex in the business users eyes) must be a genius and a great asset to the company. What better job security can you get?
If at first you don't succeed, failure may be your style. (Quentin Crisp)
Recession is when a neighbor loses his job. Depression is when you lose yours. (Ronald Reagan)
|
|
|
|
|
And the comments on the terminating braces are useless, too.
Professional Geek,
Amateur Stage-Levelling Gauge
|
|
|
|
|
I like writing such code. It is typical COM-Spaghetti.
Congratulations.
(ROFL)
Greetings from Germany
|
|
|
|
|
16 layers...that guy must be insane
modified on Friday, February 27, 2009 6:54 AM
|
|
|
|
|
This particular gem was found in the code of a recently departed team member who described himself as a C# 'Expert'. Everytime someone in the team looks at his code for more than 5 minutes, they find another howler. Truly shocking.
public bool SelectedByDefault
{
get { return _defaultSelected; }
set
{
if (value != null)
{
_defaultSelected = value;
}
else
{
_defaultSelected = false;
}
}
}
|
|
|
|
|
Just a different take on a common situation.
|
|
|
|
|
lol, arguments in code comments.
|
|
|
|
|
Here, here might need this: ?
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Even more surprising is that it appeared convinced this was true even though the compiler gives an unreachable code warning and tell you that the check will always return true. But he probably didn't notice it hidden amongst the other 200 warnings. Sigh.
|
|
|
|
|
By the way, C# compiler (with optimization option 'on') generates these IL instructions for set accessor:
ldarg.0
ldarg.1
stfld bool <reference_to_local_field>
ret ;
so, at the C# level it whould be:
this._<reference_to_local_field> = value; ;
So, this construction is obviously needless
modified on Monday, January 19, 2009 1:56 AM
|
|
|
|
|
A colleague says perhaps this guy just plain didn't trust that said field would be checked actually *in* the serialization code...not that anyone would want to risk an exception getting thrown for serializing a bool anyway.
Since when were bool variables ever null ? Besides isn't that equivalent to false , or am I not a "C# Expert?"
-Brian
Sincerely Yours,
Brian Hart
|
|
|
|
|
public bool SelectedByDefault{ get; set; }
why not like above ?
|
|
|
|
|
Clearly, that would be _way_ too easy!
Just because the code works, it doesn't mean that it is good code.
modified on Friday, March 20, 2009 4:41 PM
|
|
|
|
|
Rotted Frog wrote: because serialisation can assign a null to a bool
Isn't the bool variable default initialized to false?
|
|
|
|
|
I think the worst projects to take over are those similar to the one I'm currently stuck with :
It's a relatively small & simple... in theory.
What complicates it is the fact that it's been through serveral developers already , is in a mix of C# and VB, uses various versions of the framework, is reliant on heaps of 3rd party DLL's, uses a 3rd party data access and business logic layer classes that are enormous & difficult to understand, there are no business requirements documents for it, it has no technical spec, the database uses a mix of naming conventions... I could go on.
Oh, and if that wasn't enough, the developer that was working on it is AWOL so no support from there...
|
|
|
|
|
So it's about par for the course?
|
|
|
|
|
Yeah, you have to get into those projects early, before all that happens.
|
|
|
|