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?
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.
Response to OP’s comment:
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.