Java: September 2003 Archives

Auto-boxing

| | Comments (0)

I’ve been thinking a bit about autoboxing, a new feature slated for Java 1.5 which is due out at the end of the year. This is basically an automatic conversion between primitive types (int, double, etc.) and their object wrappers (Integer, Double, etc.).

As far as I can see, this is just a bad idea, and the only reason it’s being considered is because C# has it. Sure, Java makes you jump though hoops when you’re using the object wrappers and there’s definitely an argument for changing something about how this all works, but autoboxing is just the wrong solution in every way. It hides what the language is doing for you in a misleading way.

Just one point: look at the overheads in Java involving object creation, better than they used to be for sure, but do we really want to add more?

Surely a far better solution would be to change the language and remove the primitive types altogether? Than it would also make more sense to allow the standard arithmentic operators to work with BigDecimal and BigInteger (maybe even adding a Complex class) as well. Remember, this is just the written expression of a program, a sufficiently smart compiler should be able to optimize this away based on context, this was supposed to be one of the main advantages of JIT compilation.

In theory, there should be no overhead to using the object wrappers in running code, after the first JIT run this hypothetical code:

for (Integer i = new Integer(0); i < 10; ++)
    // Do something here...

Should be no less efficient than:

for (int i = 0; i < 10; ++i)
    // Do something here...

Note that we could allow the standard operators to work on these ‘blessed’ classes, much the same way as the addition operator works for String concatenation today.

Working at the Weekend

| | Comments (0)

Again. Something I said that I’d never do again. Again… although at the moment I’ve not really got too much to do other than be here. Probably spend the rest of the evening coding on my current personal project, MEX.

Update: A bunch of the code that I started writing for Message Explorer has been incorporated into RvSnoop.

Dot Net

| | Comments (0)

I’ve just written my first .net program! (Using mono) It seems very similar to Java, I’m going to grab a book and have a play with it some more over the next few days.

Of source, I’m really trying to learn Lisp, but since the books I bought have been stranded in Vienna it seems like I may have to wait a few weeks for that.