POV-Ray : Newsgroups : povray.general : Question 'bout indentation (no flamewar) Server Time
12 Aug 2024 07:21:30 EDT (-0400)
  Question 'bout indentation (no flamewar) (Message 3 to 12 of 12)  
<<< Previous 2 Messages Goto Initial 10 Messages
From: Roland Mas
Subject: Re: Question 'bout indentation (no flamewar)
Date: 29 Mar 1999 13:22:14
Message: <m3emm8cg15.fsf@clodomir.rezel.enst.fr>
"Thorsten Froehlich" <fro### [at] charliecnsiitedu> writes:

>                         #if (A > 0)
> union
> {
>                         #endif
>     sphere { ... }
>                         #if (A > 0)
>     sphere { ... }
> }
>                         #endif

Nah.  Doesn't work.  The first sphere is indented and should only be
so if A > 0.

> OR BETTER
> 
> 
> #declare mySphere1 = sphere { ... }
> #declare mySphere2 = sphere { ... }
> 
> #if (A > 0)
> union
> {
>     sphere { mySphere1 }
>     sphere { mySphere2 }
> }
> #else
> sphere { mySphere1 }
> #endif

  Yes.  Works better, for sure.  I had thought of it, but it only
works for small scenes.  If you have plenty depending on A, it becomes
really hard to read.
-- 
Roland Mas

A man walks into a bar.  Bang.


Post a reply to this message

From: Nieminen Mika
Subject: Re: Question 'bout indentation (no flamewar)
Date: 29 Mar 1999 13:33:33
Message: <36ffc77d.0@news.povray.org>
Roland Mas <rol### [at] casimirrezelenstfr> wrote:
:   Suppose you have the following lines:

: #if (A > 0)
: union {
: #endif
: sphere { ... }
: #if (A > 0)
: sphere { ... }
: }
: #endif

:   How would you indent?

  In this case the #if statement doesn't stand for conditional code
execution (like 'if' in C) but for conditional parsing instead (like '#if'
in C) (it's often a bad thing that povray doesn't distinguish between these
two things).
  Conditional parsing (or compiling) is always a tricky thing. It makes
the code hard to understand almost always. It's also very hard to indent.
  In this case I usually do something like this:

#if(A>0)
  union {
#end

    sphere { ... }

#if(A>0)
    sphere { ... }
  }
#end

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Roland Mas
Subject: Re: Question 'bout indentation (no flamewar)
Date: 29 Mar 1999 13:45:51
Message: <m3pv5sjfs1.fsf@clodomir.rezel.enst.fr>
Nieminen Mika <war### [at] cctutfi> writes:

>   Conditional parsing (or compiling) is always a tricky thing. It makes
> the code hard to understand almost always. It's also very hard to
> indent.

Sure.  But in the case of POV-Ray, which behaves like an interpreted
language, the difference between conditional parsing and conditional
execution is non-existent.  To my mind.
-- 
Roland Mas

It would be hard to be deader without special training.
  -- Theatre of Cruelty (Terry Pratchett)


Post a reply to this message

From: Bob Hughes
Subject: Re: Question 'bout indentation (no flamewar)
Date: 29 Mar 1999 20:25:22
Message: <370027F3.1CC2D10B@aol.com>
I'll bite, even though I had such a hard time just now getting through
the "other" latest round of indentation threading.

#if (A > 0)
 union {
#endif
  sphere { ... }
#if (A > 0)
  sphere { ... }
 }
#endif

Sloppy indenting maybe but you asked. Guess I better explain my casual
indentation method just the same.
To me the #if's and corresponding #endif's are the priority in this and
aren't embedded in one another so are left-most, no need to indent one
or the other set. The union is second priority to me and inset once,
closing brace aligned with the union keyword. The spheres (final
priority) are equal objects and indented inward of the union; not
affecting one or the other such as in a difference, intersection, or
merge, so are lined up along the vertical column.
That too simplistic? Well now you know about my style, simple even if
not exactly understandable on down the pike.


Roland Mas wrote:
> 
>   Hi all.
> 
> I have a question about indentation.  I fear it might degenerate
> into another flamewar, but heh, such is life.  On the other hand, it
> might bring some arguments to Ken Tyler.
> 
>   Suppose you have the following lines:
> 
> #if (A > 0)
> union {
> #endif
> sphere { ... }
> #if (A > 0)
> sphere { ... }
> }
> #endif
> 
>   How would you indent?
> 
>   The point is: there are two different hierarchies that have nothing
> to do with each other /a priori/.  You cannot mix them, 'cause you end
> up with incoherences.
> 
>   The other point is: do you indent the first sphere?  At write time,
> you don't know whether the union will exist (if you did, the test
> would be useless).  So, do you indent the sphere as inside the union,
> or do you leave it unindented?
> 
>   Might be of some interest to discuss, although I'm afraid the issue
> is insoluble.
> 
> Roland.
> --
> Roland Mas
> 
> Sauvez les castors, plantez des arbres.

-- 
 omniVERSE: beyond the universe
  http://members.aol.com/inversez/homepage.htm
 mailto:inv### [at] aolcom?Subject=PoV-News


Post a reply to this message

From: Tom Melly
Subject: Re: Question 'bout indentation (no flamewar)
Date: 30 Mar 1999 03:34:26
Message: <37008c92.0@news.povray.org>
k.i.s.s. - i don't think using #if in the way you did is a good habit - many
languages would probably refuse to compile. Besides, standardised code is
easier to read, indent and debug.

Even in pov, i would have thought you might be vulnerable to future release
changes, since the usage wouldn't necesserely be preserved (I haven't tested
your code, but I assume it works in current versions).

I would suggest one of the following two versions (untested, so i apol. for
any mistakes):

#if (A > 0)
    union {
        sphere { ... }
        sphere { ... }
    }
#else
    sphere { ... }
#endif

Or:

union {
    sphere { ... }
     #if (A > 0)
         sphere { ... }
     #endif
}



your version:

> #if (A > 0)
> union {
> #endif
> sphere { ... }
> #if (A > 0)
> sphere { ... }
> }
> #endif


Post a reply to this message

From: Nieminen Mika
Subject: Re: Question 'bout indentation (no flamewar)
Date: 30 Mar 1999 11:45:29
Message: <3700ffa9.0@news.povray.org>
Tom Melly <tom### [at] aolcom> wrote:
: #if (A > 0)
:     union {
:         sphere { ... }
:         sphere { ... }
:     }
: #else
:     sphere { ... }
: #endif

  This is not good coding since you are repeating code unnecesarily.
  You should declare the repeated sphere code as an identifier and use that
identifier instead.

: union {
:     sphere { ... }
:      #if (A > 0)
:          sphere { ... }
:      #endif
: }

  This is not good coding either, since you get a warning when A<=0.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Johannes Hubert
Subject: Re: Question 'bout indentation (no flamewar)
Date: 30 Mar 1999 12:44:20
Message: <37010d74.0@news.povray.org>
Nieminen Mika wrote in message <3700ffa9.0@news.povray.org>...

>  This is not good coding
[snip]
>  This is not good coding either, since you get a warning when A<=0.

I would agree with your first assessment, since code duplication leads to
problems once you start to change code and forget to do it in all places
where you duplicated it.

However, I would disagree with your second opinion:
Getting warnings is not a bad thing in general, because they are just that:
"Warnings". They mean "Hey something here *might* be wrong, you're sure you
wanna do this?" and you always have the choice (as in the given situation)
to say "Yes, damn sure! ;-)"

So long,
Johannes.


Post a reply to this message

From: Nieminen Mika
Subject: Re: Question 'bout indentation (no flamewar)
Date: 31 Mar 1999 02:07:59
Message: <3701c9cf.0@news.povray.org>
Johannes Hubert <jhu### [at] algonetse> wrote:
: However, I would disagree with your second opinion:
: Getting warnings is not a bad thing in general, because they are just that:
: "Warnings". They mean "Hey something here *might* be wrong, you're sure you
: wanna do this?" and you always have the choice (as in the given situation)
: to say "Yes, damn sure! ;-)"

  Perhaps in this case. However in C (and C++) a warning is almost always
advisable and should be considered as an error message (this is what they
have taught me and this is what I have seen by experience).

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

From: Johannes Hubert
Subject: Re: Question 'bout indentation (no flamewar)
Date: 31 Mar 1999 03:29:11
Message: <3701dcd7.0@news.povray.org>
Nieminen Mika wrote in message <3701c9cf.0@news.povray.org>...
>Johannes Hubert <jhu### [at] algonetse> wrote:
>: However, I would disagree with your second opinion:
>: Getting warnings is not a bad thing in general, because they are just
that:
>: "Warnings". They mean "Hey something here *might* be wrong, you're sure
you
>: wanna do this?" and you always have the choice (as in the given
situation)
>: to say "Yes, damn sure! ;-)"
>
>  Perhaps in this case. However in C (and C++) a warning is almost always
>advisable and should be considered as an error message (this is what they
>have taught me and this is what I have seen by experience).

In general I agree with you.
Only sometimes warnings are just that. Especially this "union with only one
object" warning. I always felt it was rather useless. I can almost see how
this warning would have never been programmed if the programmer who did it
had felt a little less careful/paranoid that day ;-)

I once had a C++ project where there always showed up 2 warnings which I
knew exactly what they came from and why I could safely ignore them. After
some time I had grown fond of these two warnings ;-) and not seeing them
after a compile gave me a feeling of wrongness...

Anyway: Most C/C++ compilers allow you to specify warning-levels. For
example Visual C++ has 4 (I think) with 2 being the standard and 4 the most
restrictive. So by choosing (or agreeing) to the standard level of 2 I
actually say: Yes, I know there would have been additional warnings if I had
chosen level 4, but I am sure that I can ignore them...

Johannes.


Post a reply to this message

From: Steve
Subject: Re: Question 'bout indentation (no flamewar)
Date: 23 Apr 1999 14:45:51
Message: <3720A3DE.EF4C2401@ndirect.co.uk>
In C a warning usually means that I forgot to write the function
that was going to use that variable.  

Cheers
Steve

Johannes Hubert wrote:
> 
> Nieminen Mika wrote in message <3701c9cf.0@news.povray.org>...
> >Johannes Hubert <jhu### [at] algonetse> wrote:
> >: However, I would disagree with your second opinion:
> >: Getting warnings is not a bad thing in general, because they are just
> that:
> >: "Warnings". They mean "Hey something here *might* be wrong, you're sure
> you
> >: wanna do this?" and you always have the choice (as in the given
> situation)
> >: to say "Yes, damn sure! ;-)"
> >
> >  Perhaps in this case. However in C (and C) a warning is almost always
> >advisable and should be considered as an error message (this is what they
> >have taught me and this is what I have seen by experience).
> 
> In general I agree with you.
> Only sometimes warnings are just that. Especially this "union with only one
> object" warning. I always felt it was rather useless. I can almost see how
> this warning would have never been programmed if the programmer who did it
> had felt a little less careful/paranoid that day ;-)
> 
> I once had a C project where there always showed up 2 warnings which I
> knew exactly what they came from and why I could safely ignore them. After
> some time I had grown fond of these two warnings ;-) and not seeing them
> after a compile gave me a feeling of wrongness...
> 
> Anyway: Most C/C compilers allow you to specify warning-levels. For
> example Visual C has 4 (I think) with 2 being the standard and 4 the most
> restrictive. So by choosing (or agreeing) to the standard level of 2 I
> actually say: Yes, I know there would have been additional warnings if I had
> chosen level 4, but I am sure that I can ignore them...
> 
> Johannes.


Post a reply to this message

<<< Previous 2 Messages Goto Initial 10 Messages

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