|
I believe you, but in 15+ years of professional software development (+ more as a hobby) with C-like languages I have never run into issue with that kind of bugs. I've seen ones with a semicolon after while, and even today I often miscount parens or even forget a semicolon here and there, but in your example the indentation just shouts in your face that something is wrong.
|
|
|
|
|
A contributing factor to the problem was that several hands had been working on this particular project. Brace style and indentation were not consistent, which meant that the two missing brace characters were less visually obvious than you might expect.
I was involved in finding the problem, because my application communicated with the service in question. The code itself was not mine, fortunately.
Software Zen: delete this;
|
|
|
|
|
I believe everything you outlined should be pounded into every new C/C++/C# student until it's second nature.
if (condition) DoSomething();
I used to shun this but now use it for strings of similar, ultra simplistic ifs. It looks clean, and if used in the right place is staggeringly obvious what it's doing. Not, as I have seen:
if (condition) x ? y : z;
And x, y and z are greatly abbreviated here. *shudder*
For the other cases, I type both braces as part of typing the if (or for, or whatever), before I type any of the contents, regardless of if it's only 1 line.
He said, "Boy I'm just old and lonely,
But thank you for your concern,
Here's wishing you a Happy New Year."
I wished him one back in return.
|
|
|
|
|
David Kentley wrote:
if (condition) x ? y : z;
That is so incredibly puke-worthy. It probably even compiles.
Software Zen: delete this;
|
|
|
|
|
I'd break the developer's keyboard for that gem.
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
Gary Wheeler wrote: I'm pretty sure the body will never be found.
We used VSS history tool for postmortem and it significantly reduced the number of causalities.
|
|
|
|
|
Amar Chaudhary wrote: significantly reduced the number of causalities
The effect of that statement is rather profound.
Software Zen: delete this;
|
|
|
|
|
lol, I love this place.
Charlie Gilley
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
|
|
|
|
|
Gary Wheeler wrote: if (condition) DoSomething();
This is what I do 100% of the time with true one-liners.
|
|
|
|
|
if there's a comment
{
//with the line,
it needs a wrapper
}
else if there's an else
{
it also needs a wrapper
}
|
|
|
|
|
My style is somewhat similar. I like symmetrical-looking if-else blocks.
Kevin
|
|
|
|
|
I always try to wrap my BACON.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
Have a bit more patience with newbies. Of course some of them act dumb -- they're often *students*, for heaven's sake. -- (Terry Pratchett, alt.fan.pratchett)
|
|
|
|
|
Nagy, you have that backwards. BACON can be used to wrap anything.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Surely all you need to say is:
Chris Meech wrote: BACON can be used
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre
Have a bit more patience with newbies. Of course some of them act dumb -- they're often *students*, for heaven's sake. -- (Terry Pratchett, alt.fan.pratchett)
|
|
|
|
|
Still too wordy:
Chris Meech wrote: BACON
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
if you don't. Manfred made a very good comment earlier that if you want to add any more code then you need to put the braces in anyways.
--
You don't hire a handyman to build a house, you hire a specialist.
|
|
|
|
|
|
Larry Wall rocks!
--
** You don't hire a handyman to build a house, you hire a carpenter.
** Jack of all trades and master of none.
|
|
|
|
|
Slacker007 wrote: if you want to add any more code then you need to put the braces in anyways.
Yeah, I'm not lazy so I wear football safety gear all the time, 'cuse if I want to play football I need to put it anyways.
|
|
|
|
|
It's not wrong to leave a single line code unwrapped under IF. Leads to consistency, uniformity, good practice, blah, blah.
But look at the below scenario:
If ()
sdfsdfsdf;
Else
{
sdfasdfas;
asdfasdfaseasf;
sdfasdfas;
asdfasdfaseasf;
sdfasdfas;
asdfasdfaseasf;
}
Shouldn't the If and else contents be switched? That way I would care less if the one line in else is not wrapped.
-
Just that something can be done, doesn't mean it should be done. Respect developers and their efforts!
Jk
|
|
|
|
|
My personal preference is to do ti always. Although it highly depends on the coding guidelines followed in the project.
"The worst code you'll come across is code you wrote last year.", wizardzz[ ^]
|
|
|
|
|
As I read the question I realise my routine has changed. Previously I considered - is this going to be a single line or not.
Now I just go if(){} ctrl-k,d and then I start to fill out the body as needed.
|
|
|
|
|
Much, much quicker is:
if<tab><tab> which results in:
if (true)
{
}
with the 'true' selected as a replaceable parameter.
ife<tab><tab> gives:
if (true)
{
}
else
{
}
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
I wouldn't let CG touch my Abacus!
When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is.
|
|
|
|
|
It is good pratice and follow it always to wrap any number of lines.
|
|
|
|
|
Consistency is a wonderful thing!
------------------------------------
I will never again mention that I was the poster of the One Millionth Lounge Post, nor that it was complete drivel. Dalek Dave
CCC Link[ ^]
Trolls[ ^]
|
|
|
|