Stackless/microthreads merge news

Christian Tismer tismer at tismer.com
Sat May 13 15:41:18 EDT 2000


Glyph Lefkowitz wrote:
> 
> Christian Tismer <tismer at tismer.com> writes:
> 
> > > interface continuation{
> > >         public Object apply( Object[] ) throws throwable;
> > > }
> >
> > Sure. Does Java support function variables?
> > COntinuations must be callable objects, and I need to
> > be able to split them off of a running context at any
> > time. Is that possible without changing Java?
> 
> Of course not!  That might have the unintended side-effect of
> increasing programmer productivity! :-P
> 
> If you tell a java programmer that you want "function variables", they
> will tell you that it's easy ... a list of "function variables" would
> only require that you rewrite your code like this:
> 
> interface FunctionObject {
>     Object funcall (Object[] f);
> }
> 
> class AddFunctionObject implements FunctionObject {
>     Object funcall (Object[] args) {
>         double a = ((Number)args[0]).doubleValue();
>         double b = ((Number)args[1]).doubleValue();
>         return new Double(a+b);
>     }
> }
> 
> Vector v = new Vector();
> FunctionObject f = new AddFunctionObject();
> v.addElement(f);
> 
> ... later ...
> 
> Enumeration e = v.elements();
> while (e.hasMoreElements()) {
>         FunctionObject f = (FunctionObject) e.nextElement();
>         Object[] args = {new Integer(5), new Integer(3)};
>         Object result = f.funcall(args);
> }

Kotz!

> this being roughly equivalent to the python code:
> 
> v=[lambda x,y: x+y]
> 
> ... later ...
> 
> for f in v:
>     result=f(5,3)
> 
> But of course, java is "better", because it's "really object oriented"
> and in "real" languages, code isn't a first class object, or storable
> in variables.  A disturbing number of Java programmers believe that
> Smalltalk is this way too, and that block closures were just a weird
> abberation that nobody uses. (This is an oversimplified version of the
> Java version, of course.  You'd have to swaddle everything in 5
> different try { } catch (){} blocks before it would actually compile.)

We should give some torture to Java's inventors:

* force them to use it themselves *

(like forcing fast food producers to eat their own stuff)

> If you want to do this reflectively (I.E. use the method foo.bar on
> some object rather than writing your own code) it's possible, but it
> would be brittle (dependant upon strings for linking at runtime, so
> you don't get any lovely compiler checks for your code... and with the
> amount of typing you need to get anything done in java, you need those
> checks), slow (the linking would be re-done each time, since you'd be
> calling the reflective string methods), and hard (you STILL wouldn't
> be able to say foo.bar, you'd have to say "foo.getClass(),'bar', or
> similiar).  Not to mention the fact that if I wrote it here it would
> be so insanely verbose that internet customers in europe would be
> yelling at me for wasting their bandwidth.

*shudder*

I wonder how JPython retains Python's flexibility - using these
techniques? May be this is ok in JPython's generated code,
but for the user - forget it.

> only-a-few-more-weeks-to-go-before-I-never-touch-Java-again-ly y'rs,

let-me-sing-with-you-in-the-same-chorus-ly y'rs - chris

-- 
Christian Tismer             :^)   <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaunstr. 26                  :    *Starship* http://starship.python.net
14163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     where do you want to jump today?   http://www.stackless.com




More information about the Python-list mailing list