Re: Why require __init__ to return None?

Thomas Kofler (kofler@ubilab.ubs.ch)
Sat, 28 May 94 01:15:15 +0200

Guido wrote:
>> I might imagine that __init__ returns None or self. If it returns self,
>> that means construction was ok. If it is None, construction failed.
>
>Not needed -- you can raise an exception.
Yes, correct. But just testing for None is often more compact:
try:
f= File('name');
except SomeException:
TellUser('opening name failed'); return;
# do the rest here
against:
f= File('name');
if ! f: TellUser('opening name failed'); return;
# do the rest here

Using exceptions can turn out to be complicated (IMO should be
avoided if possible). In the book "The Design and Evolution of C++",
Stroustrup cites Booch: "... is like a parachute. You do not need it
often, but if you need it, it is essential." BTW: The book is really
exciting and helpful ;-)

-- Thomas
----------------------------------------------------------
Thomas Kofler |Email: kofler@ubilab.ubs.ch
Union Bank of Switzerland |Tel: +41-1-236 4567
Bahnhofstr. 45 |Fax: +41-1-236 4671
CH-8021 Zurich, Switzerland |
----------------------------------------------------------