[Qt5-feedback] new Qt5 - great! - but: What about exceptions?
BRM
bm_witness at yahoo.com
Tue May 17 10:51:35 CEST 2011
----- Original Message ----
> From: André Pönitz <andre.poenitz at nokia.com>
> On Friday 13 May 2011 21:02:30 ext szyk100 wrote:
> > Hi all
> >
> > One of modern languages feature included in C++ are exceptions.
> > Exceptions have mainly one advantage and only one real disadvantage.
> >
> > Advantage is: clear separation "fast path" and error handling - for me
> > this is huge advantage and I realy like this feature. It is the same big
> > leap in programming as invention "code modularization" concept. I
> > suppose you think "who care about some excepitons", but we have only few
> > modern concepts in C++ and rule "full backward compatibility" stops many
> > great innovations (see: D or Python language features for comparision).
> > Ignoring such great feature as C++ exceptions is ununderstandable
> > self-limitation.
> >
> > The only real disadvantage you (Trols) mentioned some where on your
> > pages is that executables will grow 20% with exceptions enabled. But as
> > you known during last 6 years drives and memory modules grown enormusly.
> > And I suppose that situation is similiar like with OpenGL - this is very
> > common and maybe limited devices will disappear quickly from the market.
>
> There are several other disadvantages of _C++_ exceptions.
>
> - Throwing exceptions through "alien" chunks of code that are implemented
> in other languages or using different compilers, sometimes even for the
> same compiler with different complier settings is not guaranteed to work.
> We do use such code even at the core of Qt for e.g. event loops.
>
> - Exceptions practically belong to the interface to a class, yet there is
> no way to properly document it "in code". Even if exceptions specification
> would "work", a change in use in 3rd party code would influence Qt's
> interface.
>
> The only sane approach to exceptions in C++ is to not let them pass
> module boundaries. And that's basically what we have already by just
> saying "we don't create exceptions by our own, you can use them if
> you want, or use 3rd party code that does, but it's your responsibility
> to cope with what you get."
>
> I can go on for a while, code generation is certainly a _very_ interesting
> aspect (if _I_ had the time I'd push for using "new (nothrow)" whenever
> possible. Including error checking that can yield much tighter code then
> normal "new") but first and foremost:
>
> - Qt code right now is not exception safe. "Fixing" that is a _huge_ effort.
> You can easily sink a few months of work here. A few of the "maintainer
> wanted" items take significantly less effort, so from my point of view any
> free capacities you might have would be spent better otherwise.
>
> > Other your argument (but emotional in this case) was "historical
> > reasons" for not using exceptions. If we will still thinking like that
> > we could not using C++ for historical reasons (WinApi and Xapi or OpenGL
> > api) and stay with raw C language. With argument like that we can even
> > stay away from concrete and steel and using only stone and wood just
> > "for historical reasons".
>
> Nice rant. Unfortunately, that's not the Realm of Ivory Towers here.
>
Agreed, and I'd like to add one more note:
Exceptions make programmers extra lazy. Errors need to be handled as close to
the source of the error as possible to have truly robust and reliable code.
That may mean that you need to define error interfaces to retrieve error
information, and to propagate the errors up through those interfaces - but
that's part of writing good, robust, reliable code.
Exceptions, on the other hand, by definition push the work of handling the error
off to someone else; and if no one handles it (b/c they think it is someone
else's job or that it is too unlikely to happen) then it will simply crash the
program - something that should never be acceptable. In other words, they are
too easy to abuse and should be avoided like GOTO is - used where it absolutely
must be, but otherwise ignored.
So I very much agree with the standing of how Qt is now (and Google's code spec
that was listed) that Exceptions should be completely ignored, and if you want
to use them go ahead, but don't force the rest of the world that wants
applications that actually work all the time in a highly robust manner to use
them.
Ben
P.S. Sorry Andre - meant to send that to the list the first time.
More information about the Qt5-feedback
mailing list