473,465 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Coding Style

I thought it might be fun to run a simple vote to discover the most
preferred spacing style for a simple if statement with a single, simple
boolean test. By my count, there are 32 possible variations for this
case. Here is a complete list.

AA: if ( a > b )
AB: if ( a > b)
AC: if ( a >b )
AD: if ( a >b)
AE: if ( a> b )
AF: if ( a> b)
AG: if ( a>b )
AH: if ( a>b)
AI: if (a > b )
AJ: if (a > b)
AK: if (a >b )
AL: if (a >b)
AM: if (a> b )
AN: if (a> b)
AO: if (a>b )
AP: if (a>b)
AQ: if( a > b )
AR: if( a > b)
AS: if( a >b )
AT: if( a >b)
AU: if( a> b )
AV: if( a> b)
AW: if( a>b )
AX: if( a>b)
AY: if(a > b )
AZ: if(a > b)
BA: if(a >b )
BB: if(a >b)
BC: if(a> b )
BD: if(a> b)
BE: if(a>b )
BF: if(a>b)

So, rank the available options from your most favorite to your least
favorite. It is not necessary fully rank all available options. Two or
more options can be ranked as being essentially equivalent. An example
ballot would look like:

AA > AJ > AG > AP > AQ = AW = AZ = BF

In this case, AA AJ AG AP AQ AQ AZ & BF, are all ranked above those
options which were left unranked. AQ AW AZ & BF are considered
essentially equivalent in terms of which would be preferred over the
other.

Feel free to e-mail your ballot to me to keep the group from filling up
with the votes. I'll announce the results (if there are any to announce)
when I stop receiving votes.

If you're interested in the method I will use to determine the result,
you are welcome to ask me via a private message.

If this receives a sufficient amount of interest, I'll do more just like
it out of some morbid curiosity concerning what is the most preferred
(within well known limitations) style around here.

Nov 14 '05
60 3112
On Wed, 12 May 2004 12:17:18 -0400, eg******@verizon.net (Eric) wrote:
I thought it might be fun to run a simple vote to discover the most
preferred spacing style for a simple if statement with a single, simple
boolean test. By my count, there are 32 possible variations for this
case. Here is a complete list. AZ: if(a > b)
BA: if(a >b )
BB: if(a >b)
BC: if(a> b )
BD: if(a> b)
BE: if(a>b )
BF: if(a>b)


I like
if(a>b) or if( a>b && a>c && a>d )
I had no problem in small programs
(~=3600 lines are the upper bound of my programs)

but because it seems not legible from others and
because I think would be useful differentiate
{COM} = { ==, !=, >=, <=, >, <} [compare]
{ASS} = { =, +=, -=, *=, %=, /=, &=, |=, ^=, <<=, >>= } [assign]
{OPER1} = { +, -, >>, <<, &, ^, |}
{OPER2} = { ~, *, /, %}
{OPER3} = { &&, ||}
(for the precedence too ?[OPER2>OPER1>OPER3])

I will use
if(a > b) ....
for 1 equality

if( a>b && b>c )
for 2 or more equalities etc.
and if( (a = b(z))!=23 && a!=3 )

+=E{ASS} => a += b
==E{COM} => a==b [but in if() when 1 time only if(a == b)]
+ E{OPER1} => a + b
* E{OPER2} => a*b or *b
&&E{OPER3} => a && b
for me '(' and ')' doesn't help.
_______________
Lato A
L'esercito perfetto era quello di hittlher così oggi
tutti gli eserciti di professionisti (anche quello degli ebrei)
tendono ad imitarlo. Gli eserciti sono il problema e non la soluzione.
Lato B
La guerra è vergognosa; il popolo è contro
la guerra e se fanno degli attentati terroristici contro il popolo
colpiscono le persone sbagliate e fanno il gioco dei guerrafondai
fabbricanti di armi e quelli del lato A (perchè danno un motivo per le
guerre) e quindi sono loro *alleati*.
______________
Come giustificare la guerra?
Lo sapete quanti nel passato sono andati al macello nelle guerre con
la scusa della PATRIA?
Oggi tale parola tende a essere sostituita con parole come "LIBERTA'"
"SICUREZZA" "DEMOCRAZIA" ...
_______________
Sugli eserciti e la guerra

La terza parte del segreto rivelato il 13 luglio 1917 nella Cova di
Iria-Fatima.

Scrivo in atto di obbedienza a Voi mio Dio, che me lo comandate per
mezzo di sua Ecc.za Rev.ma il Signor Vescovo di Leiria e della Vostra
e mia Santissima Madre.

Dopo le due parti che già ho esposto, abbiamo visto al lato sinistro
di Nostra Signora un poco più in
alto un Angelo con una spada di fuoco nella mano sinistra;
scintillando emetteva fiamme che
sembrava dovessero incendiare il mondo; ma si spegnevano al contatto
dello splendore che Nostra
Signora emanava dalla sua mano destra verso di lui: l'Angelo
indicando la terra con la mano destra,
con voce forte disse: Penitenza, Penitenza, Penitenza! E vedemmo in
una luce immensa che è Dio:
“qualcosa di simile a come si vedono le persone in uno specchio
quando vi passano davanti” un
Vescovo vestito di Bianco “abbiamo avuto il presentimento che fosse
il Santo Padre”. Vari altri
Vescovi, Sacerdoti, religiosi e religiose salire una montagna
ripida, in cima alla quale c'era una grande
Croce di tronchi grezzi come se fosse di sughero con la corteccia;
il Santo Padre, prima di arrivarvi,
attraversò una grande città *mezza in rovina* e mezzo tremulo con
passo vacillante, afflitto di dolore e
di pena, pregava per le anime dei cadaveri che incontrava nel suo
cammino; giunto alla cima del
monte, prostrato in ginocchio ai piedi della grande Croce venne
ucciso da un *gruppo di soldati* che gli
spararono vari colpi di arma da fuoco e frecce, e allo stesso modo
morirono gli uni dopo gli altri i
Vescovi Sacerdoti, religiosi e religiose e varie persone secolari,
uomini e donne di varie classi e
posizioni. Sotto i due bracci della Croce c'erano due Angeli ognuno
con un innaffiatoio di cristallo
nella mano, nei quali raccoglievano il sangue dei Martiri e con esso
irrigavano le anime che si
avvicinavano a Dio.

Nov 14 '05 #51
eg******@verizon.net (Eric) wrote:
I thought it might be fun to run a simple vote to discover the most
preferred spacing style for a simple if statement with a single, simple
boolean test. By my count, there are 32 possible variations for this
case. Here is a complete list.

AA: if ( a > b )
AB: if ( a > b)
....

Ok, asymmetrical solutions are out from the start. Period.
Then, I dislike spaces on the inside of parentheses. They grate on my
eyes; they're not there in any other use of parens, especially not in
human language (you use parens like this ( not like this )).
Lastly, I like to make function calls and syntactical constructs look
different by omitting the space between a function name and its opening
parenthesis, but including one for if, while and the like.
These three requirements leave me with these two options:
AJ: if (a > b)
AP: if (a>b)
Now, the question was not about _an_ if statement, but about _this_ if
statement. That is, it is about comparing a with b, not comparing some
expression called a with some expression called b. In that, simplest,
case, I'll always use
AP: if (a>b)


and the same is true for any other comparison between two simple
identifiers or constants. If a and b are supposed to stand for
expressions, then the more complex a and b get, the more likely I am to
add the spaces.

Richard
Nov 14 '05 #52
Allan Bruce wrote:

x = (a == 3 ? 5 : 60) ;


won't that evaluate to
x = (a == 5);

or have i missed something about the ternary operator's precedence?
--
-- Charles Banas
Nov 14 '05 #53
Charles Banas wrote:

Allan Bruce wrote:

x = (a == 3 ? 5 : 60) ;


won't that evaluate to
x = (a == 5);

or have i missed something about the ternary operator's precedence?


Yes, you have.

x = (a == 3 ? 5 : 60) ;

is equivalent to

x = ((a == 3) ? 5 : 60);

--
pete
Nov 14 '05 #54
Charles Banas wrote:
Allan Bruce wrote:
x = (a == 3? 5: 60);
Won't that evaluate to

x = (a == 5);

Or have I missed something about the ternary operator's precedence?

cat main.c #include <stdio.h>
#include <stdlib.h>

int
main(int argc, char* argv[]) {
if (1 < argc) {
const
int a = atoi(argv[1]);
int x = (a == 3)? 5: 60;
fprintf(stdout, "%d = x\n", x);
x = (a == 3)? 5: 60;
fprintf(stdout, "%d = x\n", x);
}
return 0;
}
gcc -Wall -std=c99 -pedantic -o main main.c
./main 2 60 = x
60 = x ./main 3

5 = x
5 = x

Nov 14 '05 #55
"Mark A. Odell" <od*******@hotmail.com> wrote in message
news:Xn********************************@130.133.1. 4...
"Mabden" <ma****@sbcglobal.net> wrote in
news:to****************@newssvr27.news.prodigy.com :
I'm nervous about disagreeing with Dan Pop, but I also like:
>> >x = (a==3 ? 5 : 60);


for simple expressions. Also, I don't prefer parens when not needed, it
makes one have to go through a lot of paren counting if there is a bug.


Then drop the unecessary ones you have included. ?: is higher in
precedence than = so you can just write:

x = 3 == a ? 5 : 60;

Not to rekindle this argument :-)


:-) Ouch!

That has GOT to be the worst way to write readable code. I am not trying to
eliminate all parens, in fact I like unnecessary ones, for instance around
"sizeof (int)". I believe "x = (a==3 ? 5 : 60);" is the most readable way to
write that statement.

Remember people, we are professional writers. Your code should be readable
by others (and yourself months later). It's more important to be readily
understood than to be fancy, tiny, fast, or anything else.

--
Mabden
Nov 14 '05 #56
Mabden wrote:
I am not trying to eliminate all parens,
in fact I like unnecessary ones, for instance around
"sizeof (int)".


Those parens that you're showing there, are necessary.

--
pete
Nov 14 '05 #57

"pete" <pf*****@mindspring.com> wrote in message
news:40***********@mindspring.com...
Mabden wrote:
I am not trying to eliminate all parens,
in fact I like unnecessary ones, for instance around
"sizeof (int)".


Those parens that you're showing there, are necessary.


I think he maybe meant;

int a;
a = sizeof a;

Allan
Nov 14 '05 #58
"Mabden" <ma****@sbcglobal.net> writes:
Remember people, we are professional writers.


Some of us are. Others are hobbyists. Others fall into other
categories. Myself, I often write code for research papers that
has to work once--to produce results for the paper--and is then
thrown away. Sometimes this excuses otherwise nasty code.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #59
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote in message
news:c8**********@news.freedom2surf.net...

"pete" <pf*****@mindspring.com> wrote in message
news:40***********@mindspring.com...
Mabden wrote:
I am not trying to eliminate all parens,
in fact I like unnecessary ones, for instance around
"sizeof (int)".


Those parens that you're showing there, are necessary.


I think he maybe meant;

int a;
a = sizeof a;

Allan


Oops, yeah, I forgot they are needed on types. I put them in always, so I
don't need to remember that!

--
Mabden
Nov 14 '05 #60
Well, it's been several days without any additional votes. I received no
votes via e-mail. Here are the ones collected from the public messages.

AA > AJ > AG > AP > AQ = AW = AZ = BF
AJ > AZ
AJ
AJ
AJ
AJ > AA > AP > AZ > AG > AQ > BF > AW
AJ > AA
AJ = AP = AW = BF
AQ > AZ > AA > AJ
AJ > AZ > AP > BF > AA = AQ > AG = AW > AL = AN = BB = BD
BF
AJ = AP

I used:

http://www.duniho.com/remote-mamcalc.php

to determine the results. The winner is rather obvious...

AJ: if (a > b)

is the most preferred option by those who choose to vote.
Only 12 out of the 32 possible candidates were even ranked.
The order of finish was:

1st AJ
2nd AA
3rd AP
4th AZ
5th BF
6th AG
7th AQ
8th AW
9th BD
10th BB
11th AL
12th AN

The tie break position was:

1st AA
2nd AJ
3rd AG
4th AP
5th AQ
6th AZ
7th BF
8th AW
9th BD
10th BB
11th AL
12th AN

Please note that the order of finish may change slighly depending on the
tie break position. Please see http://alumnus.caltech.edu/~seppley/ for
a full description of the method being used.
Nov 14 '05 #61

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
by: craig | last post by:
I am curious about how many of you prefer style 1 vs. style 2, and why. Are there names for these style? style 1: method { }
144
by: Natt Serrasalmus | last post by:
After years of operating without any coding standards whatsoever, the company that I recently started working for has decided that it might be a good idea to have some. I'm involved in this...
29
by: Ron Burd | last post by:
Hi, As my company is moving into C# they are enforcing the use of styling convention in the source code, such as methods naming conventions, newlines, etc. Does someone know of products that...
4
by: Dotnetjunky | last post by:
Hi, So far, I've found tons of documents describing recommended coding standards for C#, but not a single piece on VB.NET yet. Anybody here knows such a coding standards guideline on VB.NET...
4
by: Mike Labosh | last post by:
I realize that you people have not seen much of me other than some framework responses I have posted. I am primarily a VB guy (yes, you can laugh) But I have lurked here for several years,...
13
by: benben | last post by:
Is there an effort to unify the c++ coding standard? Especially identifier naming. Not a big issue but it would be annoying to have to incorporate different coding styles simultaneously when...
3
by: ct-86 | last post by:
http://www.cdbook.cn/book.asp?id=2393 Organizational and Policy Issues 1 0. Don't sweat the small stuff. (Or: Know what not to standardize.) 2 1. Compile cleanly at high warning levels. 4 2....
7
by: Robert Seacord | last post by:
The CERT/CC has just deployed a new web site dedicated to developing secure coding standards for the C programming language, C++, and eventually other programming language. We have already...
1
by: Jim Johnson | last post by:
is this C style coding? I don't seem to see much C++ code in this way. is this a bad programming practice? code seem ugly coding this way. =================
7
by: MJ_India | last post by:
Style 1: struct my_struct { ... }; typedef my_struct my_struct_t; Style 2: typedef struct my_struct {
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.