Sean O'Dell
11/21/2003 9:14:00 PM
On Friday 21 November 2003 12:48 pm, Rasputin wrote:
> * Sean O'Dell <sean@celsoft.com> [1144 19:44]:
> > A: I don't agree that it helps you control your large team projects. Can
> > you offer more evidence?
> >
> > Q: Okay. We have to look to code quite often in lieu of project
> > documentation, and normally we look to the description of classes, and
> > the declarations of function parameters to determine how to make calls
> > and to understand how classes are designed that are unfamiliar to some of
> > the programmers on the team. Type checking would help us to know what
> > parameters are used by certain methods at-a-glance, which saves us from
> > having to spend time studying source code to figure things out.
>
> You're assuming the guy who wrote the library methods used this
> optional 'interface' extension. If he cant even be bothered to
> document his library, why would he do that? Wouldnt a class
> need to know in advance that it would be passed to an interface-aware
> method?
Because this is far simpler, and once started, cannot lapse. When he tests
his code, if he forgot to update the interface description, he'll get errors
that notify him. You can be mostly assured that the interface description
you see from a library is up-to-date, unlike documentation.
Convenience is a mighty strong catalyst for action.
> This seems to be using interface implementation to flag a class
> as suitable for use in a particular way. Thats just as much an agreed
> protocol between the method and the argument as a respond_to? approach,
> but respond_to? doesnt require such a fundamental change to the
> language (and thats what it would have to be, if it was really to be
> useful - I dont think an optional feature would please anyone).
The difference is: simply stating a class' purpose is easy. You do it once
and that's pretty much it. As you develop, though, the interface changes.
Keeping up with specific method documentation is much more labor-intensive.
If you have an interface description that you had to adhere to, you wouldn't
have the option of falling behind on updating it. Your code simply wouldn't
work until you did.
> D'd certainly like extensions to respond_to? so I could check argument
> type and count (think someone posted that earlier?) - but that could
> be mixed in, so I wouldnt be imposing this on those who didnt want it.
You can already do that now in Ruby, but perhaps an interface mechanism could
make that easier.
> > Q: Okay. When an unsuitable object is passed to a method, and that method
> > tries to call a method of the object that either doesn't exist or has a
> > different number of parameters than expected, an error occurs deep inside
> > the method and it's tedious figuring out how to fix what went wrong.
> > Some form of type checking would help us recognize our mistakes faster.
>
> But again, its less hassle to document your API than to do rigourous
> argument checking.
No, it's more hassle. To update a document, you have to open a different
file, and if you make a typo or just plain write it wrong, there is nothing
to stop you from doing so. Interfaces can be described in the same source
file as your class definition, so it's easy to find and update, plus, you
can't update it wrong, or your code gives you errors.
> It seemed like you were more interested in a way to know how an API
> will use your object. Why not send in a probe?
Because probes can sometimes cause damage, and the errors reported deep inside
may not be easily understood. It's a hit-or-miss proposition in there; some
people have no trouble diving in and reading someone else's code. I do it as
a last resort because I find it's a terribly inefficient way to debug.
> Thats a back of a beermat approach, but I reckon that coupled with
> some good unit testing frees you up from relying on the kindness of
> strangers, at least a little.
I just don't think that probing and unit testing alone does quite what I'm
proposing. My proposal provides a lot of assurance, a lot of understanding
right up-front, and I think will just plain make a heck of a lot of people
happy.
> Even if it only tests method name and argument count, that gives you all
> an interface would, without any changes to the API you are using.
Well, since classes can implement interfaces, the test can also check that
methods are being passed object that fulfill the interface contract. So, a
sort of type checking can be performed.
> The difference is API probing can be done with existing mechanisms,
> *optionally* and more importantly, they dont require both sides
> of the method to play by the rules. Or reach a consensus :)
We have probing already, and it functions for lots of people. Not everyone.
And not to the degree of ease and clarity some would like.
> > Q: Gee, alright, but I'm running out of reasons.
> >
> > A: Thus you are close to realizing the friviolity of your request.
>
> The pissing contest is getting old now, and its just drawing out a
> long thread to a longer one.
This was actually the start of it, as far as I know. You must have gotten
this post out of order, or read into things previously said that I didn't
catch.
> I think I share some of both sides viewpoint, but I dont want a
> Java'ed Ruby, and it seems that this interface idea is coming from
> that angle.
It is, it most certainly is, except for two things. One, it's not a
requirement, you can ignore it and never have to deal with it. Two, classes
that claim to implement an interface can still work dynamically and can add
their own methods. It's just an optional feature, not a whole new system
being imposed globally.
Sean O'Dell