Readable code (Was: Re: [H-GEN] Which is better?)

Greg Black gjb at gbch.net
Wed Apr 28 20:51:04 EDT 2004


On 2004-04-29, Byron Ellacott wrote:

> He's also trying to suck me into the thread, I swear it, it's not my
> fault.

And now you've sucked me back into it (briefly).

> However, many languages don't really give you divide when you tell them
> to '/' two values.  C, for example, does an integer divide, which
> truncates its result.

This is wrong[0].  For the arithmetic operators, the operands
are subject to "the usual arithmetic conversions"[1].

This means that if one of the operands is a floating point type,
the other operand is converted to that type; if they are both
floating point types, then both are converted to the larger
type.  The operation is performed in that type and the result is
of that type.

Furthermore, even for integer division, truncation is not the
whole story.  If both integers are positive, it's correct.
However, where either operand is negative, the result is
implementation-defined[2].

> I like Python[3].  Python means noone's going to give me a piece of code
> with unindented blocks, not unless they're also saying, "My Python code
> doesn't even compile, let alone run!"

Yup, this is one of the best things about Python.  Mind you,
indent can fix C code to the form I want and I refuse to read it
otherwise.

Cheers, Greg

[0] At least, according to C89; I have not checked C99, but it
    would be a mistake if they had changed this.

[1] AS 3955-1991 (ISO/IEC 9899: 1990) Section 6.2.1.5 "Usual
    arithmetic conversions".

[2] Ibid. Section 6.3.5 "Multiplicative operators".
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 249 bytes
Desc: not available
URL: <http://lists.humbug.org.au/pipermail/general/attachments/20040429/07d9eb3c/attachment.sig>


More information about the General mailing list