Re: Readable Java 1.5

by William Grosso

Related link: http://www.onjava.com/pub/a/onjava/2003/09/24/readable_java.html



Stephen Jungels wrote an interesting article on syntax problems in JDK 1.5. In it, he proposed an interesting variant on Generic syntax using parentheses instead of angle brackets. That is, his syntax replaces code like expurgate(Collection<String> c) with code like expurgate((String) Collection c) and the angle brackets after Collection became a cast before Collection.


He listed a lot of reasons why he prefers his syntax. Most of his reasons seemed unconvincing to me, to be honest. And the fact that Java generics look like C++ templates counts as a big win for me (it starts my intuition going in the right direction).


But recently I've discovered, there's a huge argument against angle brackets syntax:


Generics Code isn't HTML or XML



Sounds stupid, right? What I'm complaining about is simply that cutting and pasting angle-brackets code into a web page, or into many instant messaging clients (I'm using AIM 5.3.2392 and I can't send generics code in a chat session), or into a wide variety of e-mail readers, is broken. A lot of devices, when confronted with <T extends Rentable> render it as blank.


So I don't like Stephen's syntax. But I really wish I didn't have to use amperandltsemicolon all over the place when I want to IM about a piece of code either.

Do you ever IM or e-mail code? How do you get around problems with the clients?


7 Comments

anonymous2
2003-11-20 05:31:39
&&
You probably don't like the && syntax either then. Or the while (i < n).


Code is for coding, and if you want to publish it, you'll have to lay it out. Live with it.

anonymous2
2003-11-20 05:47:22
flat text email to the rescue once again
And people still wonder why I hate HTML email.


I've been playing very seriously with the idea of automatically rejecting all HTML email.
Not only would it greatly reduce the amount of spam and virus emails I get (most of that is spam) but also the huge bloat of my mailbox size (an HTML email is typically 100-1000 times the size of a plaintext email with the same content).


Now there's another reason: preventing misparsing of sourcecode.


I didn't like the idea of generics, but this syntax has its advantages after all :)

wegrosso
2003-11-20 08:03:46
And what is coding?
Code is this stuff we produce, mostly collaboratively, in order to get the machines to do what we want. At least part of "coding" is collaboration. And at least part of "collaboration" is text-based tools like IM or e-mail or HTML pages in a weblog or ....


Now think about what you just said. It boils down to "syntax shouldn't take the environment in which coding occurs into account" (okay, that wasn't very boiled down). Do you really believe that?


Here's another reason you shouldn't-- google. Right now, you can google for code examples and get fairly high quality examples of api usage with a little work. Will google work as well with genericized apis? I don't know (and neither do you), but it's a consideration.


Again, I like the new generics (a lot). I even think that, on balance, the intuition from angle-brackets is probably worth the HTML and XML costs. But there are costs, it isn't an open and shut case, and saying "live with it" isn't a good answer.


bazzargh
2003-11-20 09:30:41
Turn off smileys.
In our company we use yahoo regularly to talk about code snippets, and we just turn smileys off. Seems to help.


Doesn't always do it, though: I was having a conversation with a dev about an L10N problem, he pasted me the chars from the page, and they appeared like this: #&1234;


We then had a somewhat confused conversation where I wondered how that character entity worked at all, before we realised that yahoo had done this to Ӓ...


Sigh. Maybe we should all switch back to irc.

bazzargh
2003-11-20 09:32:02
Turn off smileys.
Well, there ya go again. The char at the end of the second last paragraph should read "ampersand hash 1 2 3 4 semicolon" but O'R munged it :)
anonymous2
2003-11-20 10:56:20
javadoc
Just a note, Javadoc is adding a {@code} tag, so you can do {@code Map} and it inserts the gtlt's for you.
anonymous2
2003-12-15 14:07:48
And what is coding?
yomama