L
Laurent Deniau
jacob said:True, but this makes the resulting language smaller.
pre- and post-conditions are not assertion, they are statements which
use assertions. This is just a convenient way to declare the contract.
This is why I put post-conditions between pre-conditions and the body
instead of after the body.
A beneficial side effect of this simpler design is that the
post-conditions can be very different according to which
type of return you use.
I do not understand this point. One feature of COS which is may be
useful for post-conditions is that you can still access the value
returned in the body even if the body has multiple return points.
Another subject matter:
What about the garbage collector Laurent?
Well, COS is in alpha release 0.2 even if it is more stable and tested
than some 0.99 releases ;-) Writing a GC is a huge task (more complex
than COS itself and *not portable*) so for the moment, COS is compliant
with the Boehm GC (see ownership p.3) for those who want one.
lcc-win32 offers a gc as a standard feature. Wouldn't this be an
advantage for OO programming in C?
Yes and no. Controlling the object allocation is not only in the spirit
of C, but it is also more efficient (in absolute about x3 for speed and
x1.5-3 for memory usage). And tuning a GC is also a difficult task
required in most large application (even Sun agrees with that).
With the COS ownership semantic, it is much simpler to manage memory
comparing to C and it allows much better tuning than GCs. People from
Objective-C are using it for a decade now with success.
I don't know yet if objects allocation (with or without GC) will be a
bottleneck for real applications since COS supports automatic objects
for fast local uses (where bottlenecks usually occur). But since
automatic objects are strengthened by multimethods -- a different
situation comparing to Objective-C -- it is possible that using a GC
would have no impact at all. If it does or if malloc is not enough
efficient, I would probably import the allocator of OOC-2.0 (which is x2
faster than GNU malloc). But this is not my priority and the decision
can be postponed until a large amount of code is available to do some
tests at the level of applications.
Another point is that objects are bound to their classes by an id, not
by a pointer, which may lead to some problem with dynamic classes in the
presence of a GC. Not to say that the GC may see many inexistent
references in objects ids.
a+, ld.