Re: Static vs Dynamic

From: Kaz Kylheku (kaz_at_ashi.footprints.net)
Date: 10/27/04


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.



Relevant Pages

  • Re: Time to Say Goodbye, Delphi?
    ... > and eventually result in abundant Delphi jobs. ... I know Java and I managed to participate in at ... IMO, the context should be advertized, not the tools. ...
    (borland.public.delphi.non-technical)
  • Re: random array elements and speed
    ... NOT the type system of the language) of the ... context it's not clear what length, I use what_length, with "what" ... this sounds like a contradiction of: you can fit more on one ... It often has some explanation of all variables. ...
    (comp.lang.perl.misc)
  • Re: Abstract public member variales?
    ... specific context of processing streams of arbitrary objects. ... That's because what needs to be saved is a requirement on the save semantics for the particular problem. ... But a lot of OOA/D modelers would be content to leave the constraint to the abstract action language describing the instantiation dynamics in whatever method does the instantiation. ... one accesses a leaf object in the generalization tree. ...
    (comp.object)
  • Re: More static type fun.
    ... If you really believe that Common Lisp's type ... These are all within the context of the static typing discipline. ... seems to be that there is only one definition of "type system", ... suddenly change its mind and adhere to the static-typing community's ...
    (comp.lang.lisp)
  • Re: Cantor and the binary tree
    ... You deliberately snipped the context, ... Um, ok, here's the first finite tree I can think of (excuse ASCII-art ... In real mathematics that means that in an infinite tree, ...
    (sci.math)

Loading