Coding standards

R

Richard Bos

Chris Croughton said:
In the UK it has been for the last 40 or so years, unless they've
changed it recently (of course, almost all typesetting is done in
proportional fonts now so it isn't obvious).

Almost all typesetting has always been done in proportional fonts. Note
that type_writing_ is vastly different from type_setting_.
Checking a sample of books from both the UK and the USA on my shelves at
home, ISTM that only the two books I mentioned before clearly have
double spaces. All others have either a single, normal-sized space, or,
in one or two cases out of a good dozen, no more than a point or so more
than a normal space. What did show in a few of them (Penguin in
particular) is that space-capital combinations seem not to have been
kerned. This means that " W" and " T", both very common, appear loose,
while sequences like " B", quite uncommon, clearly show that the actual
size of the space is no more than normal.
It was certainly that way for dissertations when I took my degree
(University of Kent at Canterbury, UK, 1978).

Dissertations are different. For starters, they are (or at least were)
often typewritten and replicated using other methods than normal
printing, nor typeset and put on a press. With the print run of a normal
dissertation, this is probably more cost-efficient.
In professional typesetting, the post-terminator gap was still greater
than the inter-word one (how much greater depends on the typesetters).
But it was usually proportionally spaced, and so less noticable.

Odd, then, that I work for a publisher, and none of the systems we use
for typesetting have separate inter-word and post-full-stop spaces, or
even a facility to enlarge the latter by a percentage.

Richard
 
R

Richard Bos

infobahn said:
The whole point of the two spaces was an attempt to get around the
inflexibility of fixed-pitch fonts. In the days before proportional
fonts existed (which, from my perspective, would have been 1990 or
before, although of course other people here will undoubtedly have
encountered them much earlier than that),

Yeah. In 1440 or so :)

Richard
 
I

infobahn

Richard said:
Yeah. In 1440 or so :)

Touche'. :)

Of course, I should have said something like "the days before
typical desktop computers could deal properly with proportional
fonts", which gains accuracy at the expense of brevity.
 
M

Michael Wojcik

Checking a sample of books from both the UK and the USA on my shelves at
home, ISTM that only the two books I mentioned before clearly have
double spaces. All others have either a single, normal-sized space, or,
in one or two cases out of a good dozen, no more than a point or so more
than a normal space. What did show in a few of them (Penguin in
particular) is that space-capital combinations seem not to have been
kerned.

Interesting. I'd never noticed that, but I just compared some
Penguin editions with a few books from other printers and found the
same thing. Space-capital combinations weren't kerned within
sentences either (not surprising), so that for example the name "J.
G. Something" in one of my Penguin books had excessive spacing
between the initials.
Dissertations are different. For starters, they are (or at least were)
often typewritten and replicated using other methods than normal
printing, nor typeset and put on a press. With the print run of a normal
dissertation, this is probably more cost-efficient.

My dissertation, for Miami University, will follow the new rules Ohio
has established for its state universities: deposited as a PDF
document, single-spaced. Before these new rules, they were deposited
as printed (typewritten) documents and microfilmed.

The new rules mean that dissertations written at Ohio state univer-
sities will be available almost immediately and at little cost.

I'm writing mine in LyX, so the PDF is being generated by LaTeX and
a converter, which means it'll have whatever issues TeX has; but it
still looks far, far better than anything I've seen from, say, MS
Word.
 
A

Arthur J. O'Dwyer

Stephen Sprunk said:
E. Robert Tisdale said:
Albert van der Horst wrote:
Natt Serrasalmus wrote:

a = (b == c) ? d : e;

a = b==c ? d : e;

a = (b == c)? d: e;
[...]
However, aren't ? and : parts of a ternary _operator_, not _terminators_?

Yes, but their use in natural language makes a? b: c more comfortable to
me than a ? b : c.

I used to use 'a ? b : c', several years ago, but then switched to using
'a? b: c'. I don't care too much about making code /look/ like English,
but I do find that the two conventions have different connotations to me.

a ? b : c

seems to give equal "priority" to all three subexpressions. So if 'a'
were about as complicated as 'b' and 'c', and were equally likely to be
zero as non-zero, I might consider it reasonable to use that convention.
"Compute a, and then do either b or c depending on its value."

a? b: c

This convention, I read much more as an algorithm: "Is a? Then do b.
(Otherwise, do c.)" Running the '?' into the condition seems to
"minimize" its visual impact, and the asymmetry of the b--c relation
is visually emphasized.

So I tend to use the latter form these days, but I wouldn't find the
other style distracting in well-written code. This situation is to be
contrasted with the

if( a ) {
[...]
}

style, which I find annoying and distracting no matter how well-written
the rest of the code is!

-Arthur
 
C

Chris Croughton

a? b: c

This convention, I read much more as an algorithm: "Is a? Then do b.
(Otherwise, do c.)" Running the '?' into the condition seems to
"minimize" its visual impact, and the asymmetry of the b--c relation
is visually emphasized.

I read it all (but prefer spaces round operators) as "a implies b
otherwise c" (since they are expressions saying "do a" is not logical to
me, the verb should be 'evaluate' if anything). As far as I'm concerned
they shouldn't be too complex anyway, if the expression won't convert
fairly easily into English then it's probably better split up, possibly
as an if statement.
So I tend to use the latter form these days, but I wouldn't find the
other style distracting in well-written code. This situation is to be
contrasted with the

if( a ) {
[...]
}

style, which I find annoying and distracting no matter how well-written
the rest of the code is!

I agree, both the extra space and the open parenthesis on the if. The {
on the same line doesn't help either...

Chris C
 
M

Mabden

Mark McIntyre said:
Natt, a word of advce. E Robert Tisdale is well-known round here for being
a very inaccurate and misleading poster. Treat his advice with caution.

And don't take my word for this

Tisdale is a C guru and all his posts are correct and should be followed
by all C coders.
 
M

Mabden

CBFalconer said:
Keith said:
[snip]

If you set tab stops to something other than 8 columns, the result
will be a text file that can't be viewed properly without filtering
it through "expand" or using a text editor with the proper settings
(and 8-column indentation is too much for my taste).

Just use space characters; they don't take up enough room to be
worth worrying about.

Besides which you will normally find that a source file using
blanks and not tabs compresses better than the version with tabs.
The tabs don't even reduce the storage or transmission time needed!

Uuuuhhh.... I like spaces. But I don't like your chosen indent style.
You use x and I like y. What do I do?

ie: you use 4 spaces to indent, but I like 3. We both use spaces - how
do I switch yours to mine and still have the VCS ignore them...? (OK,
some allow "ignore whitespace" but the consultant refuses to load tools
we own, or buy it)

I have an old set of DOS utilities that will tabify and untabify spaces,
but that seem harsh in our "new and improved GUI world".

Is there a "GOOD" pretty printer that "does it all" for cheap, that are
flexible to my quirks?
 
M

Mike Wahler

Mabden said:
ie: you use 4 spaces to indent, but I like 3. We both use spaces - how
do I switch yours to mine and still have the VCS ignore them...? (OK,
some allow "ignore whitespace" but the consultant refuses to load tools
we own, or buy it)

Eh? The solution to a consultant who refuses to do
something is rather obvious. :)

-Mike
 
A

Albert van der Horst

So I use K&R as my day-to-day reference. It's unlikely to betray
me except in odd corners of the language which I'm unlikely to use
anyway. And yes, p53 is well-worn. Of course, I don't need that
information when I *write* code; only when I read it.

I glued the table on cardboard, covered it with transparent plastic
and trimmed the corners. It has withstood the years well.
It is page 49 on my copy.
Are you talking about K&R 2, by any chance?
The use to which the Standard appears to be most commonly put is
a stick to beat people with; this is a great shame.

Well, I needed it once to convince people that the result of
a comparison is 1 not -1. Normally this doesn't matter much,
but they had

#define TRUE -1

in a header file.



--
 
K

Keith Thompson

Albert van der Horst said:
Well, I needed it once to convince people that the result of
a comparison is 1 not -1. Normally this doesn't matter much,
but they had

#define TRUE -1

in a header file.

That's a silly definition, but it shouldn't break anything *if* it's
used properly. For example, something like this:

int condition = TRUE;
if (condition) ...

is ok. Something like this:

int condition = (x==y);
if (condition == TRUE) ...

will break, but this:

if (isdigit(c) == TRUE) ...

is broken for *any* possible definition of TRUE. (It might happen to
work sometimes, which just makes it worse.)

The comparison operators always yield 0 for false and 1 for true, but
any non-zero value is treated as true in a condition.

If the result of an expression is a condition (logically a boolean
value), use it as a condition; don't try to compare it for equality to
another condition.

On the other hand, anyone who would define TRUE as (-1) probably
doesn't know enough about C conditions to use it properly.

See also section 9 of the C FAQ, particularly 9.2.
 
I

infobahn

Mabden said:
Tisdale is a C guru and all his posts are correct and should be followed
by all C coders.

And God has asked everybody to send me ten major units (dollars,
pounds, euros, whatever) of their country's currrency. If we're
going for gullible, let's do it right.
 
C

Chris Croughton

And God has asked everybody to send me ten major units (dollars,
pounds, euros, whatever) of their country's currrency. If we're
going for gullible, let's do it right.

Please be prepared to receive 80 triangular rubber coins each 6800 miles
on each side. Sorry, the banks wouldn't exchange then for 10 Triganuc
Pu because they won't take "small change"...

(Did you know that 'gullible' isn't in the dictionary?)

Chris C
 
M

Mabden

Chris Croughton said:
Please be prepared to receive 80 triangular rubber coins each 6800 miles
on each side. Sorry, the banks wouldn't exchange then for 10 Triganuc
Pu because they won't take "small change"...

(Did you know that 'gullible' isn't in the dictionary?)

Obviously, you can never have the accuracy of a Tisdale, Fount of
Wisdom, and Prophet of the true C way.
 
T

Thomas Stegen

infobahn said:
And God has asked everybody to send me ten major units (dollars,
pounds, euros, whatever) of their country's currrency. If we're
going for gullible, let's do it right.

The problem with this guy is not that he is trolling, it is that
he is doing it so badly.
 
C

Chris Croughton

(Did you know that 'gullible' is in the dictionary?)

http://dictionary.reference.com/search?q=gullible

Heh, you looked it up! Of course it's in any decent dictionary of the
English language, but it's amazing how many people are gullible enough
to believe that it could be missing and go and look it up. That's the
point, it's an illustration of the word.
Please don't ask me to define "the dictionary". I won't ask
you either :)

It isn't in my Latin dictionary, or my German one (and probably isn't in
the Russian one, although I haven't checked). Overall, there are
probably more dictionaries without it than with it (more as in different
kinds, rather than in numbers published)...

Chris C
 
C

CBFalconer

Chris said:
.... snip ...

(Did you know that 'gullible' isn't in the dictionary?)

Says something about the QUI of your dictionary. Does the name
"Schlidt" appear in the credits?
 
T

Thomas Stegen

Chris said:
Heh, you looked it up! Of course it's in any decent dictionary of the
English language, but it's amazing how many people are gullible enough
to believe that it could be missing and go and look it up. That's the
point, it's an illustration of the word.

I have a feeling you have a point to make here...

:)
 

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

Similar Threads


Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top