POV-Ray : Newsgroups : povray.advanced-users : movie within : Re: movie within Server Time
29 Jul 2024 04:23:48 EDT (-0400)
  Re: movie within  
From: Dan P
Date: 4 Feb 2004 20:32:59
Message: <40219d4b$1@news.povray.org>
"Darren" <dne### [at] sanrrcom> wrote in message
news:40219931$1@news.povray.org...
> Mike Raiford wrote:
> > Essentially you have this:
> >
> If you're a "structured programming" fan, the first makes more sense.
> What if a requirement comes up "by the way, print a message just before
> returning from this routine"? In that case, the former has a definite
> advantage.
>
> The cleverest solution I've seen is
>     still_good = true
>     if (still_good) {
>         still_good = operation1();
>         if (!still_good) handle it,
>             possibly setting still_good to true again.
>      }
>      if (still_good) {
>          still_good = operation2();
>          if (!still_good) handle it;
>      }
>      if (still_good) {
>          still_good = operation3();
>       and so on.
> Of course, with some languages, this can turn into
>      still_good = still_good && op1();
>      still_good = still_good && op2();

I like that approach because it forces the person to handle every case and
not be lazy about the way they do it. What that is doing is kind of like
what Java does, only the test is more implied in Java. For example, the same
code in Java-esque would be:

    try
    {
        operation1();
    }
    catch (Exception e)
    {
        handle it
    }
    ... and so forth.

If you are really smart about your exceptions, a big try block can be a lot
more compact:

    try
    {
        operation1();
        operation2();
        operation3();
    }
    catch (Operation1Exception e)
    {
        handle it
    }
    catch (Operation2Exception e)
    {
        handle it
    }
    catch (Operation3Exception e)
    {
        handle it
    }

or, even better, if they all send the same exception and the toString()
method on the exception contains useful output, this is nice too:

    try
    {
        operation1();
        operation2();
        operation3();
    }
    catch (OperationException e)
    {
        System.err.println(e.toString());
    }

What you described is a really concise way of doing it in C, I think. Also,
Visual C++ .NET has the try{} catch{} structure now. I'm not sure if the
latest version of g++ has something like that yet, but I wouldn't be
surprised if it did or does soon.

Thanks for the feedback, Darren, fellow RoadRunner enthusiast! :-)


Post a reply to this message

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