|
I commented just by seeing return type of the function. Did't dare to look into 16 layers at all...
As per prototype
bool UpdateImageFileWithGPSPosition(LPCTSTR lpszPictureFilePath, char* lat_lon)
my comment meant the function would return false in case of failure (rather increasing the layers).
|
|
|
|
|
Easier to do specific cases surely?
------------------------------------
"The greatest tragedy in mankind's entire history may be the hijacking of morality by religion"
Arthur C Clarke
|
|
|
|
|
Let me guess - there's a coding rule to use only one return statement per method?
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I somehow do not appreciate the "single return" coding rule.
|
|
|
|
|
I generally follow the single return style but if it is this complex I would have broken the function into smaller parts.
John
|
|
|
|
|
|
Even so, it's easy enough to do something along the lines of:
success = Operation()
if (success == TRUE)
{
...
}
if (success == TRUE)
{
...
} etc
or
do {
success = Operation();
if (!success) break;
success = Operation2();
if (!success) break;
...
} while(false)
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Hi,
the former is what I do, the latter is a bit ugly, it basically is a never looping loop construct, maybe it belongs in the horror section
|
|
|
|
|
Luc Pattyn wrote: belongs in the horror section
Yes, as mentioned the last time it was brought up.
|
|
|
|
|
I agree. The first time I saw the latter in use I had a double take and went 'hang on...' in a very suspicious tone.
No, not recommended, but arguably better than 16 levels of bleah.
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Sorry Chris, but that second option is just a <hushed_tones>goto </hushed_tones> that avoids using the letters 'g' or 't'.
I know you can do better than that!
Phil
The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.
|
|
|
|
|
I said is was pretty or would not cause gagging.
cheers,
Chris Maunder
CodeProject.com : C++ MVP
|
|
|
|
|
Sorry Chris, but that second option is just a <hushed_tones>goto that avoids using the letters 'g' or 't'.
The reason GOTO has gotten a bad rap is that it has historically been used without any concept of structured control-flow. Programs are generally easiest to understand if they can be subdivided into nested blocks, such that there are few jumps across block boundaries, and all inter-block jumps are of a few specific forms (e.g. jumping to the start or end of an enclosing block). Consider:
if (condition) goto TRUE_CASE;
FALSE_CASE:
do_false_stuff();
goto END_IF;
TRUE_FASE:
do_true_stuff();
END_IF:
Not quite as nice as using the C block constructs, but not particularly nasty. On the other hand, prior to the invention of structured programming, such code would often have been written as:
if (condition) goto TRUE_CASE;
do_false_stuff;
END_IF:
.. somewhere else in the code ..
TRUE_CASE:
do_true_stuff();
goto END_IF;
The code for the true case would often be placed rather arbitrarily. In assembly code written for some machines, it might be placed before the start of the routine which used it, so as to allow an efficient short-displacement branch. Trying to follow code whose physical arrangement bears no relation to its logical flow is, of course, difficult. The problem, though, isn't the use of GOTO per se but rather the use of control flow that doesn't follow any logical structure.
(nb: I do sometimes write assembly code which is more like the latter than the former, particularly in cases where the 'if' case occurs far less frequently than the 'else' case, and the performance impact of adding an extra branch to the 'else' case would be significant and unacceptable. I don't like such code, but sometimes it is necessary).
|
|
|
|
|
Or if it's just functions being called in sequence
success = success && Operation1();
success = success && Operation2();
success = success && Operation3();
or more obfuscated...
success = success && Operation1() && Operation2() && Operation3();
|
|
|
|
|
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
|
|
|
|