type checking

Julian Fitzell julian at beta4.com
Mon Sep 5 17:38:11 UTC 2005


Hi Kalecser,

As Matej said, there's no "right" answer but that pattern is not a 
common one.  Usually you would leave that open because you could 
(sometime in the future) decide you want to pass in someother 
Entity-like object and it would be great if it worked.

If you wrote a method that expected a collection, for example, you might 
later decide it would be useful to pass in a ClassList object that you 
had created.  All you would have to do is implement the right interface 
(perhaps #do:, #add:, and #remove:) and you could pass it in instead.

In most cases, the class is not that important, it's the used interface 
that is.  We use parameter names to indicate the type of object we're 
expecting, which gives clues as to what interface might be required. 
Then you just run the code and the debugger will let you know if you're 
missing some part of the interface when you get a doesNotUnderstand.

So, if there's some reason why a particular class is absolutely 
essential, then sure throw an error: it'll make it more clear what the 
problem is.  Otherwise, you probably don't need to worry about it: if 
you pass an integer as a parameter that's expecting a collection you'll 
get another error pretty quickly as soon as some method tries to do 
something collection-like to the integer.

Hope that helps,

Julian

Kalecser Kurtz wrote:
> In smalltalk's dynamic typing aproach, do you think it's a good practice 
> to throw errors when the user try to use incompatible types?
> 
> For example:
> 
> - I create a class 'Mock' to mock general objects;
> - I create a class 'EntityMock' that is a Mock, but just to mock 
> Entities, once entities use doesNotUnderstand to resolve some of it's 
> methods;
> 
> So, if the user create a EntityMock with any other object than an entity 
> should the system warn him?
> 
> []'s Kalecser
> 
> -- 
> Tis the business of little minds to shrink,
> but he whose heart is firm, and whose conscience approves his conduct,
> will pursue his principles unto death.
> Thomas Paine
> 
> 
> ------------------------------------------------------------------------
> 
> 

-- 
   Julian Fitzell  --  Beta4 Productions
julian at beta4.com  --  http://www.beta4.com
Seaside: http://seaside.st/



More information about the Squeak-dev mailing list