|
Fascinating discussion !
While recognizing the special constraints of device driver, and down-to-the-hardware specific, programming, in a high-level language, like C#, with a powerful optimizing compiler, I favor multiple returns, and "defensive" error checking (throw immediately) wherever possible, asap.
For me, "deeply nested" is for the (recursive) birds.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Single ``return`` or multiple ``return`` I think is a potential code smell - based on design and code format agreements.
I like the concept of having the guard statements and their ``return`` or ``throw`` exception small and tight at the beginning of a function/method. Putting the error handling into an ``else`` block can destroy the readability.
We recently found a method in a work project where we were setting a ``results`` variable to ``true``, and then calling ``return false``. The last line of the method was to ``return results``. (Of course, no comments what team member that is no longer with the company was thinking.) This was in the logic and processing, not in guard statements.
I think using negation logic can also be a code smell
void doSomething(var a)
{
if (a == null)
{
throw new Exception("a == null");
}
else
{
}
}
is more readable than
void doSomething(var a)
{
if (a != null)
{
}
else
{
throw new Exception("a == null");
}
}
|
|
|
|
|
I had to write some incredibly complicated business rules.
Imagine that we charge a 3% fee.
But there are like 19 situations where the fee is either more or less than that fee.
The fees are also relative to that 3% fee, which is customer specific.
I thought long and hard about how to write this to clarify the businesses intent, and used an infinite loop to avoid the return, but I also had to have a STRING indicating which rule was applied for logging, as well as to generate the invoice.
while (true) {
if (condition1) {set %; set sMsg; break}
if (condition2) {set %; set sMsg; break}
break;
}
logIt("Rate Calculation",sMsg, % as string);
setup return variables
return;
}
The upside of this code was that the comments, and the FLOW were ratified 3 times by the business side. The code went into production 20 years ago, and was never modified.
Is this similar to the "many returns"? Yes, in a big way. There are many exits from the loop, but it captures the flow and priority perfectly. In fact, there was a decent amount of pre-loop setup code that calculated pieces to make the conditions make sense and be readable to the business people.
While I am HUGE on coding standards and code reviews. There are ALWAYS unique coding situations where I will gladly throw them all out the window to produce Highly Provable code that is easy to process and find errors in!
|
|
|
|
|
Did Pink Freud release an album called "The Dark Side of Your Mother"?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
there's no dark side of your mother really, matter of fact she's all dark
Message Signature
(Click to edit ->)
|
|
|
|
|
Hey now. Isn't the preferred term "African American"?
|
|
|
|
|
Not if she's not an American!
- I would love to change the world, but they won’t give me the source code.
|
|
|
|
|
I met with a cringeworthy left extremist here who referred to a colleague as "African American".
I told her that the dude she was referring to had nothing to do with Africa or 'Muhrica, and just for kicks asked her why was she being condescending and insulting about an aboriginal Australian.
The look on her face was priceless.
modified 15-Feb-19 15:50pm.
|
|
|
|
|
That was intentional in my response. There's plenty of "dark people" (ahem) who get referred to as "African Americans", even though they weren't born or might not have ever been to either Africa of 'Muhrica.
Political correctness gone mad. But then, I don't know of any other type of political correctness.
|
|
|
|
|
dandy72 wrote: That was intentional in my response.
Yup, I figured that much.
dandy72 wrote: Political correctness gone mad. But then, I don't know of any other type of political correctness
Very true!
|
|
|
|
|
Dunno, all I remember is that body-part-in-the-wall song...
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
Yup, and I'd put money on you having brain damage, if you had the time to listen to it a lot while on the run.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
interestingly enough though they say for some forms of brain damage: better to keep the loonies ON the grass.
Message Signature
(Click to edit ->)
|
|
|
|
|
Correct, I believe the directions are take a hit, and breathe.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
or was it "Shine on you crazy Psycho"?
Got my site back up after my time in the woods!
JaxCoder.com
|
|
|
|
|
I wish you where here so that I could tell you that you have had a momentary lapse of reason.
Socialism is the Axe Body Spray of political ideologies: It never does what it claims to do, but people too young to know better keep buying it anyway. (Glenn Reynolds)
|
|
|
|
|
|
Well done! I'm just certified, I need to be to work here
|
|
|
|
|
|
Great! Congratulations.
My goal is to live forever. So far, so good.
If you can keep your head while those about you are losing theirs, perhaps you don't understand the situation.
|
|
|
|
|
theoldfool wrote: Great! Congratulations. Thanks!
theoldfool wrote: My goal is to live forever. There can be only one!
|
|
|
|
|
Well done, remember to make 2020's goal re-doing all of your exams again because Microsoft has expired the ones you've just passed
|
|
|
|
|
Yeah, I got 70-532 just last year... This is basically just the replacement
|
|
|
|
|
Azure cert, well that's nice,
so... do you have at least 15 years of actual experience?
- no: sorry, not a suitable match
- yes: 15 years! sorry, but in that case you're too old for IT! "it's a young peoples game."
Hot tip:
5+ years experience in visual studio 2019 sure to impress
- they will be throwing jobs at you
(well, until next week when something else new is released.)
Message Signature
(Click to edit ->)
|
|
|
|