POV-Ray : Newsgroups : povray.general : unexpected rotation result : Re: unexpected rotation result Server Time
8 Aug 2024 14:17:50 EDT (-0400)
  Re: unexpected rotation result  
From: Peter J  Holzer
Date: 5 Feb 2001 16:01:42
Message: <slrn97u21r.1qn.hjp-usenet@teal.h.hjp.at>
On 2001-02-05 16:14, Scott Hill <sco### [at] ncgraphicsnet> wrote:
>"Tom Melly" <tom### [at] tomandlucouk> wrote in message
>news:3a7e8c51@news.povray.org...
>> "PoD" <pod### [at] merlinnetau> wrote in message
>> news:3A7E8847.C9EFB12A@merlin.net.au...
>>
>> All in all, it reminds me of what someone at work told me. He is
>> an experienced programmer and script writer, but he always uses
>> brackets...
>
>    Most experienced programmers/scripters do - it's the safest way to
>get any language to do what _you want_, rather than what _it thinks you
>want_ ! E.g, what does 1+2*3-4 evaluate to ?

That one should be the same (3) in just about every programming
language. But there are more difficult examples. E.g., what is
(0x11 & 0xF0 == 0x10) in C? C has so many operators that even the
experienced C programmer gets confused sometimes. It gets worse if you
use several programming languages with slightly different evaluation
rules.

However, more parentheses are not always more readable. Where the
average programmer already knows the precedence (e.g, multiplication
before addition), they only clutter the display and make the reader
wonder why they were used. For example, I wouldn't write
    1+(2*3)+4,
although I would probably write 
    1 + 2*3 + 4
to enhance readability for the human reader.

Really religious application of parentheses is required in macro
processors which do simple string substitutions (like cpp or those of
many assemblers). Otherwise you get nasty surprises if you do something
like

#define twice(a) a*2
printf("%d", twice(1+2));

	hp

-- 
   _  | Peter J. Holzer    | All Linux applications run on Solaris,
|_|_) | Sysadmin WSR       | which is our implementation of Linux.
| |   | hjp### [at] wsracat      | 
__/   | http://www.hjp.at/ |	-- Scott McNealy, Dec. 2000


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.