Coding Style

E

Ed Morton

E. Robert Tisdale said:
I see that you've already met some of our indigenous trolls.
If you decide to continue your subscription to the comp.lang.c newsgroup,
you will learn to recognize and ignore them.

A brilliantly insightful contribution. Perhaps we should add "savant" to
your title....
 
E

Ed Morton

Eric said:
Whether you'd consider using them or not is irrelevent. The only thing
that matters is whether you see any merit differences between them.

I'm not sure where the confusion arose, but I appologise for not being
clearer. By saying "I'd never consider..." I meant that as in your
original example:
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.

AJ and AA are ranked above all those options that I left unranked.

Regards,

Ed.
 
E

Eric

Default User said:
To what end? It's one of the more useless discussion around.

Why must fun have a purpose?

However, it does fit with another hobby of mine (which I also view as
fun) within which it would be quite useful.
 
O

Orhan Kavrakoglu

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. [snip]
So, rank the available options from your most favorite to your least
favorite.
[snip]

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

Case

Eric said:
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.
AJ: if (a > b)

This is K&R style and the most common I've seen over the years.
It's my style as well. I wonder what the C standard has to say
about this; I mean implicitly of course.

Kees
 
A

Allan Bruce

CBFalconer said:
The millenium has arrived, 1229 days late. Dan and I are in
complete agreement.

This is my preferred style too.
How about people style for the following?

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

Allan
 
D

Default User

Eric said:
Why must fun have a purpose?

For certain very dull definitions of "fun", I suppose.
However, it does fit with another hobby of mine (which I also view as
fun) within which it would be quite useful.


If it's as "fun" as the first item, please don't hesitate to keep me in
the dark.




Brian Rodenborn
 
D

Dan Pop

In said:
This is K&R style and the most common I've seen over the years.
It's my style as well. I wonder what the C standard has to say
about this; I mean implicitly of course.

The C standard uses the K&R style in its examples:

if (u.n.alltypes == 1)
if (sin(u.nf.doublenode) == 0.0)
/* ... */

Dan
 
A

Allan Bruce

Dan Pop said:
In <[email protected]> "Allan Bruce"

Why handle == differently than the other operators?

Dan

I like to keep the comparison as a single statement and then separate the
true and false conditions. I think the lack of whitespace at the start
clarifies what is being done. I think
x = (a == 3 ? 5 : 60) ;
is a bit messier. another example might be:
x = (someFunction(a) ? Value1 : Value2);

Allan
 
E

Eric

Default User said:
If it's as "fun" as the first item

Actually, it's far better.

I find the topic of single winner election methods to be fascinating.
Unfortunately, it isn't that easy to obtain genuine ranked ballots
because where a ranked ballot method is used in real life the actual
ballots are not generally made available because of privacy concern.

It is extremely useful to be able to collect real ballots so that
various resolution methods can be compared.

I personally do not believe it would be overstating the situation to
claim that using a good single winner election method, when three or
more candidates are available, would offer benefits to the whole of
society and I find working towards the betterment of society to be fun.

For more information:

http://en.wikipedia.org/wiki/Voting_system
http://electionmethods.org/
http://bcn.boulder.co.us/government/approvalvote/
http://en.wikipedia.org/wiki/Condorcet_method
http://en.wikipedia.org/wiki/Approval_voting

As a side note, the Debian Project
(http://en.wikipedia.org/wiki/Debian), which some of you may be familiar
with, uses a Condorcet Method to make certain decisions. Ever wondered
why?
 
C

Case

Dan said:
The C standard uses the K&R style in its examples:

if (u.n.alltypes == 1)
if (sin(u.nf.doublenode) == 0.0)
/* ... */

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

This closes the discussion; we must all obey the C standard. The
styles other than AJ are blatantly off-topic.

Kees
 
D

Dan Pop

I like to keep the comparison as a single statement and then separate the
true and false conditions. I think the lack of whitespace at the start
clarifies what is being done. I think
x = (a == 3 ? 5 : 60) ;
is a bit messier.

The *right* way of dealing with "messiness" is by adding parentheses, not
by removing white space. So, if you feel uncomfortable with

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

replace it by:

x = ((a == 3) ? 5 : 60);
another example might be:
x = (someFunction(a) ? Value1 : Value2);

Unless someFunction(a) returns a conceptually boolean value (like the
isxxx() functions from <ctype.h>), omitting the explicit text is not a
good idea.

Dan
 
A

Arthur J. O'Dwyer

How about people['s] style for the following?

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

I used to write

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

but these days I have taken to the style which I see is also
advocated by ERT:

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

It's shorter, and better parallels English typographical rules.
Note that I've dropped the parentheses around the whole ?:
expression, since I don't think they add to readability. They
certainly add to "non-ambiguity," but I would trust the reader
to figure out that reading the statement as
(x = (a==3))? 5: 60;
would be nonsensical. :)

-Arthur
 
M

Martin Dickopp

It is extremely useful to be able to collect real ballots so that
various resolution methods can be compared.

I personally do not believe it would be overstating the situation to
claim that using a good single winner election method, when three or
more candidates are available, would offer benefits to the whole of
society and I find working towards the betterment of society to be
fun.

But your poll is not very likely to produce different results with
different methods. To achieve that, you would have to pick an example
where people tend to vote "tactically" in a single vote system (like
"I want candidate `N' to become president, but he doesn't stand a chance
of winning anyway, so I'll vote for my second choice, candidate `K',
whom I still prefer over candidate `B'").
As a side note, the Debian Project
(http://en.wikipedia.org/wiki/Debian), which some of you may be
familiar with, uses a Condorcet Method to make certain decisions. Ever
wondered why?

No, never wondered why. The mathematical properties which make
Condorcet best-suited in this case are well-known, after all.

Martin
 
M

Martin Dickopp

Allan Bruce said:
How about people style for the following?

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

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

As soon as one of operands of the conditional operator gets slightly
more complex, I prefer
x = (a == 3
? 5
: 60);

Martin
 
D

Default User

Eric said:
Actually, it's far better.

Turned out to be far worse. At least the original question was
marginally on-topic.

You had no real interest in the subject, but instead wanted to waste the
of those on the newsgroup. Capital.

Oh, and:


*plonk*



Brian Rodenborn
 
M

Mabden

Dan Pop said:
In <[email protected]> "Allan Bruce"

The *right* way of dealing with "messiness" is by adding parentheses, not
by removing white space. So, if you feel uncomfortable with

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

replace it by:

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


Unless someFunction(a) returns a conceptually boolean value (like the
isxxx() functions from <ctype.h>), omitting the explicit text is not a
good idea.

I'm nervous about disagreeing with Dan Pop, but I also like:

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

Mark A. Odell

I'm nervous about disagreeing with Dan Pop, but I also like:


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 :)
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top