[vtk-developers] vtkMathTextUtilities and otherPrint test

David Cole david.cole at kitware.com
Tue Jul 10 14:09:07 EDT 2012


But.....

One more idea for a technique to avoid the goto:

Use a wrapper around PyObject * that automatically calls Py_XDECREF when it
goes out of scope. Is that the only thing you ever do in these cleanup
blocks? Seems like you need a smart pointer for PyObject.


On Tue, Jul 10, 2012 at 2:07 PM, David Cole <david.cole at kitware.com> wrote:

> There are 4,953 occurrences of "goto" in VTK 'master' today:
>   4,828 in ThirdParty/
>   125 in VTK itself
>
> If nothing else, there's certainly a strong cultural bias against the use
> of goto in VTK code.
>
> I don't like them, and I don't know anybody who really is a fan.
>
> But if you think your code is more readable and maintainable with them,
> then goto it.
>
> I am a very big fan of readability and maintainability. Although I really
> don't have a hard time reading either style... And just the presence of the
> "goto" makes my brain do a little double-take jump when I do see it.
>
> There is precedence for allowing "goto" -- albeit sparingly.
>
>
> David C.
>
>
> On Tue, Jul 10, 2012 at 1:48 PM, David Lonie <david.lonie at kitware.com>wrote:
>
>> On Tue, Jul 10, 2012 at 1:32 PM, David Cole <david.cole at kitware.com>
>> wrote:
>> > Instead of the goto's, how about something like:
>> >
>> >   bool err = this->CheckForError();
>> >
>> > if (!err)
>> > {
>> >    mplMathTextLib = PyImport_ImportModule("matplotlib.mathtext");
>> >    err = this->CheckForError(mplMathTextLib);
>> > }
>> >
>> > [snip]
>> >
>> > if (err)
>> >      {
>> >      // in case the error was an exception.
>> >      delete this->Parser;
>> >      this->Parser = NULL;
>> >     }
>> > }
>>
>> That would work, but I think it loses quite a bit of readability,
>> especially if applied to something like this (taken from a local patch
>> I'm working on):
>>
>> http://codepad.org/E1DVBfhY
>>
>> That snippet has a somewhat complicated loop and needs to clean up
>> objects in a couple of places mid-loop and also before returning. It
>> could be converted to something like above, but I still think gotos
>> are the best solution here.
>>
>> Is there an argument against them, other than that they're unusual in
>> c++? IMO I think they're fine in simple cases like these.
>>
>> Dave (the other-other dave)
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20120710/ad154411/attachment.html>


More information about the vtk-developers mailing list