Reputation: 5411
I couldn't seem to find a good question on SO, or a good Google search that seemed to answer my question. What is the industry or popular preference when it comes to formating code "chunks" and their brackets. Here are some examples for what I am trying to explain...
if($foo)
{
return $bar;
}
else
{
return $stackOverflow;
}
VS
if($foo){
return $bar;
}else{
return $stackOverflow;
}
Of course, with similarities in the other major languages, and of course with any code blocks that use curly brackets. I have seen across the board both methods used, and the first one seems to make more sense as it allows one to quickly look up and down to find the matching bracket.
What are your thoughts?
Upvotes: 0
Views: 142
Reputation: 91786
Depending on whether or not you are working with a company that prefers a standardized convention, you would be obliged to use that.
Otherwise, use what you feel comfortable using and be consistent.
Adapting to a standard before knowing what the specific companies standards's are might not be worth while. Depending if you hop from one job to another they may have a completely different set of standards that you would have to now re-adapt to.
Upvotes: 4
Reputation:
Most companies i worked for used
if ($foo)
{
bar();
}
As i currently prefer to develop in C# which follows this style it now comes naturally.
I've also noticed that it greatly depends on the language, C(++) and Perl programmers prefer {} on the same line, C#, Java and PHP developers prefer { and } on their own lines.
Upvotes: 2
Reputation: 7309
Sigh. It doesn't matter. Stick with whatever the standard is where you work. If there is no standard, be consistent when writing your own code, and use whatever is already there when modifying others code.
Upvotes: 0
Reputation: 6872
I prefer the second one, because I don't consider curly bracket an statement. Anyway, just my thought.
Upvotes: -1