DependentsArray size how does it work ?

Marcus Denker denker at iam.unibe.ch
Wed Feb 8 13:32:26 UTC 2006


On 08.02.2006, at 13:58, nicolas cellier wrote:

>
> I did not understand how first implementation did work, but i  
> understood
> programmer's intention.
> I used this example to propose a clean understandable collection  
> extension:
>     ^self count: [:e | e notNil]
>
> What you're proposing above sounds a little bit like:
>     ^self count: [:e | true]
>


But of what help is that here? You would need to explain this, too.

> Apart writing the block argument, all code above is correct, tricky  
> but
> correct.
> At least, there is a programmer that can be proud driving me nuts!

You will find *a lot* of code of that quality in Squeak... part of  
that is
because Smalltalk is older than the style of programming that was  
invented
after people used it for some decades... and because there were other  
contraints
on the Alto than on today's machines (memory, performance, code size...)

And then there is a lot of stuff that's just bad design... e.g. done  
in a hurry because
you don't win with style points when you need to do finish a demo for  
next week.

The real question is, in general, how to re-engineer, improve and  
evolve such a
systems without breaking it, and especially without breaking the  
clients that use it.

Huge problem...

> Tricky code deserve either refactoring or implementation notes i  
> think.
>

indeed.

>
> I will try it this evening. if not redefined, then the whole class  
> seems
> dangerous to me and there might be other side effects.
>

It gets interesting when you look at the real users of DependArray. The
only place is

Array>>copyWithDependent: newElement
	self size = 0 ifTrue:[^DependentsArray with: newElement].
	^self copyWith: newElement


not directly obvious way of doing it, either: lazy convertion of empty
arrays, with the place where the real instanciation should have  
happended
nicely hidden...

        Marcus




More information about the Squeak-dev mailing list