What's your prefered program layout?
Some people do:
Code:
#include <stdio.h>
int main(void) {
printf("Hello, world,");
if(1) {
printf(" and goodbye.");
}
}
but I do:
Code:
#include <stdio.h>
int main(void)
{
printf("Hello, world,");
if(1)
{
printf(" and goodbye.");
}
}
I don't see why the hell they do the first one, because it is near impossible to keep track of the brackets. Are they stupid or do they have a reason?
Also, assembly can be used from within C[++] programs, and therefore we should have an assembly board. We need one.
Oh, this is my 500th post. I have no life.
Re: What's your prefered program layout?
I personally like:
Code:
#include <stdio.h>
int main(void){printf("Hello, world,"); if(1){printf(" and goodbye.");}}
Four most popular techniques
Well, nowadays, there are four most popular techniques of coding that are acceptable, encouraged and used in developing softwares:
the first technique is the K&R that looks like this:
if (cond) {
stmt1;
stmt2;
...
}
the second technique is called the Allman technique that goes like this:
if (cond)
{
stmt1;
stmt2;
...
}
the third would look like this:
if (cond)
{
stmt1;
stmt2;
...
}
and is called Whitesmith.
Finally, the fourth most popular technique is the following and is known as Alternative:
if (cond) {
stmt1;
stm2;
...
}
The kernighan and Ritchie style(#1) is the most widely used style since it uses slightly less vertical space than other methods. On the other hand many, like Brian, feel that it is more burdensome to match up braces with this technique.
#2 and #3, the Allman and the Whitesmith styles are often preferred by programmers specially those who have done programming in pascal. The brace matchin is easy but extra vertical space is used.
finally #4 is a very popular alternative to standard D&R formatting.
What is important, Brian, is consistency. You pick any one of the acceptable styles and make sure you are consistent.
Remember, a good programer is the one who "Writes programs for people first, computers second". So make sure your code is readable.
tnx,
ben
p.s. if my codes dont look the way they should, then please let me know how to use the special editor. I will post the 4 techniques again in that case. thanks
The four techniques, again
Thanks to adrian, I am able to show you the four techniques once again, (I hope it works i mean...)
#1) K&R
Code:
if (cond) {
stmt1;
stmt2;
...
}
#2) Allman
Code:
if (cond)
{
stmt1;
stmt2;
...
}
#3) Whitesmith
Code:
if (cond)
{
stmt1;
stmt2;
....
}
#4) Alternative
Code:
if (cond) {
stmt1;
stmt2;
...
}
I hope it works this time!
tnx,
ben
The four techniques, again
Thanks to adrian, I am able to show you the four techniques once again, (I hope it works i mean...)
#1) K&R
Code:
if (cond) {
stmt1;
stmt2;
...
}
#2) Allman
Code:
if (cond)
{
stmt1;
stmt2;
...
}
#3) Whitesmith
Code:
if (cond)
{
stmt1;
stmt2;
....
}
#4) Alternative
Code:
if (cond) {
stmt1;
stmt2;
...
}
tnx,
ben