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

Re: zed: When will the new PI be done?



On Wed, 2002-03-06 at 22:05, Peter Zelezny wrote:
> I don't know if I like this idea. Why not just make xchat.get_info(ph, id)
> available under python? Trying to make all these objects like User,
> Channel etc, seems like too much work for little effect. 
> 
> Can fields of a class/object be dynamic anyway? What if someone does user.abc
> (abc being a new field added later) on an older version of xchat? Under
> the C-plugin interface, it'd just return NULL and no problem, but wouldn't
> python throw an error?

Just to lend a little insight, in Java, you could have, say, a Session
class, with the method:

  Object get(String fieldName)

Then, you pass the name of the field you want as 'fieldName', and the
return is an arbitrary object, but you don't know what type it is. (You
have to run tests on its type via 'instanceof', or cast it if you
already know its type or if it's OK to throw an exception from a failed
cast.)

When this 'get' method creates the new object to be returned, it does
need to know what kind of object to construct, so I need to have a
facility for asking X-Chat what the proper type is for a given field, so
that we can construct the proper kind of object here. (Or you can return
a null type somehow, if the field doesn't exist.) I _don't_ need to have
a list of the fields' names -- just the type of a field given its name.

There would probably be some other convenience methods for accessing
fields, like:

  String getTopic()

This would just be a wrapper around the generic 'get' method above,
though. It would be written something like this:

  String getTopic() {
    return (String) get("topic");
  }

Here, it gets the topic, casts it to a string, and returns it.

And no, it's not possible to make a class with fields/methods that are
dynamically created. They have to be there at compile time. That means
that the Java classes (eg, Session) need to be updated when some fields
are added/removed, to add the appropriate methods in Java. If you try to
run some Java code that's designed for a newer version of X-Chat than
what it's being run on, and it tries to access a method that doesn't
exist in the older version, then an exception will be thrown. The Java
code trying to access this method is allowed to catch the exception and
recover, so as to be made backwards-compatible.

Or the Java code can use the generic 'get' method, in which case it will
get a 'null' return for nonexistent fields, and will have to check that
and deal with it appropriately.

Regards,

Alex.

-- 
PGP Public Key: http://aoi.dyndns.org/~alex/pgp-public-key

-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s:++ a18 C++(++++)>$ UL+++(++++) P--- L+++>++++ E---- W+(+++) N-
o-- K+ w--- !O M(+) V-- PS+++ PE-- Y+ PGP+(+++) t* 5-- X-- R tv b- DI
D+++ G e h! !r y
------END GEEK CODE BLOCK------

This is a digitally signed message part