Re: Static vs Dynamic
From: Kaz Kylheku (kaz_at_ashi.footprints.net)
Date: 10/27/04
- Next message: Matthew Danish: "Re: Static vs Dynamic"
- Previous message: Kenny Tilton: "Re: Lisp and GUI on Linux/Windows"
- In reply to: Darren: "Re: Static vs Dynamic"
- Next in thread: William Bland: "Re: Static vs Dynamic"
- Reply: William Bland: "Re: Static vs Dynamic"
- Reply: Darren: "Re: Static vs Dynamic"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Oct 2004 15:59:04 -0700
pyedarren@hotmail.com (Darren) wrote in message news:<ef14039.0410251915.6117eeef@posting.google.com>...
> Pascal Costanza <costanza@web.de> wrote in message
>
> Something about your post was bothering me after thinking about it:
>
> > My claim is just that Java's type system isn't very helpful because
> > there is a good chance that type errors that are flagged by the Java
> > compiler are not really errors
> [..]
> > Java's type system wouldn't hinder you to write straightforward code
> > this wouldn't be a problem, but there is again a good chance that you
> > need to write more complex code than necessary in order to convince the
> > type system to accept your code
>
> This I really don't understand becuse I never see this problem. All
> of the examples you have provided were based on flawed designs and
> flawed implementations.
>
> I guess this is why I have been defending Java. I have read many
> criticizms of Java but they always seem to use errored code or bad
> designs as the proof. To anyone who understands the language the
> response is obvious: "you broke it not the language." (Except your
> exception example which really does illustrate a weakness and that I
> conceded as a valid criticizm.)
>
> Do you have an example of a good OO design that Java forces you to
> implement in an ugly way?
I have an abstract syntax tree whose nodes are implemented as class
objects. The class hierarchy follows the phrase structures in the
grammar, and the tree is heterogeneous. One node might be derived from
a Declaration, another from Expression or whatever.
I want to do a particular traversal of the tree and perform some
operation at every node, possibly collecting information (such a a
syntax-directed translation or whatever).
The framework must support the selection of different kinds of
operations, and specializing them to the particular type of node that
is being processed.
E.g. I might want to use this to pretty-print the tree, to evaluate
it, or to translate it to some code. I may need a context object for
the traversal, and it would be nice if the operation also varied based
on the type of that context object.
The Lisp solution looks something like
(traverse #'generic-function tree context)
Inside the bowels of TRAVERSE, what happens is this:
(funcall func node context)
Dispatch takes place based on the type of both NODE and CONTEXT, so
you have total flexibility. Specify any suitable generic function, and
specialize its methods to any context type and node type however you
want.
> I am not talking about having to put in casts or more lines of code
> (generally we all type at 30+ words per minute but only generate
> 200-500 lines of code a day in any language, point being: brevity !=
> better), I am talking about something that hinders the developer and
> makes the code more complex.
What is better is:
- smaller patches to implement a change
- less stuff to *read* and *understand*
- ability to experiment with changes to the program without having to
make irrelevant adjustments just to get it to compile!
This last point is important. I've done some refactorings of Lisp code
where I didn't acually fix the entire program all at once. I
experimented with a risky change and ended up with a half-broken
program. But enough of that program worked that I was able to get it
running and test just the new modifications, being careful not to step
on the broken parts. Once I knew that I was going in the right
direction and thus ``de-risked'' the proposed change, I began to
ripple it through the rest of the program, gaining more and more
confidence as more and more of the program worked with the new data
structures.
- Next message: Matthew Danish: "Re: Static vs Dynamic"
- Previous message: Kenny Tilton: "Re: Lisp and GUI on Linux/Windows"
- In reply to: Darren: "Re: Static vs Dynamic"
- Next in thread: William Bland: "Re: Static vs Dynamic"
- Reply: William Bland: "Re: Static vs Dynamic"
- Reply: Darren: "Re: Static vs Dynamic"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|