|
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
|
|
|
|
|
agree
just have to enforce myself..
|
|
|
|
|
A person might be able to play without being creative, but he sure can't be creative without playing.
|
|
|
|
|
Agree
|
|
|
|
|
I feel that code should always be wrapped between braces. (readability) Not doing it for single line statements would surly be inconsistent towards the rest of your code. (consistency)
"Program testing can be used to show the presence of bugs, but never to show their absence."
<< please vote!! >>
|
|
|
|
|
Single:
if ( pWnd == NULL)
return;
Multiple:
if ( pWnd == NULL) {
return;
} else if ( pWnd->IsWindowVisible()) {
return;
}
|
|
|
|
|
Back when I used to code without using code blocks for single line statements, I would occasionally add some code later on for one of the branches and find that I'd forget to add the block and the indentation would trick me into thinking a code block was there causing me to chase my tail for bit.
What a time waster.
I just got to the point where I'd always use code blocks, to prevent these silly mishaps.
|
|
|
|