[Date Prev][Date Next][Thread Prev][Thread Next][Author Index][Date Index][Thread Index]

Re: [zzdev] Proper abstractions



On Sun, 22 Oct 2000, Benjamin Fallenstein wrote:

> 
> Hi Tuomas--
> 
> I agree about abstractions, but the particular way you coded this one
> seems to be really clumsy to me -- a nameless inner class for each
> iteration. Why not use something like an enumeration, i.e.:
> 
> ZZAlternator i = new ZZAlternator(...)
> for(i.start(accursed); i.more(); i.next()) {
>     if(done.get(i.cell) != null) { i.stoppart(); continue; }
>     if(i.distance() > rows) { i.stoppart(); continue; }
>     col[i.steps() + cmain] = i.cell;
> }
> for(<every cell in col>) {
>      for(i.start(<current col cell>); i.more(); i.next()) {
> 		// plac the cell
> 	}
> }
> 
> Possibly we could even abstract out the recursion:
> 
> ZZAlternator alter = new ZZAlternator(...);
> ZZDimRecursor rec = new ZZDimRecursor(dims, alter, ...);
> for(rec.start(accursed); rec.more(); rec.next()) {
>     if(done.get(rec.cell) != null) { rec.stoppart(); continue; }
>     if(rec.distance() > maxdepth) { rec.stoppart(); continue; }
>     // (place cell)
> }

There are pros and cons. The reason for coding it the way I did was that I
want to get both the cell and the distance as parameters. The same class
can be used for other kinds of iteration too.

I like the paradigm of callbacks - possibly I'm just showing my Perl
background where something like that would have been especially easy, with
anonymous subroutines. For some reason I've never liked the idea of
enumerations. I don't know why.

Abstracting the dimension recursion is interesting but the question is how
much more complicated would it be. Keeping track of how you're placing
them in the grid seems difficult.

	Tuomas