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: Kevin Crowston
Subject: Re: Clever code vs. readable code...
Date: Tue, 11 Nov 1997 14:46:38 -0800

>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...

...examples omitted.

>Right?

Yes.  (Except for the typo in the final line--[TheFNet addNode:
aFEntity]--it should be theFNet.)

>What does "entityList = [theFNet getNodeList];" do?

It asks theFNet to return the list of entities that have been added to the
graph, i.e., all of the nodes.

>Could the name stuff declared above the "unreadable" statement be
>included in my version of the same code?  Does it have to come before
>it?

Yes. It has to be before where you reference aName, i.e., the line before last.

>Is this an example where the programmer wanted to create "clever" code
>instead of "readable" code?  Why do people do that?

Well, readability is in the eye of the beholder.  One could argue that the
first version is in a way clearer because it's more obvious that all of the
messages are being sent to the same object, while in the second, you have
to look a bit to see that (you don't have to look very hard, mind you, but
you do have to check).  Alternately stated, every language has its unique
idioms which seem cryptic to those who don't know the language but which
are clearer and more obvious to those who do (C is full of these--and you'd
laugh at a BASIC programmer who argued that C was unreadable because s/he
didn't know them).

In particular, the use of cascading message sends is common in Smalltalk
and has been carried over by at least some to Objective-C.  Note also that
this style of coding assumes that all messages that don't return something
specfic return self instead, which is an Objective-C convention.  But it's
just convention--if you don't like it (e.g., having to rebalance the []'s
every time you add or delete a line), you can always write your code your
own way, just as some programmers write all programs as if they were in
BASIC (or COBOL, or whatever).  In particular, I think I've read that Swarm
doesn't follow the convention--messages that have no return value are
declared as void instead.

Kevin



                  ==================================
   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]