RAII is a Paradigm (Was: Re: Google's Go & Exceptions)

John D jdean at googling.com
Fri Jan 29 23:07:21 PST 2010


"Walter Bright" <newshound1 at digitalmars.com> wrote in message 
news:hjnrej$1kpc$1 at digitalmars.com...
> Justin Johansson wrote:
>> (1) For some reason (possibly valid only in an historic context), I 
>> have this great aversion to throwing exceptions from inside C++ 
>> constructors. From memory, I once threw an exception from inside a 
>> constructor
>> with an early C++ compiler and wound up with stack corruption or 
>> something like that, and consequently I developed the practice of 
>> forever more avoiding throwing from inside a C++ constructor.
>
> I'm a believer in the methodology that a constructor should be 
> "trivial" in that it cannot fail (i.e. cannot throw).

Me too. (It's not "a methodology" though, just a style or coding 
guideline/requirement).

> I'm probably in the minority with that view,

C++ is called a "multi-paradigm language", but one of the most widely 
used paradigms of C++ is never included in the list along will OO, 
generic, procedural, etc. The one curiously omitted from the lists is 
RAII. That "lil thing" will PERMEATE a program's architecture. I'm of the 
persuasion that Initialization Is Not Resource Aquisition (IINRA). At the 
very least, RAII violates the principle of Separation of Concerns. More 
of a problem though is that RAII paradigm FORCES you to use exceptions 
rather than another/other error handling technique(s): it takes away your 
choice and sucks in a complex language feature and all its surrounding 
issues.

> but you shouldn't feel like you're doing the wrong thing when you stick 
> to such a style.

(That's better: "style" instead of "methodology").





More information about the Digitalmars-d mailing list