|
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
|
|
|
|
|
When simple code, I use:
if (a[i] > n)
result++;
When some additional logic or comments required, I use:
if (a[i] > n)
{
new Calculator(this).Calculate(a[i], i, n);
}
and
if (a[i] > n)
{
result++;
}
|
|
|
|
|
I agree and voted with 5
|
|
|
|
|
Since we use stylecop for our coding guidelines, single-line statements without braces are no more existant
In my opinion, it improves the reading so I totally agree in using braces always.
Have a nice day and happy coding,
Stops
|
|
|
|
|
// ♫ 99 little bugs in the code,
// 99 bugs in the code
// We fix a bug, compile it again
// 101 little bugs in the code ♫
|
|
|
|
|
|
Also using StyleCop for C# but only using { } when needed (readability, multiple lines etc.)
Which rule "forces" you to use { } always?
A:
if (a)
a();
else if (b)
b();
else if (c)
c();
else
d();
B:
if (a)
{
a();
}
else if (b)
{
b();
}
else if (c)
{
c();
}
else
{
d();
}
If you're paid per code lines you'll prefer B, right?
Some argue using { } always in order to avoid bugs when another developer is adding code e.g. to a if block. But I never produced a but because of this ^^
if (ab)
a();
b();
if (ab)
{
a();
b();
}
|
|
|
|
|
Hi,
It is the rule "SA1503: CurlyBracketsMustNotBeOmitted".
I'm not paid per line, but I still prefer braces for one-liners.
Best regards and happy coding,
Stops
|
|
|
|