Coding Style

M

Mabden

E. Robert Tisdale said:
No!

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

Not bad, but I prefer to have parens around the whole, and to keep the ? and
: separate since there are three distinct parts to the expression.

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

Eric

Martin Dickopp said:
But your poll is not very likely to produce different results with
different methods.

Regardless of whether it actually does or not, I am interested in the
result.
To achieve that, you would have to pick an example
where people tend to vote "tactically" in a single vote system

Not true.

It is entirely possible for different results to occur where people have
only cast (or we can at least assume this) sincere votes. You are
welcome to check out my ballot archives at:

http://www.ericgorr.net/library/tiki-index.php?page=BallotArchives

or, if you like, it isn't difficult to produce theoretical examples
where I would simple declare people have voted sincerely and yet can
produce a different winner even among the Condorcet variants.

By 'sincere vote' I mean that regardless of how other voters may or may
not vote, voter A will always have Candidate X ranked above Candidate Y.
 
M

Mark McIntyre

On Wed, 12 May 2004 21:47:49 GMT, in comp.lang.c ,


Thats a bit rude.

I'm sorry you feel that way.
The question you asked was which we preferred. Ed
answered that - AJ or AA.

I asked people to rank the available options from most to least
preferred, [/QUOTE]

He did, AJ or AA, equally ranked, the rest ranked in last place. By
defiunition surely, anything he'd not use is ranked last.
Is this clear now?

Its clear that you're imposing conditions akin to those psychometric tests
which require you to rank "potato" "elephant" "psoriasis" and "mars" in the
order which most reminds you of Jello, and from that reveals that you're a
mad axe murderer*

By the way I've just realised you're Eric Gorr the Troll from 2003. I
propose to therefore respond no further in this thread, and see how it
develops. If your posts return to last year's trollishness....

*I've always wondered about that. Where /do/ mad axes come from? And why
would anyone murder them?
 
M

Mark McIntyre

Actually, it's far better.

I find the topic of single winner election methods to be fascinating.

You need to get out more. And possibly see a specialist.
 
E

Eric

Mark McIntyre said:
By the way I've just realised you're Eric Gorr the Troll from 2003. I
propose to therefore respond no further in this thread, and see how it
develops. If your posts return to last year's trollishness....

Not a time period I am particularly proud of.

I apologize for all wrongs or offenses.
 
A

August Derleth

Thanks again Dan for your standard insight in this very important
matter! ;-)

Genius comes standard, I guess. ;)

(Ok, enough bad puns.)
This closes the discussion; we must all obey the C standard. The
styles other than AJ are blatantly off-topic.

Kees

Heck, that wouldn't be a bad idea in general: I don't think anything would
be lost if the C programming community as a whole chose /a/ standard
formatting style, and K&R seems as good a pick as any. The GNU indent
program can work wonders with code that looks like it was passed through a
meat grinder, so most human-produced code from the last 15 years should be
fine for mechanical reformatting (it might have a problem with the
'a*=b'/'a=*b' ambiguity of proto-C compilers).

Of course, that's never going to happen.

(Ironic that the GNU indent program should be so useful here, as the GNU
Project itself likes a much different style, which indent defaults to
unless you feed it the right command line option.)
 
R

RoSsIaCrIiLoIA

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.
 
R

Richard Bos

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
 
P

pete

Charles said:
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);
 
E

E. Robert Tisdale

Charles said:
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
 
M

Mabden

Mark A. Odell said:
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.
 
P

pete

Mabden said:
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.
 
B

Ben Pfaff

Mabden said:
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.
 
M

Mabden

Allan Bruce said:
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top