When writing code (in C++ particularly), where do you put your curly braces?
ex:
int main()
{
}
OR...
int main(){
}
which do you think is better? clearer? more professional?
Name:
Anonymous2012-03-25 20:11
From a professional point of view they're both good. Personally, I prefer the first one. Looks more balanced, I like that.
At my uni they told us to use the second one though.
Either way, it doesn't really matter.
int main() {
if(1) {
printf("All the way to schfifty-five.\n");
} else {
printf("It's perfect K&R, except there's no space between control structures and the following parenthesis.\n");
printf("This is my Achilles heel.\n");
}
}
Name:
Anonymous2012-03-25 20:38
// also, not putting spaces around things makes you an illiterate assmucher and/or engineer
Do you write:
if( (test1) || (test2) )
or do you write:
if((test1) || (test2))
or do you write:
if((test1)||(test2))
or do you write:
if( (test1)||(test2) )
or do you write:
if( ( test1 ) || ( test2 ) )
or do you write:
if(( test1 ) || ( test2 ))
or do you write:
if(( test1 )||( test2 ))
??????
int
main(
)
{
if(
1
)
{
; printf(
"All the way to schfifty-five.\n"
)
; }
else
{
; printf(
"It's perfect K&R, except there's no space between control structures and the following parenthesis.\n"
)
; printf(
"This is my Achilles heel.\n"
)
; }
}
This style brings several benefits to an ENTERPRISE QUALITY project, among which are:
Scalable statement addition and by the use of canonicalized statement initializers as well as terminators (;). Thus you can always know where a statement begins and where it ends.
Mandatory braces for readability, enforced by the prior rule.
Enhanced formal argument injection, as per mandatory line-separation of parameters (not shown here).
Visual hierarchy of braces. Opening braces are always more important than closing ones, thus they are on space further to the left.
In conclusion: the revised /prog/ coding style brings benefits to ENTERPRISE projects by leveraging the visual recognition competencies of the team members and enforcing itself by the means of industry-standard tooling.
>>25
Sorry, this thread is about C++ (that's in the title at least), I was thinkng of C. In C, a struct declared within a struct doesn't have inner scope, but the same scope as the outer struct. Curly braces most often mean ``statement list'', except for variable and array initializations, unions/structs and (some say) function bodies. Statement lists introduce a lexical scope for variable and other names. Structs and unions don't.
Opening bracket for function bodies should be in column 0 so you can jump from function to function with [.
>>52
Your awesome display of technical incompetence is just as impressive.
Name:
Anonymous2012-03-27 17:52
>>51 >>53
Reported, called the cops, sent multiple letters to FBI, NSA and CIA, phoned interpol and europol and lit my house on fire so the cops would come and here my report about you in person.
Hope you enjoy that ass rape in jail kodak-kun
Name:
Anonymous2012-03-27 19:27
>>36
if this is what i have to expect in future jobs im going to kill myself