About Smalltalk at: .... ifAbsent:/present:

stéphane ducasse ducasse at iam.unibe.ch
Tue Nov 30 10:48:52 UTC 2004


Hi andreas

It seems that:
>> - first it would be better to let the compiler compiles method with 
>> reference to classes that are not in the system and let the system 
>> complain at execution tim (marcus suggestion and he can explain that 
>> much better than me).
>
> I doubt this. Yes, all of these could be re-written as, say:
>
>    Foo ifNil:[self mumble].
>    Foo ifNotNil:[Foo bar].
>
> instead of
>
>    Smalltalk at: #Foo ifAbsent:[self mumble]
>    Smalltalk at: #Foo ifPresent:[:foo| foo bar].
>
> but the main point is that the latter two are very verbose in 
> conveying the intention that "yes, the caller is very well aware that 
> Foo may be absent and that the dependency is a weak one". If you know 
> how to read to the first one the same may be true but the latter is 
> just simply obvious in this regard.

I hope that marcus will explain what he thought :)

>
>> - second, it occurred to us that packages are missing in some cases 
>> because having a dependency mechanism
>> (I'm not sure that it is the solution) would make sure that the code 
>> needing to be invoked is present in the image by the structural 
>> dependency between packages or registration where optional code can 
>> be declared
>
> I don't understand that. The whole point of using "Smalltalk at: #Foo 
> ifAbsent:[]" is to declare a weak dependency, e.g., the presence of 
> Foo may be advantageous but is by no means required. Of course, a 
> dependency system could model these weak dependencies as well but only 
> at the cost of clarity (see above).

I will try to explain better.
If you know that you have package and that this the responsibility to 
package to make sure that
when one reference another class in another package there is a 
dependency between package or that there is a configuration that make 
sure that your classes are loaded together. Then you as a class writer 
(vs. a "package plugger together") do not have to worry about that. In 
the smalltalk code we wrote we never get concerned with that since we 
know that one package in loaded in the context of certain 
configurations.

>> We would really appreciate to get you open a browser, look at the 
>> code (clean if you identify some dead code, ugly methods ;)) and 
>> share with us your impressions. And what are the solutions you see, 
>> because it seems to us that there are far too much use of this idiom.
>
> I'm not at all convinced that this is a bad idiom. The only problem I 
> have with it is that it doesn't come up when you browse the references 
> to a class (but that problem is easily fixable if someone just cares 
> enough) and while you have made some points on how to "fix" the idiom 
> you haven't made a very good (or bad ;-) argument why to fix it to 
> begin with, e.g., why you'd think this idiom is problematic.

Ok I will try to explain what we are thinking. but watch out this is 
fussy but I'm convinced there is something. I have the impression that 
you end up with a lot of ifdef kind of structure.
and with a better package mechanism (right now we only have classes and 
not really package) we could separate these two aspects.
Is it clearer?

Stef





More information about the Squeak-dev mailing list