Result of I need your experience - classification and comparison of languages
Alex Martelli
aleax at aleax.it
Mon May 13 04:28:01 EDT 2002
Gabriel Moreau wrote:
> I don't understand why Effeil is more safe than Sather because Effeil
> use covariance (not safe) and Sather contravariance (safe).
Sather is indeed safer, although covariance (admittedly unsafe!) is
sometimes quite handy indeed.
> One really nice features in Sather is Iterator you don't find in any
> other languages. You can find iterator in Ruby but they are not as nice
> as in Sather. Iterator are a very safe features because loop are clean
> and many bug comes from loop.
Sather iterators are indeed awesome and I highly recommend everybody
to study them, see:
http://www.icsi.berkeley.edu/~sather/Publications/toplas.html
Ruby's iterators are Smalltalk-like and thus "inside-out" with
respect to Sather's. The paper you can download from the above
URL presents a fair comparison (since Ruby's iterators are basically
what the paper calls closures/blocks) and, I think, shows the
superiority of Sather's approach. Traversing more than one
structure at a time is easy for Sather, not for Ruby.
Python's iterators are far closer to Sather's -- some minor details,
such as the fact that to get the next item from a Python iterator
you call .next() on it (or use it in the headclause of a for
statement), while a Sather iterator gives its next value whenever
you use it within a loop statement, are little more than syntax
sugar (Sather's sugar is nicer, Python's way simpler to retrofit
into an existing language;-).
Sather's iterators are _way_ more powerful than Python's because
Sather's can accept both "hot" arguments (evaluated anew each time
the iterator is called) and "once" ones (evaluated only at the first
call on the iterator). The flip side of this is a sentence in
Sather's paper that's a fair assessment: [Sather] "iterators are a
powerful construct and it is possible to write obscure and hard to
understand code using them". Python's are less powerful, but they
don't really present any mystery nor are they particularly prone to
producing obscure and hard to understand code.
All in all, if a totally new language was being designed I think
I'd go for something closer to Sather's iterators rather than
Python's, but its a delicate judgment -- the tradeoff between
maximal power and potential elegance vs potential obscurity and
lack of clarity is a crucial and difficult one. GvR, Python's
architect, has a great track record in getting most such tradeoffs
"just about right" (even though in the case of iterators and
generators he was of course constrained by backwards compatibility,
since they were being retrofitted into an existing language!).
Alex
More information about the Python-list
mailing list