Hi,
In message "Re: "stereotyping" (was: Re: Strong Typing (Re: Managing metadata about attribute types) )"
on 03/11/22, "Sean O'Dell" <sean / celsoft.com> writes:
|Some of the things we gain were listed in the proposal.
|
|As to benefit: it depends on who you care about. Programmers, and especially
|library authors, gain a way to help people learn a little about their code
|and to catch potential errors in pitfalls. Project developers gain pretty
|much the same things: the ability to share code and help their co-workers
|understand a little more about their code and to help prevent them from
|making some obvious mistakes. We also gain some speed in debugging: where
|interfaces are used by people unfamiliar with the code they are calling into
|(through ignorance and lack of documentation) it's faster responding to a
|nice error message about type incompatibilities than it is to wonder about an
|error regarding method calls. Project managers are also far more likely to
|implement Ruby in their projects if they feel it is as safe as what they
|need, and type checking is one of the safety catches that a lot of people
|have grown comfortable with. It's also something Python doesn't have, and
|will be one of the things you can flat-out say "we have it, they do not."
|
|Worth it? In my opinion, absolutely.
In my opinion, not much. You've mentioned interface contract would:
(a) help learning code.
(b) gain speed in debugging by more check (and better message).
(c) make project manager feel better for more safety.
(d) allow us to say "we have something you don't have" to Python
people.
Among these, only (b) appeal to me. (a) can be done better by RDoc
documents. For (c) and (d), I don't care about selling Ruby to
anyone.
I prefer Jim Weirich's idea in [ruby-talk:86007], utilizing method
combination.
in the library code foo.rb:
require 'foo_if'
# which defines interface
# you can comment out from production code
class Foo
def greet(hi)
hi.display
print "\n"
end
end
in the foo_if.rb:
class Foo
def greet:pre(hi)
assert hi.respond_to? :display
end
end
with probably interface checking cosmetic.
matz.