Archive for November, 2005

Muito Sou Java

Geir talked again about Apache, Harmony, and Geronimo. It was
again basically the same talk, so I didn’t note much. He did say that
Intel’s contribution of the JCE framework (no providers, they use GNU
Crypto, Jessie, and Bouncy Castle for that) included 3000 test cases
– definitely need to investigate that for Mauve.

He also said that “Apache is not out to compete with anyone else”.
I don’t recall if this came from the Harmony part or the Geronimo part
of the talk. It seems to apply equally well to either. I’m not
really sure what this means, as in a way some kinds of competition are
inevitable and not contingent on our intentions. In the Classpath
world we’ve (for the most part) handled this by recognizing that,
while the VMs do compete in some ways, in general our interests — in
a solid, complete class library and in free Java implementations in
general — outweigh our differences. Start with that, work
together for a while, have a few beers and late night chats together,
and one day you wake up with real trust and a real community. (I know
Geir understands this in a deep way. This is for any journalists out
there looking for a controversy :-)

One way not to compete would be to work harder to cooperate, i.e.,
move license harmony back to the front burner instead of the current
situation, which is that the majority of folks on both sides (me
included) are just hoping it will magically fix itself. Magical fixes
just don’t happen.

Max Rydahl Andersen, JBoss

Max is a Dane living in Switzerland. Sometime I wonder whether
giving these personal details of the speakers crosses some line of
etiquette. I do it just to personalize these writeups in a small way.

This was about Hibernate 3.1 — what’s next. My first note is
that his powerpoint presentation was cool, in that he could highlight
parts of a slide with a yellow highlighter (software) pen, which
marked up the slide as if it were an image (i.e., not restricted to
textual selections). I wonder what program that is.

So what is new? JBoss is writing NHibernate, for one thing. I
wonder whether stuff like this makes Sun nervous. Maybe not — the
crowd at this event was pretty rah-rah-Java; and just like at the
Denver JUG I didn’t find anybody planning to move development to .NET,
which rather surprised me (e.g., I talked to a guy from a Delphi shop
that is moving to Java — not C#).

I don’t know diddly about Hibernate and I didn’t take many notes
on it as a result. The Hibernate eclipse plugin that he demoed looks
nice, though I don’t recall why. And, he said on the Hibernate web
site there is a “help wanted” search you can do, to see how you can
help out. This struck me as a nice idea and I think for Classpath we
should either have an automated “FIXME finder”, or perhaps “stub
finder”. Or, change the cpbot to assign you a “FIXME” to fix on
request. In case you’re, like, bored or taskless or something. Ha,
ha.

Sun’s View of Open Source

Simon Phipps gave a nice presentation on Sun’s view of open
source. This covered a lot of ground, with a lot of ideas, and
unfortunately my notes on it are rather fragmentary since I was sleep
deprived. Bah.

Early in the talk he made a prediction, which is that due to Peter
Jackson’s engagement with the fans (the parallel to an open source
company is obvious — breaking down barriers between supplier and
customer, having a conversation instead of an ivory tower), King Kong
is going to make money. Hmm. I will make a counter prediction, which
is that since monster movies are intrinsically boring, and that since
we’re all deadly tired of remakes, it will not do very well. This
film, sorry Peter, is already on my must-miss list.

Simon talked about one important aspect of standards, which is
that standards mean substitutability. The idea here is that if there
is a governing standard then you can switch implementations with
little cost.

However, according to Simon, neither open source nor open
standards is enough. And, dammit, my notes are so vague here as to be
useless.

My recollection is that this was a somewhat pro-Java (there are
standards) and anti-Linux (LSB being what it is) approach. He didn’t
say what standards cover Open Solaris though :-). My notes say that
he did tout the Debian/Solaris project. That was interesting to me
since I thought there would be a licensing smackdown here. Maybe that
will come from the FSF instead. Simon also talked a lot about the
CIO’s point of view, which is super important if you’re delivering to
enterprise customers. And, he made the point that the needs of
development are not the same as the needs of deployment (I think
meaning something like, open source alone is great for development,
but freedom in deployment requires the substitutability delivered by
standards).

I felt bad that I didn’t take better notes. This was an important
talk. I disagreed with a lot of it; as I remember it many of the
assertions were a bit too binary, whereas in reality there is a
continuum of, say, compatibility even if standards are in force — a
quick survey of C++ compilers is instructive (Simon, I suspect, would
argue, correctly, that C++’s approach is a poor one and that
Java-style test compatibility kits are more useful). Anyway, it is
hard to express one’s disagreement cogently when one doesn’t even
remember the material. Sigh.

ObjectWeb Consortium

Fran├žois Letellier gave a talk. He represents the ObjectWeb
Consortium, the makers of JoNAS. His talk was not very technical but
instead more economically focused. He was the only person at the
whole conference to mention the 4 Freedoms — bravo! And, any slide
about free software that mentions Nash equilibria and societal
externalities is cool by me. (Yes. Any slide.)

Once again though I fell down on the note-taking. He described
ObjectWeb’s approach as “open source with governance”. I think that
is pretty smart, as in general I prefer explicitness and transparency.
The GNU style (cf GCC) is more anarchic — there is governance but it
is often implicit, or largely embodied in tradition, or simply not
discussed much as if it were my crazy aunt who I keep locked in the
attic.

He said the software industry can best be viewed as competing
networks of firms. Good observation.

Update

Graydon pointed out I inverted the sense of an important clause.
Fixed.

Floyd Marinescu

Floyd is a
friendly guy, from Canada, formerly of theserverside.com, who is going
to launch his own site soon. It sounds quite good; I’m looking
forward to it and I’ll post about it when it is live.

Unfortunately I missed the first part of Floyd’s talk about trends
in Java, since I got locked in a bathroom. You’d think this would be
hilarious, but really it was just boring and mildly irritating. One
of the other guys called Bruno on his cell phone and after a short
wait maintenance physically removed the lock.

Floyd had many examples of AOP to present. I dislike AOP quite a
bit, since I think it violates the heuristic that says that it is
better to have local constructs be lexically signified. (There. I
put that in the most obscure and highfalutin way I could think of. Am
I pomo yet?)

I didn’t write down the examples but one idea was architectural
enforcement — where the AOP insertions can check that your code is
following some rule supplied by the framework. But see what I mean
here? It would be better to enforce these rules statically, using
compiler-level tools (perhaps in addition to dynamic checks if that is
really needed — though these too should, ideally, be done in a way
akin to verification).

About 15% of the audience planned to use AOP, and Floyd said this
was about what he found globally. Floyd is a gold mine of this sort
of information.

Dependency injection is a must-learn trend according to him. So
are annotations, everybody likes them. (C#’s influence on the
language is easily felt, but I suppose the web services guys would
have pushed for this regardless — look at xdoclet to see why.) I’m
probably going to use annotations for the next generation of GDirect,
for what it’s worth, as it is a natural fit. Floyd had a nice list of
known best practices for annotation use — most of these can be
thought up pretty easily, but it is smart to just distribute the
information like this, I think, to try to get good penetration of the
ideas early on.

He said that many shops are moving back to OO design and POJO
applications. I’m not really a J2EE type guy but I gather that this
is a change from how web applications are written today. The new
buzzword here is “domain driven design”, which really just means
“OO”. Buzzword proliferation is a disease and the UN ought to combat
it.

Scripting is a good “new” trend, with Groovy soaking up most of
the press gravy lately. Both NetBeans and Eclipse folks are
investigating scripting the IDE. Got Emacs? Though one nice thing is
that since the JRE provides a consistent platform, the scripting
language choices matter a lot less; you can pretty much write
scripting goo in any language you prefer.

“Domain specific languages” is also a new trend, just like it has
been for the last 10 years. “Software engineering” is the endless
renaming of existing ideas, and the history of it is largely the story
of IBM introducing the same ideas that it likes, over and over, with
different names each time, until they finally take hold.

Floyd also talked about Ruby on Rails (as did many here, mostly to
argue against it), and AJAX. (Ean pointed out that Project
Blackwood
, which got little uptake, is really just AJAX for Java
applets. This seems like a cool thing to revive.) Running out of
time he mentioned “SOA” (service oriented architecture). I didn’t
know what this meant, but this
explanation
seemed relatively clear.

To sum up he hit on something that was repeated a couple of times,
namely the importance of open source Java for emerging economies like
Brazil. “Emerging” is the official phrase — I heard it 2-3 times. I
think “developing” is reserved for poorer places.

I was glad to hear this from someone! There’s a quote I like
which goes something like: “Philosophy is the middle ground between
science and religion, open to attack from both sides”. This describes
work on gcj perfectly — the free software world and the Java world
are similarly unenchanted. The Brazilian Java community, though,
really gets what we’re about, and why we’re important, and this is why
I was so happy to come here to talk. The point here is, we have a lot
of free infrastructure below the JVM, and we have a lot of free
applications above the JVM — but that crucial middle layer is a
proprietary zone with all the attendant pitfalls. Our vision is to
change this, and we’re actually quite close to that.

Sou Java

A couple days later the Sou Java event started. This was held
only in Sao Paulo. The first talk was given by Robert Brewin, a
Distinguished Engineer at Sun. He is very tall, and one supposes this
is not unrelated to his lofty position. By contrast I suspect those
of us in the audience felt, suddenly, that we were Undistinguished.
He’s also an avid surfer.

His talk had the unwieldy title, “Java and the Developer, Platform
and Tools, Trends and Futures” and started with a joke about cariocas
(the Brazilian word for someone from Rio).

Some interesting facts: Brazil is number 4 in the world for
developer population, after the US, India, and the EU considered as a
whole. Also, there are apparently 4.5 million Java developers. (Now
one feels for Onno’s plight, as his job, I think, is to grow this to
some absurd number like 20 million.)

His talk is what I described in my notes as “a typical OSS talk”,
which is somewhat ironic considering that the JDK is not OSS. The
fact is, the folks I meet from Sun all understand OSS fairly well, and
sympathize, and even work on it in various ways (make no mistake
slashdotters — Sun is a major open source supporter), but also often
hold on to a fear about potential platform forks by unfriendly
entities (read: Microsoft). Personally I think these fears are
somewhat outdated, given that .NET exists, but nevertheless I can
sympathize. The existence of Classpath does complicate the picture
though, and my guess is that in this instance Sun will follow the
time-honored tradition of open-sourcing projects only once they are
already obsolete. Good news for Classpath, I suppose, but another sad
example of the inefficiency and short-sightedness of the system.

The various Sun communities look great on paper — big numbers,
like 7 million NetBeans downloads. More on NetBeans later, there were
many talks about it.

On to trends… Sun’s general trend is toward OSS and community.
Cool beans. This is exemplified by Open Solaris, which came up a
number of times during the week. Fun fact: apparently it took 5 years
and was quite expensive to turn Solaris into an OSS project.
Apparently they had to do a full code audit and contact many different
organizations to get a grip on the IP issues. So, this is another
area where OSS rocks; GNU projects basically all have a better paper
trail than this.

A Few Notes on Productivity

One point he made is that the complexity of programs is increasing
(which I agree is indisputably true) and that past metrics of programs
don’t apply. He said that nowadays programmers don’t write systems,
but instead integrate sets of systems. (This is true in the Java
world, the C world is still more like 1995, and the C++ world has in
some ways taken a fatal tack toward the deeper past.)

He also said that lack of productivity is a major concern. A few
talks echoed this concern over the next days, but I was struck by the
fact that nobody made an attempt to define what productivity actually
was.

My perspective is that productivity is about maximizing the amount
of functional, bug-free code that can be written in a given amount of
development time. Furthermore, a real measure of productivity would
recognize that more time is spent in maintenance than in development,
and skew results accordingly. From this perspective I think it
becomes pretty clear that some of Java’s design goals are on target,
particularly, “reading is more important than writing”. (And honestly
on this basis I have misgivings about generics… they are clearer in
some situations, and have caught a few buglets in Classpath, but are
actually quite complex for what they provide.)

Anyway, my thinking in this area has led me to conclude that what
Java needs is, most likely, features adding more quality assurance to
the language. Generally I translate this into Eiffel-like code
invariants to better support safe derivations, and perhaps some kind
of hygienic macro support to allow things like transactions and other
higher-level application-specific modifications of control flow while
preserving “lexicalness”. (This can be done currently using anonymous
classes, but the effect is rather clunky.) On the topic of macros
though it is generally agreed that I am a nut.

Back to the Party

Bob then talked about handling complexity, for which his remedy is
sensible standards and sensible simplifications. Also he thinks that
ease of development is important, meaning that attention must be paid
to the entire application lifecycle (agreed; and both Eclipse and
NetBeans are still missing important parts of this; for example
neither has a built-in bug tracking interface, let alone more complex
things like making releases or tracking cross-release API
compatibility). He says we shouldn’t consider just “tools” but should
also look at the platform and the language. To me this is a natural
continuation of the Java approach, which is to try to consider the
system as a whole (and which explains why the compiler and the library
are not fully separable).

Another remedy for complexity is focus, namely being able to
orient to the task at hand and avoid noise. In the Eclipse world,
Mylar is exploring this area.

He made a claim, without supporting evidence, that the new
enum support helps productivity. It probably does reduce
bug rates by some small degree, but I would say little given typical
Java coding practices. He also gave what my notes describe as a
“bogus example” of using annotations — annotations are cool and do
help, but I saw some disturbing evidence at this conference that
future Java programs, particularly in the J2EE domain, are going to
end up looking like “@ soup”.

Another quote: “applications can be too complex for most
developers”. I suppose that can be true. At our airport meeting,
Simon said that in his opinion programmers do not really use
programming languages, but rather use the associated libraries.
There’s truth in this and Bob’s point may be that a typical
application can provide a bewilderingly large API profile, with
overlapping abstractions, complicated deployment schemes, and the
like. All true.

In this vein, we’ve known for a long time that personality is an
important component of programming in most environments, likewise the
social organization of teams and corporations, and the emotional
skills of managers. There is a lot of room for improvement in this
area.

But, these talks are more narrowly construed and so Bob didn’t
dive into a psychosocial analysis of the typical Java hacker. Instead
he then gave a demo of writing a NetBeans plugin. NetBeans is coming
along well. I’ll post a full entry on it soon.

Brazil

I’m back from Brazil. This was a fairly bizarre experience — Sao
Paulo is enormously big (20 million people) and also the world’s best
argument for zoning laws; Ean Schuessler is a virtuoso of weird on the
level of Survival Research Labs; and for some unfathomable reason
Bruno refers to me only by my last name, which would seem military if
the city and its inhabitants weren’t so militantly disorganized.

Over the next few days I’ll write up my notes from this trip.
Well, the ones I can understand (I wonder what “The Big B! And on!”
might mean… all I can recall is that it is something snarky), and
the ones that are suitable for public consumption.

The chaos — and I don’t want to overemphasize this, as it was not
inconvenient and in fact lovable in a certain way — began as I got
through customs. Instead of seeing Bruno (or one of his countless
friends who he got to help him with the conference), instead I was
greeted by Simon Phipps holding a sign with my name on it. Simon is a
great talker and we sat at a cafe in the airport for a couple of hours
and had the first of the many interesting conversations I would have
over the next week.

Also I wanted to mention that Bruno and the rest of the Sou Java
crew did an excellent job with this conference. It was very well-run,
and both the speakers and the audience were excellent. Also the
organizers went far beyond the call to make sure we had an easy time
getting around in Sao Paulo.

Maratona

The first event was called the “Maratona 4 Java”. It took place
in a number of different cities around Brazil (and in Austin, TX). I
stayed in Sao Paulo for this, though. For this we went to a
university, seemingly hours away, which is big enough to be considered
its own city within SP.

Geir talked first, about Harmony of course. I didn’t take too
many notes on this, as it largely seemed to be the same talk he gave
at OSCON. However he did mention that he now works at Intel. And, he
mentioned the code contributions Harmony has gotten since OSCON;
namely some core class library code from IBM, some of the security
code from Intel, and various other bits. I was a bit surprised to
find that Tcl is now an Apache project. Also he mentioned about the
idea that it would be cool if Sun donated code to Harmony.

Flavio Bergamaschi

Flavio Bergamaschi from IBM gave a talk called “The IBM
Contribution to Apache Harmony”. Flavio is a Brazilian who lives in
England and seems to be a kind of senior engineer — one recurring
theme for me this week was that these larger companies have relatively
rich internal career paths, and many of the participants here had
“juice” but were not in management. I suppose that is one of the
benefits offered by employment at an enormous company like IBM or Sun.
As I (gracefully) age I find I think more and more about what my job
might look like in ten years, or twenty.

Flavio is super friendly and knowledgeable. He spoke in Portugese
so I mostly took notes based on his slides… which were quite good –
next time I give a talk I plan to make nice graphics and stuff like
that. Up until now I’ve been embarrassingly low-touch.

One note I have is, “functional units allows separable life-cycle
and trivial switching implementation”. I’m not totally sure what this
refers to, but I think to this idea that keeps coming up on the
Harmony list about managing the core classes via some OSGi-based class
loader scheme. I did finally think of a concrete benefit this could
provide — if you have a core library that depends on something like,
say, Apache’s commons-logging (think mx4j), you could use that while
not exposing its existence on the boot class path to application
classes (which is critical). Given that we haven’t actually run into
this in practice, though, I still suspect this approach is a lot of
complexity for little gain. I find the posts on the Harmony list
about this to be quite vague… be concrete, people, not abstract!

IBM’s medium term vision for Harmony is: run the Eclipse compiler
on it by 3Q05 (this works with the IBM Harmony contribution if you use
the closed-source VM they provided), run Eclipse and Derby by 4Q05,
and run Geronimo by 3Q06. I think gcj can do all of that today :-).
This is an aggressive schedule for a new project.

I took a quick stroll through IBM’s code contribution a few weeks
back. It includes a bunch of NIO-based character set encoders;
Classpath largely relies on iconv, so this is probably
worth picking up. (Though for gcj, it is less clear… one point I
make in my talks is that with gcj and Classpath, we efficiently reuse
a lot of other free software, which is good at development time and
good at runtime.)

Me

I gave a talk next, which was another revamp of a fairly standard
gcj talk I give — it covers our goals, what we can do, some
information about the implementation and the status, and a short demo
(in this case of Eclipse and of AWT). My notes on this are mostly
about my emotional state, as I’ve found that to be the most important
part of a presentation (once I realized that I have already mastered
the actual content). I thought it went pretty well overall.

In the question section, Geir suggested we revamp gcj-jit to work
properly. He also suggested that we hook into class loaders to
compile entire jars at once. We’ve discussed this before on the gcj
list, and unfortunately I think that, first of all, it isn’t trivial
as many class loaders do a lot of work by hand (I think the OSGi
loaders do this) — meaning that we would have to break our rule about
not requiring application-level changes. Also, compiling an entire
jar at once is notably unfriendly to the system (though we could use
aot-compile-rpm to work around this).

Evolving the Java Language

Next up were a couple of guys who, I think, came from the local
university. They had a presentation on evolving the Java language
that they got from Sun. I only read the slides of this talk as it was
given in Portugese.

The slides were quite nice though. They touched on a number of
things I think about in the isolation tank in the basement bathroom.
So, for instance, the slide about Java Principles said that Java is
designed with the idea that reading code is more important than
writing it, that simplicity matters (having a clear semantic model,
and having programs mean the same thing everywhere — in contrast to C
and C++). They are most interested in new features that improve
developer productivity while preserving simplicity and clarity; though
the slides didn’t indicate how the language designers go about
measuring this. Language design remains unscientific in this respect.

There was some mention of putting XML support directly in the
language, but they skipped this slide too quickly. I’ve heard of this
before but never really looked into it; hopefully I’ll pass on gcjx
maintainership before this, whatever it is, becomes real.

There was also a list of rejected features, which includes just
about everything that I hear requests for — multiple inheritance,
operator overloading, AOP, continuations, preprocessing or macros,
multiple dispatch, and multiple return values.

One point that was made is that Java is also a platform. Folks
can write their own languages which implement some of these features
and simply compile to the JVM. This won’t help with things like
continuations though, which I think would require VM support… I
asked about that but didn’t get a really good answer.

It sounds like javascript and/or groovy will be part of the
official platform soon, like in Mustang. We’ll name the next
generation VM “Yikes” in honor of this.

Update

Mark pointed out that I misspelled everybody’s name. I fixed
that.

Cacao and Eclipse

Today, for no readily discernible reason, I set up Cacao with Eclipse project files.
This gives another easy way to hack on Classpath — you can check out
Classpath, then check out Cacao, and as soon as it is done building
(this happens automatically) you will have a fully working Classpath
development environment. Changes to Classpath will be immediately
available to Cacao, so your development cycle will be nicely short.

Some folks (hi Mark) report that they can’t get the auto-building
to work in Eclipse, but it always works for me. I can go from zero to
a fully working Classpath development environment in about 15
minutes… maybe we’re using different versions of Eclipse or
something.

Thread Patterns

This
blog entry
is a must-read for anybody on the GCC lists. I wonder
whether the k00ks know who they are. Or, worse, if I am one ;-)

Snow

First snow here in Boulder. Incredibly late this year… a few
storms have come by but they’ve hopped over us and hit Denver instead.

Gdb Stuff

This
gdb patch
from Michael Snyder is pretty cool. It adds new
checkpoint and restart commands to gdb; the
former is used to save a copy of the debuggee’s state at the current
moment, and the latter is used to resume debugging at the saved point.
The implementation is nicely simple — make the inferior program fork
and just let it hang around until we’re ready to use it. This
functionality seems pretty useful; I often will do multiple debug
sessions starting at the same point, and this is a way to avoid
lengthy startup procedures. Maybe it needs a
restart-checkpoint command, which brings a new copy of
the inferior to the foreground, leaving a pristine copy waiting for
future restarts.

Also, any patch that adds a variable named
forky_forky can’t be bad.

This isn’t the only potentially cool thing going on in gdb-land.
Over the last few months there has also been a fair amount of talk
about debugging in reverse (here’s
one thread
). This is one of those features I’ve wanted for
years…

International Java Developers Conference

In a week or so I’ll be at the International
Java Developers Conference
in Sao Paulo. I’m very excited about
this! It is in Brazil, which is exotic and cool, and this year I’ve
just missed a few opportunities to give a talk there — it is good to
finally make it. But more importantly, Brazil seems to have a lively
free software scene and a lively Java development scene — so it is a
great place to talk about what we’re doing.

The conference
program
looks pretty interesting. I’m looking forward to meeting
the Sun guys.

Operator Overloading

This weekend I thought a bit about operator overloading in Java.
I thought I’d write up some of the things I considered.

Basic Approach

My first idea was something similar to what C# does — allow
essential operators to be overloaded, but not unusual ones like
|| or .. In C#, operators must be public
and static, so I would just copy that too. It is probably best to
introduce a new operator keyword, though we could just as
easily simply anoint magic method names like
operatorPlus. Since all operator uses are unqualified
(a Foo.+ b just looks too ugly), users would use
inheritance or static import to introduce operators into the scope.

If we use the operator keyword, then we have to
augment static import a bit to allow importing operators. I think
this argues slightly for simply picking special method names.

Since we would simply be translating operators into method calls,
no serious binary compatibility issues would arise. We could simply
define the rules for operators to map directly to the rules for
ordinary methods.

C# also synthesizes the compound assignment operators like
+= from primitive operators, if the compound operators
are not explicitly declared. This seems like a good idea to me.

We must also define how this interacts with boxing, but that is
also simple to do. The rule should be modeled after ordinary method
invocations, with the additional note that if the left hand side of a
binary operator is a primitive type, then we simply do not consider
non-static methods (i.e., we don’t box initially).

Additions

This would be pretty useful, but I can think of two possible
problems. The first problem is that it just seems nicer to allow
non-static methods as well. This is easily added, along with a rule
to search first for an instance method (in the left hand argument for
binary operators, or in the sole argument for unary methods), followed
by searching for a static method.

The second problem is that some operators are commutative, but
ordinary method definitions are not. Suppose you define
BigInteger.operator+(int). Now you can write
bigint+5 — but 5+bigint is an error. This
means you will end up writing a number of fairly redundant operators;
but it would be nice to be able to remove this redundancy.

C# and C++ seem to simply punt on this issue, which I suppose
makes sense. You might think about adding commutativity rules, but
that introduces an asymmetry for the situations where operators are
not commutative. Also, it makes searching for the operator method
strangely complicated.

More Ideas

Groovy apparently maps some operators onto already existing
methods, for instance mapping == to the
equals method. This is a cute idea, but I think it is
dangerous in practice. Sometimes you really do want to be able to
tell if two objects are identical, and equals is
frequently overloaded. We could resurrect this idea by having a
special interface that indicates that we want this sort of overriding
to happen automatically. We would then add new methods somewhere
(e.g., System) to allow un-overloaded equality
comparisons.

Groovy’s idea of mapping some comparison operators to
compareTo seems like a good one to me. It doesn’t suffer
from the same special problems as equality; we could automatically
override operators like > for any class which
implements Comparable. In fact, I think this should be
the only way to overload these comparisons.

One other thing to think about is whether the special operator
method names should simply be taken from BigInteger.
This approach would allow retrofitting of some operator overloading
onto this existing code without any library changes. Note that due to
the commutativity problem this would not be completely seamless -- so
for best results we would need to add new methods regardless. In my
opinion, though, this would not be a good idea, as methods
named add are not uncommon; they are used all over the
collections API, and turning all of these into + doesn't
seem smart.

Example

Here's an example of how we would add an operator to
BigInteger.

    // New special interface indicating that == and != should be
    // overridden.
    public interface ComparisonOperator
    {
    }

    public class BigInteger extends Number
      implements Comparable, ComparisonOperator
    {
      ...

      // Implement the smallest number of operators to let "+"
      // work.

      public BigInteger operatorPlus(BigInteger val)
      {
	return add(val);
      }

      // Rely on widening primitive conversion.
      public BigInteger operatorPlus(long val)
      {
	...
      }

      public static BigInteger operatorPlus(long val, BigInteger bi)
      {
	return bi.add(val);
      }
    }

    // Use it.
    BigInteger x = whatever();
    System.out.println(x + 5);

Efficiency

Currently, Java compilers will take an expression using the
special String addition operator and turn it into a series of method
calls on a compiler-generated StringBuffer object. In
a case with multiple additions, e.g. a+b+c, the compiler
will generate a single buffer and make multiple calls on it.

Unfortunately, I don't see a simple way to recapture this
efficiency for user-defined operators. It would be possible for the
compiler to notice a series of overloaded operators where each call
is resolved to the same method. And, for example, this could be
turned into a call to a varargs method:

    public static String operatorPlus(Object... args)
    {
      StringBuffer result = new StringBuffer();
      for (Object o : args)
	result.append(o);
      return result.toString();
    }

However, in this situation you end up creating a new garbage array.
Maybe this idea is the way to go, I don't really know. I suppose in
theory object creation is supposed to be cheap.

One thing I haven't considered here is the interaction between this
idea and type conversion operators. I think adding implicit type
conversion to the language is, most likely, a bad idea. It certainly
seems to hurt in C++. (If we did have type conversion, we could
handle this case by having a different type for all the intermediate
operators; in the String case this would simply
be StringBuffer.)

Implementation

I gave some thought to implementing this in gcjx. I think it
would be straightforward.

If magic method names were used, the parser would not need any
changes. Otherwise, we would have to add a new keyword (trivial) and
a change to static import (reasonably easy).

For semantic analysis, we would have to update the code for the
operators to handle this properly. That is quite simple, most of this
code is in two files. For instance, all of the simple binary
operators are handled in a single method.

For code generation, we could use a trick to make it relatively
simple. The idea would be that each operator class in the model would
hold a pointer to a method invocation object. If a particular
operator is in fact a call to an overloaded operator, this pointer
would be non-null. Then, an operator's implementation of the visitor
API would simply forward to this operator instead:

template<binary_function OP, operator_name NAME>
void
model_arith_binary<OP, NAME>::visit (visitor *v)
{
  if (overloaded)
    overloaded->visit (v);
  else
    v->visit_arith_binary (this, lhs, rhs);
}

I believe this approach would let us introduce this feature without
any changes to the back ends. (It would make some uses of the
visitor a bit odd -- for instance the model dumper would print method
calls rather than operator uses here. I don't think that is a major
problem. In any case this is fixable if we care enough, by adding
default implementations of a new visitor method to the visitor class
itself.)

Anti-overloading

Operator overloading remains a contentious issue. While in some
situations (namely, math-like things such as BigInteger or matrix
classes) it is clearly an improvement, in other situations it is
prone to abuse.

This is a big discussion, and I have a lot of thoughts on it, but
I want to actually finish writing this today; I'll write more on the
topic of the future of programming languages later. Meanwhile, I
think one common anti-overloading argument, namely their obscurity, is
definitively overturned by today's IDEs. If overloading were part of
Java, you wouldn't have to be confused about the meaning of a
+= appearing somewhere in the code -- F3 in Eclipse would
take you directly to the proper definition.

In sum, this was a fun thought experiment for a Saturday morning.
I don't think operator overloading is the most important feature
missing from Java, but it is often requested. Adding this to the
language would not break any existing code, would not greatly
complicate the language, the compiler or typical programs, and would
be clearly useful in some situations.

More Ajax

It turns out that a lot of folks are doing the ajax-based web
front page thing. Alexander Larsson told me
about Netvibes, but there is
also fyuze, Protopage, and (how could I have
missed this?) Google
Reader
. I would imagine that My Yahoo will move this direction
someday too.

Netvibes in particular looks amazingly similar to start.com.
Protopage is a bit different in that it appears to be more of a sticky
note and links holder — that’s a nice idea. I haven’t investigated,
I wonder if the pages are shareable. Anyway, the others should add
this functionality.

Services Versus Software

I found out about start.com last
week and I’ve been playing with it (even though it is written by MS,
boo). I think it compares very favorably to older “newspaper”
applications like My Yahoo. For one thing, the UI is notably cooler
– nice clean design. It seems to be a new-style Ajax application,
though as an end user I don’t really care much about its
implementation, just the result; namely that it is much more
interactive than Yahoo. I can click and rearrange things and it
happens immediately, rather than taking me to an intermediate edit
page. Also, with start.com it is immediately obvious how to go about
adding random RSS feeds — I didn’t even notice this feature of Yahoo
until writing this entry.

In addition to the UI improvements, it is better than My Yahoo in
another important way. start.com supplies a way to write gadgets,
which I gather are non-passive ways to integrate new feeds. And, as
gadgets are themselves just web entities of some kind, you can use
ones supplied by third parties.

So, that is cool.

The Problems

However, it occurs to me that this mode of deploying applications
has a major flaw: it can still only show me the world as viewed from
the server — but this is noticeably different from the world as
viewed from my machine. For instance, start.com can’t access the Red
Hat intranet. Nor can it access my bank accounts, or whatever
feed-like things I might happen to run privately (nightly test results
come to mind).

I see this as somewhat of an analog to the programming rule that
says that the structure of a program is a model of the structure of
the group that wrote it. In this case, my view is determined by the
relationships that start.com has, not by the relationships I have.

Analogies

Another analogous case is Google. Google does a great job of
searching the web and as a result we all use it dozens of times a day.
Rock on! But google.com only knows the public web, which is not the
same as my web.

Google-the-company, being smart, tries to solve this problem too,
by providing Google
Appliances
and Google Desktop Search.

But… once you accept this you’ve crossed that magical boundary
between services and applications, and all the usual rules for
software once again apply. In particular, why install some random box
on your internal network unless it is running free software under your
control? We just spent the last 15 years getting away from that!

Differentiate And Abstract

I think we need to clearly differentiate between data sources,
presentation, and UI implementation.

Data sources are the classic kind of “service”, and that is really
all I want from the web. In particular I don’t want a UI mixed in
with a service, as it is not going to be able to integrate all the
data sources I need.

What this means is that the presentation must be local, not
remote. So, the aggregator has to be a local program under my
control.

However, this does not necessarily mean that this program’s has to
be some typical C/Gtk thing. Ajax is perfectly fine — provided it
meets the usual user expectation requirements. I don’t see any reason
why the aggregator couldn’t be running inside a local web server.