Java Literally Sucks

May 4th, 2008

I use Java at my day job and I find it frustratingly verbose and confining. One thing that particularly bothers me is that I can’t easily represent literals.

Java adopted C’s convention for arrays:

    int[] x = {1,2,3}

which work fine if I want to use arrays; but I rarely use arrays because I like OOP and I usually want to do things with my data structures like call methods on them. So, I typically use a list which I could declare like this:

    List l = new ArrayList();
    l.add(1);
    l.add(2);
    l.add(3);

… but I don’t do that because I don’t like warning about not using generics properly so I usually declare the list in this even more verbose way:

    List<Integer> l = new ArrayList<Integer>();
    l.add(1);
    l.add(2);
    l.add(3);

The problem with both of these alternatives is that you really can’t “see” a list. You just see an allocation of a list container followed by three method calls. This really obscures the data structure in unnecessary logic.

Sometimes, in an effort to make my data structures less obscure, i create a list like this:

    List<Integer> l = Arrays.asList(new Integer[]{1,2,3});

Of course, this isn’t really a good idea because that list is immutable but it looks like it’s mutable which is kind of scary and weird to anyone who might expect this list to support operations like ‘add’ or ‘remove’ defined in the List interface.

To get around that problem, I’ve seen code that looks like this:

    List<Integer> l = new ArrayList<Integer>(Arrays.asList(new Integer[]{1,2,3}));

which is, well, ridiculously awful.

This problem only gets worse when I want to do something outrageous like define a map for which I have no primitive like an array to help me out. This leads to a long series of put() invocations which makes me a little nauseated.

The fundamental problem is that Java has no literal representation for basic data structures. I’d argue that this deficiency led to the proliferation of XML in Java projects for defining data. I can’t think of another language whose users get so much pleasure out of something like Spring. Ruby users wouldn’t understand why you’d want to model parts of your application in a markup language: why not just use Ruby?

Oskar and Mavis Play Tetherball

April 14th, 2008

SmugMugExport 1.0.6

April 5th, 2008

I just released SmugMugExport 1.0.6 which provides support for new SmugMug security features and also allows you to edit albums. Check it out!

SmugMugExport 1.0.5 Released

March 2nd, 2008

I just released SmugMugExport 1.0.5. The big new feature is Growl support. The release also fixes some bugs.

More Hillaryous Videos

February 20th, 2008

I take back all those things I said about Hillary being out of touch.

found at Fake Steve

Hillaryous

January 21st, 2008

Found that at Maud Newton’s blog.

PyXML on Leopard

January 17th, 2008

I attempted to install PyXML on Mac OS X 10.5 today and ran into a problem: I was unable to load any of the PyXML modules:


>>> from xml import xpath
Traceback (most recent call last):
  File "“, line 1, in 
ImportError: cannot import name xpath`

So, the problem originates from this nasty hack that allows PyXML to contribute modules to Python’s standard xml namespace.

On Leopard, simply installing PyXML will not make the PyXML modules magically appear in the xml namespace as on other platforms. If you take a look at:

/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/xml/__init__.py

you’ll see why:


# only prefer _xmlplus if the environment variable PY_USE_XMLPLUS is defined
if os.environ.has_key('PY_USE_XMLPLUS'):`

So, the solution is to set that environment variable and your PyXML packages will all magically appear. I think this is new to 10.5 because I didn’t find any links from Google about it (just the Darwin source code for __init__.py).

SmugMugExport 1.0.4 Released

December 9th, 2007

I just released SmugMugExport 1.0.4. Changes include:

  • added software-update
  • iPhoto image titles can now appear in the SmugMug interface
  • improved keyword handling
  • other bug fixes

A full change log is available.

Neil Young, Trans Tour

December 5th, 2007

I wish I could find the source of this footage.

I support Barack

November 18th, 2007

I support Barack Obama. He is the only viable candidate that is serious about changing politics.

His speech at the Jefferson Jackson Dinner was one of the best speeches I’ve heard from a politician since he spoke at the 2004 Democratic National Convention:

Lawrence Lessig recently publicly endorsed Obama. The alternative to Obama appears to be Hillary; Lessig describes why he’s not supporting Hillary:

But the part that gets me the most about Senator Clinton is the eager embrace of spinelessness. I don’t get this in Democrats generally. I never have, but I especially don’t get it after two defeats to the likes of George Bush (ok, one defeat, but let’s put that aside for the moment). Our party seems constitutionally wedded to the idea that you wage a campaign with tiny speech. Say as little as possible. Be as uncontroversial as you can. Embrace the chameleon as the mascot. Fear only that someone would clearly understand what you believe. (Think of Kerry denying he supported gay marriage — and recognize that the same sort of people who thought that would win him support are now inside the control room at ClintonHQ).

I want the next president to have a spine.