|
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[ ^]
|
|
|
|
|
And you can always add statements later without having to remember to add the now needed braces.
Cheers!
|
|
|
|
|
I agree with this. Many times I used to confuse with unwrapped single lines
|
|
|
|
|
If you have trouble remembering to add braces after inserting new lines you should consider changing your career.
|
|
|
|
|
And yet, you don't know how to handle braces correctly... I admire you persistence. So tell me how did you get so far, by name calling?
|
|
|
|
|
|
Agreed, consistency is the key, thus I never wrap single line blocks - I'm consistently trying to reduce nuber of code lines.
|
|
|
|
|
If it is an if followed by a single line or an if-else where both are followed by single lines, then I don't wrap. If multiple lines occur in either part of an if-else , then I wrap both parts.
|
|
|
|
|
It is better to wrap the lines, even if it is a single line. It reduces the confusion and future bugs.
Regards - Kunal Chowdhury | Microsoft MVP (Silverlight) | CodeProject MVP | Software Engineer
|
|
|
|
|
strongly agree
|
|
|
|