Browsing the blog archives for May, 2010.

Comments Now Support SexpCode

Computers

Koen Crolla has specified a replacement for BBCode (that atrocious square-bracketed markup language for bulletin boards) called SexpCode. It uses S-expressions (think the LISP language), with ’staches instead of the usual parentheses . Comments in this blog are now SexpCode-enabled.

The source for my comment below is {b This} is {i {u my} {o playing} with} {code SexpCode}.

4 Comments

Java is not Python and Cygwin is not Linux

Programming

I’m burning the midnight oil working on a project in Java and came upon a number of gripes, all right in a row, that I thought were all worth blogging about in case I can help make somebody else’s night a little bit better. So here are some things I learned today.

Java is not Python. Java’s changes that introduced generics (to allow expressions like, for example, “Vector<Integer>”) were pretty much all in the compiler. The bytecode stays the same; the compiler just gets some additional data to use for typechecking. Then your beautifully generic Java 5.0 code undergoes a process called type erasure producing the same — but better typechecked — bytecode that your old 1.4 code would have. The result is that when I, with my limited understanding of Java generics, tried to write overly dynamic code, the compiler scoffed.

“required: class or array”, it said. What it really meant was, “You can’t use a generic type in an instanceof operation, you dummy, because I’m about to erase that type and replace it with Object.” Doi.

Cygwin is not Linux. Especially where Java is concerned. I spent about 20 minutes trying to figure out why I couldn’t pass the JDK an absolute classpath from Cygwin when relative classpaths worked just fine. It was because the JDK I was calling is Windows native, not Cygwin, so it doesn’t understand the Unix-style directory structure I was giving it.

Java is not Python (redux). I’ve mostly been using Python for my various and sundry programming needs over the past couple of years. And it’s impressive how quickly one gets used to a REPL (read-eval-print-loop) — and how useful it is for quick debugging and answers.

For instance, I missed having a REPL when I had a simple question: can I typecast null to whatever object type I want (the answer is yes, by the way, which makes a lot of sense when you think about it)? I was in the midst of a fairly significant rewrite so I couldn’t just try it and run it. So I saw four choices: assume it would work and test it later, assume it wouldn’t work and rewrite it, look it up, or write a Java program to test it.

Turns out that there’s actually a fifth option: use the Java REPL. It’s called BeanShell (or bsh), and I feel pretty much ridiculous for not having found it before. Maybe you’ll enjoy it.

Okay, back to work.

No Comments