|
I never wrap single line statements - only multiple lines get wrapped.
Prasad C.M.
modified on Thursday, June 23, 2011 6:20 AM
|
|
|
|
|
But I'd say I mostly wrap single line statements but occasionally don't. But the latter tends to be in maintenance or maybe if I've copied and pasted some code from elsewhere.
If I'm writing new code and I'm in VS then I tend to use the if code snippet that inserts the braces anyway.
Kevin
|
|
|
|
|
Me too. I can't say I do it ALWAYS, but I sure try to, I think it's a lot more readable.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Right....Readability is the main reason to vote for Second !!!
Cheers by,
Anand Ranjan
www.arpblog.com
|
|
|
|
|
I always wrap within braces only readability purpose
|
|
|
|
|
Having superfluous junk in your code makes it more readable? Nonsense. If that's true, then you should put curlies around every block, not just conditions.
The argument that it "prevents bugs" because people will be fooled by indentation is as lame as it can be. First, you should fire anyone who is that stupid, second you should indent correctly in the first place.
Should we also have semicolons on empty lines so people don't get confused by them and think that maybe there is some WhiteSpace programming going on in them?
This is why Python is such a cool language. The indentation must be correct and you don't have any religious wars over white space (though you do have to deal with goofballs who insist on using tabs instead of spaces, because "it is more efficient" -- of course, these same people are using bloated XML all over the place, but why be rational and consistent when you are talking about premature optimization?).
|
|
|
|
|
Right, only about 48% do it correctly.
|
|
|
|
|
Matt Gerrans wrote: The argument that it "prevents bugs" because people will be fooled by indentation is as lame as it can be. First, you should fire anyone who is that stupid, second you should indent correctly in the first place.
As a programmer you are mostly not in a position to fire anybody, specially your team-leads and bosses. And for proper indentation some people can't even remember to press [ctrl]+[K]+[D] - how can we expect them to manually indent properly.
We just have to deal with real world
|
|
|
|
|
In my language called Anonymus you also dont have to wrap or something. It also counts whitespaces. I've written an article about it.
|
|
|
|
|
|
I ofter see development teams using multiple lines characters in code defaults.
|
|
|
|
|
I've taken to line wrapping with _ VB.NET single line If statements, especially simple ones relating to execution flow.
So
If Not condition Then _
Exit Sub
Of course otherwise the IDE puts the End If in for you, so normally single statement If s do get the equivalent of {} .
Regards,
Mark Hurd, B.Sc.(Ma.) (Hons.)
|
|
|
|
|
For those who use VS and have trouble reading single line of code without braces: "Format Your Document"
I assigned F4 to doc. format and helps a lot.
modified on Wednesday, May 18, 2011 1:48 PM
|
|
|
|
|
I always revert changes from people that do that. In my opinion it is an arrogant assumption of individuals to open a code file, reformat the entire file to their preference and then check it in.
|
|
|
|
|
first of all I meant people's own code.
also I don't see anything wrong with indenting the code so one wouldn't perceive:
if (condition)
statement1;
statement2;
as:
if (condition)
{
statement1;
statement2;
}
instead would be like:
if (condition)
statement1;
statement2;
also I don't consider caring about tidiness and readability of the code arrogance.
another reason for me to auto format the code is that source control tools such as SVN wouldn't consider every line of code "changed" only because of some tab or space changes and cause conflicts between different versions.
Cheers
H.M.
|
|
|
|
|
If is only for those wishy-washy, skinny-latte types who can't make their mind up. Make a decision and stick with it.
|
|
|
|
|
I remember using an editor (can't remember which) that wouldn't let me set a breakpoint on the second part of a single line if statement but since that day I used braces.
I've also seen a newer developer get into trouble with something like
if (a ==0)<br />
.....b++;<br />
.....c++;
(sry can't work out how to tab )
|
|
|
|
|
It's a good programming practice,It improves code readability.
Easy to understand for new programmer.
|
|
|
|
|
... since it makes my code more readable, I personally prefer the style
if (condition) {
statement
}
instead of
if (condition)
{
statement
}
I'd also say it depends on the programming language you are using. The first style is more common for Java programs, while the second style is most popular when writing C# code.
Best regards,
Lizandro Campbell
|
|
|
|
|
it makes my code more readable. however the style based on the language I'm working on.
for java,
<br />
if (condition) {<br />
statement<br />
}<br />
for .Net, C++, etc
<br />
if (condition) <br />
{<br />
statement<br />
}<br />
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Now I like the second style because it is easier to read. A good topic for another survey.
------------------<;,><-------------------
|
|
|
|
|
That's called KnR. I also use that format. Thumbs up!
|
|
|
|
|
lzcampbell wrote: I personally prefer the style
Hey, one religious war at a time! I personally prefer the second.
Kevin
|
|
|
|
|
I always wrap single statement in the braces at it looks more readable and understandable to me.
--
Thanks
Sheo Narayan
|
|
|
|
|
I prefer to code in Schizophrenic style. At least I think I do. I can never remember which of us decides the code style.
When I go back to my review my code after 6 months, I think "Who the hell was the lunatic that coded this?!"
It is usually after the shock treatments that I remember I'm the only coder.
No single raindrop believes it is to blame for the flood.
-irresponsibility@Despair.com
|
|
|
|