Caffeine Peter Colijn
(RSS)

January 05, 2006 (link)
Missing in Action

This blog has been MIA for quite some time. Due mainly to the fact that the friend with whom I left my machine switched around a bunch of stuff on his network without telling me, and didn't really know enough Linux to help get things going again. Time for some "real" hosting, esp. now that I can afford it.

Holidays n'at

Holidays were good. Extremely busy, but good. I hate Christmas shopping more and more each year. The thing is I'm not a "gift card" kind of person. I just don't like it, it's barely better than giving money. There's a lot to be said for really thinking about someone you know, and what they'd like. It's a good contrast to the rest of the year, when most people are thinking "me me me," and I think the whole gift card phenomenon is basically a cop-out. Of course, when you do decide to actually get gifts for everyone, it gets much more time consuming. But it worked itself out in the end; people seemed to like the gifts I got them.

[image]
Owen and Shane at the fiddle, New Year's eve

Waterloo

Back in the 'loo now. This place just has a way of sucking the life right out of you. Between the dreary days and spending lots of time in MC, it's enough to make you just feel tired and apathetic all the time. Hoh well, only 4 more months and then this stinkin' town can kiss my ass.

On Java

So I spent a fair bit of my last term coding (gasp!) Java. To be sure, there was a fair amount of C++, Python, Perl and even some more Ruby. But the majority of my work was in Java. Java gets lots of C++ fanboys screaming about how it sucks because it's slow or it has GC or it doesn't have pointers. I'm not going to take the fanboy approach, but will instead, for your amusement (or horror, depending on how you see it) describe my "hit list" for Java.

There's no const. The way this is typically worked-around is using interfaces. Let's say you have the interface IFoo. You write an implementation UnmodifiableFoo that wraps an IFoo and throws UnsupportedOperationException for all the mutation operations (BTW, this is the decorator design pattern). What's wrong with this? First, you have to write UnmodifiableFoo yourself, which is of course error-prone. Second, because UnsupportedOperationException is an unchecked exception, there will likely be lots of code out there that calls the mutation operations without catching that exception. So you pass an UnmodifiableFoo into a method taking an IFoo, the compiler happily does that for you, and things blow up at runtime. You can't throw a checked exception without changing the interface, so basically you're hosed if you want to try to add immutable implementations after writing the interface. In C++, the contract of the method that the compiler checks can specify that it wants a non-const reference because it will be doing mutations. AFAIK, there is no way to have the Java compiler do anything similar for you.

References are not explicit. This is easy to get used to, but it inevitably confuses newcomers. Also, there's no way to have a reference to a primitive type (most of what you want that for is accomplished with "out" parameters in C#).

While C++ has them as well, exceptions are much more heavily used in Java. I tend to prefer return codes. The argument for exceptions is that you force the programmer to do something when an exceptional condition occurs. In fact, you do not:

try { methodThatThrowsStupidException(); } catch (StupidException ex) { }

Sure, you made them write a catch block. Who cares? The other thing that inevitably occurs is that programmers, fed up with writing try and catch blocks, inevitably end up having gigantic, 500-line try blocks. Then when an exception occurs, you have no real idea what went wrong. I guess I prefer return codes because I feel that it's pretty easy to tell by looking at the code whether you're checking them or not. Exceptions essentially de-localise error-handling code, and I don't like that.

Finally, the generics in Java leave a lot to be desired. I've written about this before so I won't go into the gory details here. Suffice it to say that writing a generic class in Java can be quite the pain in the rump.

Now, I know I promised that I'd steer clear of "fanboy" tactics, but I actually will say something about GC. It's not appropriate in a lot of situations, like embedded or real-time systems, but I do think that C++ programmers spend way too much time tracking down segfaults and memory corruption. Of course I agree with Joel that it's important to understand pointers and have experience debugging that kind of thing. But so much time is spent tracking these things down, and it's only when you have good common practices (smart pointers, or auto_free semantics, or whatever else) and your development team adheres to them religiously that it becomes much less worrisome. Since most projects end up using external code and add new programmers, that situation of common best practices and strict adherence is extremely rare, so the memory management problem remains a big one, and GC is one solution that is appropriate in many situations.

January 07, 2006 (link)

On Java, continued

apenwarr: You're correct that it's definitely possible (and reasonable) to have an immutable base class (interface), and a mutable subclass (subinterface) that extends it. That is indeed how I would write things normally. Unfortunately, that is not the convention in Java. The Collections API doesn't do it that way, and it has become the "accepted norm" to have one main interface, for which certain operations will be unsupported. The main reason for this, as explained to me by on of the main implementors of Java who now works at Google, is that when people tried to do the immutable base class thing, codebases just became too unruly. Aggravated, of course, by Java's requirement that class Foo be in Foo.java and not any other file. I suppose that's more a complaint about the conventions than the language. Still just as annoying, however:

Collection<String> getStringList();

You might think, for example, that it would be perfectly valid to do getStringList().add("foo");. However, getStringList() is just an accessor and may very well return an implementation of Collection that does not support add() (and the compiler would never warn you in that case, because the exception thrown is unchecked). Even worse is the so-called "defensive copying pattern," where getStringList() will allocate a new Collection<String>, copying everything into it and then returning the new collection. In that case everything is slower just to protect against the possibility that someone wants to modify your collection, and your code will compile and run absolutely fine but do something completely unexpected. So you're right, there's a sensible way to do things, but large parts of the JDK (which isn't technically part of the language, but is so heavily used it might as well be) do things badly, so it's still a major annoyance. Finally, a "const Foo" makes more sense to me than having both ImmutableFoo and Foo, and it's less boilerplate, so I still argue that C++'s const concept is superior to separate mutable/immutable interfaces in Java. And of course, in C++ you get the choice; you can do either.

As far as GC is concerned, I agree that you have to think about object lifecycles. You always do, and you're right that some people interpret GC as a "free lunch" not to think about things any more. I don't have a good solution for that, but I would still argue that GC is valuable in Java in a lot of cases, in particular for short-lived objects that are larger than you'd typically want to allocate on the stack. In my experience, a lot of objects fall into this category, so GC is valuable. Of course that varies depending on the type of software you are developing.

I haven't heard of people using object pools too much in Java, and never saw any code that did that myself, so I don't think allocation and constructor-invocation time is much of a worry (even it was perhaps in the past).

January 11, 2006 (link)

Politics

Lots of people have been talking about this, so I'll try to keep it short. I watched the English debate (didn't have time to catch the French one, unfortunately). The take away was that Harper seemed calm, Martin and Layton seemed desperate, and Duceppe was, as usual, the most intelligent of the bunch. Too bad he wants to tear apart the country. The thing that really bugs me about the Conservative campaign is that they've totally steered clear of all their stupid social policies on things like same-sex marriage and abortion. While it's politically a good strategy, it's just slimy not to talk about that stuff to get in, and then try to do it later. The prospect of a Con minority actually wouldn't bother me that much if it weren't for their wacko religious redneck leanings. Don't believe me? Dude, I grew up in Alberta. I've met Preston Manning, spoken with Con candidates in Calgary, and believe me, it's rough. You have to remember that these aren't the same Tories we used to have. They're mostly Reform now. For an example of where "traditional" Tories stand, see Belinda Stronach.

January 15, 2006 (link)

RSS

So RSS is quickly becoming the new hotness. I've been using Google Reader lately to read PlaNit, Slashdot, and whatever else tickles my fancy. It's quite nice, and I can read my news anywhere (both an advantage and a disadvantage, I suppose).

However, none of the common blogging tools seem to be able to do upgrades or migrations in an RSS-friendly way. It seems almost every day, somebody on Planet GNOME upgrades their blog, and all their entries appear at the top. It's enough to make me want to write my own bloody agregator that isn't so braindead. Or at least fix Google's, the next time I'm there :)

In other news, we're all doomed.

January 21, 2006 (link)

apenwarr: I basically agree with you the psychology of perks is strange. But all the perks you mention (with the possible exception of the foosball table) fall into what I would call "personal" perks. It's your vacation, your free t-shirt and your glasses insurance. The most beneficial (for the company) perks, I would argue, are those that make the workplace more attractive.

For example, at Google you can get all 3 meals for free at work each day. The result? Many people will show up rather early (8-9:30) to get breakfast or stay somewhat late (at least 7) to get dinner (or even better, both). The meals are probably therefore revenue-neutral or possibly revenue-positive for Google, since people both work longer and feel like they're getting a perk. Similarly with laundry. Why worry about gathering together a bunch of quarters and other random change on a Saturday when I could just go to work to do my laundry? And hey, while I'm waiting for my clothes to dry I might as well read email. And I still feel like it's a perk, despite the fact that they've gotten me to come in and catch up on email on a Saturday.

Pure genius. They've got me working harder and I feel like I'm totally privileged. And I know it. And I don't even care.

January 23, 2006 (link)

Bye-bye ndiswrapper

I bought my current laptop off of eBay, and in the eBay description it claimed the laptop came with the Intel PRO wireless (i.e. the one that has native Linux drivers). It did not. Since stuff worked with ndiswrapper and I didn't really want to go through all the trouble of returning it (especially since I bought it in the states and a replacement would have to go to Canada, so the customs crap would be annoying) I just let it be. Though I did give the eBay seller some bad feedback.

Recently, some persistent and motivated people have even begun releasing snapshots of an open-source Broadcom driver. I even tried them.. and they oops sometimes when you set the essid and couldn't manage to do anything more than associate for me.. but A+ for effort, and hopefully they'll work Real Soon Now.

But that's not actually what I'm writing about. I discovered that you can buy an Intel PRO Wireless miniPCI card for $30CAD on eBay! For $30 + shipping I get to kiss my random lockups goodbye and support a company that, you know, isn't completely braindead. Done deal. Had I known how easy and cheap it was before, I would have done it long ago. Anybody else stuck with craptacular Broadcom wireless should seriously consider doing the same. For $30, you can't really go wrong.

Reminder

VOTE
Are you voting yet?

January 24, 2006 (link)

Election

<sarcasm degree="modest">

To those of you who are:

  • White
  • Male
  • Straight
  • Anglophone
  • Wealthy

Congratulations! The new government will be looking after you well!

To the other 90% of the country: I'm sorry. But some of you must have voted for the fuckers; WTF were you thinking? Hey here's a fantastic idea: in the next election, why don't we just bring Bush up here to run for the Cons? Apparently Canadians really like him, as demonstrated by their voting for his Canadian counterpart, so if we bring in the real deal it should be a landslide!

</sarcasm>

Sigh. At least it's only a minority. Hopefully everyone else in parliament can gang up on the Cons to prevent truly gruesome things from happening. But man, Harper for PM? We're gonna look like complete idiots internationally now. I guess we deserve it; it seems many of us are, indeed, complete idiots.

On a slightly more positive note, 29 (at last count) seats for the NDP ain't bad. And after Martin's departure, Belinda Stronach for Liberal leader anyone?

January 28, 2006 (link)

Help me!

So I'm working on compilers. morethanreal and I are writing it in Scheme.

When you're working in Scheme, checking which ( matches which ) is of utmost importance. And if you know me, you know that I use vim. Vim has pretty minimalist paren-matching stuff by default; you can use '%' to see what matches the paren (or square bracket or brace or whatever) under the cursor.

I found some stuff using Google that makes vim briefly move the cursor over to the matching open paren when you type a close paren. While this helps, it's not perfect, in that it will match open parens in code when you type a close paren in a string or comment (but.. I could probably fix that).

Then I found some other stuff that does the emacs-y thing of highlighting the matching paren when your cursor is on a paren. This is super-helpful; unfortunately, the stuff I found was way too slow to actually use (where "too slow" is defined as follows: you hold down j/k to scroll through text, and the scrolling slows down, getting behind on keypress events, so that when you release the button, it keeps scrolling seemingly forever).

Does anybody know of some good vim scripts/plugins/whatever to do this? Suggestions welcome at pcolijn gmail com, unless your suggestion is of the form "use emacs you vim-loving weenie." I am in this to increase productivity; learning to use a new editor is too much overhead (at least in the short term; in the long term it is possible I could be brought over to the dark side, as some of vim's shortcomings (like this one) are starting to get to me).

Back: October 2005 Next: February 2006

email: caffeine@colijn.ca