|
Stacy Dudovitz wrote: If that author forgets to now add the curly braces to enclose scope, bad things happen.
So not only coding now to guess at the competence of future programmers but also presuming that comprehensive unit testing will not happen?
|
|
|
|
|
To the first question about competence, that may be a bit harsh. We are, after all, human beings, and as such, even the best of us make mistakes. To be clear, while some mistakes can be attributed to competency levels and/or experience, I've also seen errors due to time pressure from the decisions makers, long hours of debugging a nasty problem, or other factors which can contribute to bugs.
Hence, my suggestion/recommendation falls more in line with defensive coding rather than assuming that everyone that is not me is an idiot. Your mileage may vary on that point.
With regards to unit testing, even in shops where unit testing is mandated as part of the development process (again, until a time deadline or other external factors discourage the practice in light of external pressures), my experience has been that often unit testing is more to tick off a checkbox than to actually produce maintainable and reliable code. Writing proper unit test code is an artform unto itself, and is predicated on other practices such as one method should encompass exactly one function. (Lets not split hairs on the triumvirate of the types of testing i.e. unit, system and integration tests. In this case I am referring to all three under the single banner of 'unit testing'.)
Bottom line, whatever practice you or your shop choose to implement, it should be purposeful and consistent. My post here was to offer a more thorough response to the original question.
|
|
|
|
|
Stacy Dudovitz wrote: often unit testing is more to tick off a checkbox
That can be solved with required code reviews and required code coverage metrics.
|
|
|
|
|
Agree on the curly braces. There was someone who did a lot of research about which if/else brace pattern worked best for automated merging, but I can never find it.
|
|
|
|
|
Do not attempt the extra check if you are dealing with floating points.
You might really need the extra ELSE clause.
if (x > 1.0) {
}
else if (x <= 1.0) {
}
else {
// yes you can reach this
throw wtf;
}
What are possible values of x?
|
|
|
|
|
Disagree! (contingent on compiler switches set, of course )
else {
throw wtf;
}
if (x == NaN) or some similar hairy answer, the compiler (again, with the correct compilation switches set) will automagically throw an exception.
Sidebar: One would NOT want to set said same switches on an embedded piece of code, since typically exception handling is turned off. Therefore, one would NOT, in such an instance wish to throw wtf .
|
|
|
|
|
The OP never mentioned language or compilers.
Some compilers for whatever language may not support those options.
It was a general stylistic question. Most compilers (and forums) wonβt even warn when you use assignment operator instead of comparison operator.
π
|
|
|
|
|
Hell no! If you must put the second conditional for documentation purposes, make it a comment
if (cond)
...
else // if (!cond)
...
or
if (cond)
...
else // cond
...
I've seen that style used for conditional compilation, not so much for braces.
#if cond
...
#else
...
#endif //cond
|
|
|
|
|
Wordle 951 3/6
β¬β¬π©β¬β¬
π©π©π©π¨β¬
π©π©π©π©π©
|
|
|
|
|
Wordle 951 3/6*
π©β¬π©β¬β¬
π©π©π©β¬β¬
π©π©π©π©π©
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Wordle 951 6/6
β¬β¬β¬β¬β¬
β¬β¬β¬β¬π¨
β¬π©π©β¬β¬
β¬π©π©β¬β¬
π¨π©π©π©β¬
π©π©π©π©π©
Phew
|
|
|
|
|
β¬β¬π¨β¬β¬
β¬β¬π©β¬β¬
π¨π©π©π¨β¬
π©π©π©π©π©
In a closed society where everybody's guilty, the only crime is getting caught. In a world of thieves, the only final sin is stupidity. - Hunter S Thompson - RIP
|
|
|
|
|
Wordle 951 5/6
β¬π©π¨β¬β¬
π©π©β¬β¬β¬
π©π©β¬β¬β¬
π©π©β¬π©β¬
π©π©π©π©π©
|
|
|
|
|
Wordle 951 4/6*
β¬β¬π¨π¨β¬
π¨π¨β¬β¬β¬
π©π©β¬π©β¬
π©π©π©π©π©
Happiness will never come to those who fail to appreciate what they already have. -Anon
And those who were seen dancing were thought to be insane by those who could not hear the music. -Frederick Nietzsche
|
|
|
|
|
Wordle 951 6/6*
π©β¬π©β¬β¬
π©β¬π©β¬β¬
π©β¬π©β¬β¬
π©β¬π©β¬β¬
π©β¬π©β¬π¨
π©π©π©π©π©
I didn't find that easy!
|
|
|
|
|
Wordle 951 3/6
β¬π¨β¬β¬β¬
π©π¨β¬β¬β¬
π©π©π©π©π©
Ok, I have had my coffee, so you can all come out now!
|
|
|
|
|
Venting on! This is a vent!!! <===
Why does Microsoft make everything so D*** difficult? I don't want to use Windows Hello... Stop prompting me!!
Why does the system configuration require editing the registry?
Why are they attempting to duplicate the Mac experience?
Why does updating a simple action mandate a blessing from the Pope and/or a drunk Newfie?
Why are they making the simplest operation a major exercise in futility and frustration???
Why is it that .... H***, I'm could go on for quite awhile but I won't.
Suffice to say I am not a fan of Windows 11.
Venting Off!!
If it wasn't for the fact that I am deeply mired (?) in the Windows environment. I would move to Linux.
I might just consider learning how to develop the a KDE type interface for Linux and write one that emulates Windows 7!!
Cegarman
document code? If it's not intuitive, you're in the wrong field
Welcome to my Chaos!
|
|
|
|
|
|
Hi,
Ok!! Thanks for the info! I will definitely have a look at both of those!!
Cegarman
document code? If it's not intuitive, you're in the wrong field
Welcome to my Chaos and Confusion!
|
|
|
|
|
I feel for you, I am not really doing Windoze software anymore, part of the reason you have described. Windows Peaked with 7, still have it on a couple machines at home. 10 is OK(ish), 11 as you said, I still have a Windows 2000 machine takes an age to start up (only 16 bit!) but you can beat it with a rock it will keep truckin', make a loud noise 11 will fall over (or drain your battery if you are unplugged!)
|
|
|
|
|
After my first attempt at installing Win2000 on a blank machine succeeded in a fraction under 11 minutes, I fell in love with that version. Sadly I've had to move on, but still remember it fondly... It did everything you could want it to, never complained, never crashed, and everything was pretty much where you would expect it to be. Downhill all the way since then as far as I'm concerned...
|
|
|
|
|
The MOD still (or did use it until recently) use it. It's NT at heart it will work on a stone tablet if it meets the basic boot requirements
|
|
|
|
|
Hi,
I traded someone my Windows ME disks (floppy's) for their copy of Windows 2K.
I believe I got the better part of that deal. Sadly, that disk is long gone. I do have a CD with key for Windows XP laying around somewhere. And a copy of Redhat 7 hiding somewhere as well.
Cegarman
document code? If it's not intuitive, you're in the wrong field
Welcome to my Chaos and Confusion!
|
|
|
|
|
I still have an ME installer that I never used all legal OEM copy some where.
|
|
|
|
|
Hi,
Sadly, I got rid of my last copy of OS/2 version 4 about a year ago. That was a solid system even running on a Pentium box with 480 meg drive. I tried it on an I-5 and it was scary fast and very very stable.
Cegarman
document code? If it's not intuitive, you're in the wrong field
Welcome to my Chaos and Confusion!
|
|
|
|