[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Proposed new SRFI for immutable lists



Vassil Nikolov | Васил Николов scripsit:

>   By the way, some languages offer yet another approach, in principle
>   similar to the latter, but more procedural.  It is to make the object
>   construction protocol a little more elaborate so the user (not just
>   the implementor) can see object _allocation_ as a separate step from
>   object _initialization_.

This is commonplace in OO languages such as Smalltalk and Java/C#.  The
danger of it, of course, is that methods wind up being called on an object
before it is fully constructed, when its invariants do not yet hold.  In a
multi-threaded program, of course, this is even more likely to happen.
Consequently, more modern APIs provide a mutable builder object that can
have various setup methods called on it, and then a "done" method which
returns an immutable working object.  The builder can then be discarded.
This approach does not permit circularity, but runs far fewer risks.

-- 
John Cowan          http://www.ccil.org/~cowan        cowan@x
If you have ever wondered if you are in hell, it has been said, then
you are on a well-traveled road of spiritual inquiry.  If you are
absolutely sure you are in hell, however, then you must be on the Cross
Bronx Expressway.  --Alan Feuer, New York Times, 2002-09-20

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports