swarm-support
[Top][All Lists]
Advanced

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

Re: Clever code vs. readable code...


From: Ken Cline
Subject: Re: Clever code vs. readable code...
Date: Tue, 11 Nov 1997 15:13:16 -0500 (EST)

On Tue, 11 Nov 1997 address@hidden wrote:

> All,
> I have been struggling with Manor's graph code and came to a conclusion
> about a statement, which I'd like to get confirmation about...
> 
> In BankModelSwarm manor has some code in -buildObjects which is:
> 
> for(i=0; i<population; i++) {
>   aName = malloc(10);
>   sprintf(aName, "FE%d",i);
>   [theFNet addNode: [[[[[[[FEntity createBegin: [self getZone]]
>             setCanvas: [theFNet getCanvas]]
>             setModel: self]
>             setFixedIncome: averageIncome]
>             setTotalAgentNum: population]
>             setEntityName: aName]
>             createEnd]];
>   }
>   entityList = [theFNet getNodeList];
>    ...
> 
> That one statement is the same as this (Right?):
> 
> //forloop
> //name stuff
> aFEntity = [FEntity createBegin: [self getZone]];
> [aFEntity setCanvas: [theFNet getCanvas]];
> [aFEntity setModel: self];
> [aFEntity setFixedIncome: averageIncome];
> [aFEntity setTotalAgentNum: population];
> [aFEntity setEntityName: aName];
> aFEntity = [aFEntity createEnd];
> 
> [TheFNet addNode: aFEntity];
> 
> }
> 
> Right?

I think there's a subtle difference between the two; you
can't write Manor's nested statement unless the `setCanvas:'
method returns an object that can receive the `setModel:'
message.  And `setModel:' must return an object that can
receive the `setFixedIncome:' method. And so on...

Also Manor's nested statement would be very different if one
of the `set' methods return an entirely new FEntity instead
of `self'.  To make your code exactly like Manor's you would
have:
       ...
    aFEntity = [ FEntity  createBegin:      [self getZone]      ];
    aFEntity = [ aFEntity setCanvas:        [theFNet getCanvas] ];
    aFEntity = [ aFEntity setModel:         self                ];
    aFEntity = [ aFEntity setFixedIncome:   averageIncome       ];
    aFEntity = [ aFEntity setTotalAgentNum: population          ];
    aFEntity = [ aFEntity setEntityName:    aName               ];
    aFEntity = [ aFEntity createEnd                             ];
       ...


Ken.


_________________________________________________________
Ken Cline                             address@hidden
SAIC                                 VOICE (410) 571-0413
Annapolis, MD                          FAX (301) 261-8427



                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]