2005-03-24

Classes per package in the JDK

I don't often get to see how many files are in a directory. Edit pretty much takes care of the whole directories thing for me. I just have to remember some fragment of a file's name, and it finds it, Google-fast.

Today I had reason to see how many files were in a particular directory, and I wondered how that measured up to other directories. In particular, was it as large as javax.swing?

Here's a bash(1) one-liner (broken down for ease of reading) to count the number of classes in each directory under the current directory:

dirs=`find . -type d ` ; \
for d in $dirs ; \
do \
count=`find $d -maxdepth 1 -and -name *.java | wc -l` ; \
echo -e "$count\t$d" ; \
done > /tmp/classes-per-directory

I ran this at the root of both the 1.4 and 1.5 JDKs' source trees.

Here's 1.5's top 20 largest packages:

hydrogen:/tmp$ sort -nr classes-per-directory-1.5 | \
head -20
215 ./com/sun/org/apache/bcel/internal/generic
191 ./org/omg/CORBA
138 ./javax/swing
130 ./com/sun/org/apache/xalan/internal/xsltc/compiler
108 ./java/awt
107 ./java/lang
91 ./com/sun/corba/se/PortableActivationIDL
89 ./java/util
89 ./com/sun/corba/se/spi/activation
80 ./java/nio
80 ./java/io
78 ./javax/management
69 ./javax/swing/text
69 ./javax/print/attribute/standard
69 ./java/security
67 ./com/sun/jmx/snmp
66 ./com/sun/org/apache/xerces/internal/dom
64 ./javax/swing/plaf/basic
62 ./com/sun/org/apache/html/internal/dom
61 ./java/net

There were plenty of packages unfamiliar to me there, so here's the top 20 without the non-java/javax stuff:

hydrogen:/tmp$ sort -nr classes-per-directory-1.5 | \
grep -v com/sun/ | grep -v ./org/ | head -20
138 ./javax/swing
108 ./java/awt
107 ./java/lang
89 ./java/util
80 ./java/nio
80 ./java/io
78 ./javax/management
69 ./javax/swing/text
69 ./javax/print/attribute/standard
69 ./java/security
64 ./javax/swing/plaf/basic
61 ./java/net
60 ./javax/swing/plaf/synth
52 ./java/awt/image
44 ./java/awt/event
43 ./javax/swing/event
43 ./java/security/cert
42 ./javax/swing/plaf/metal
42 ./javax/naming
41 ./javax/swing/plaf
hydrogen:/tmp$

That looks a lot more like what I expected. Still a couple of surprises, though. I'm surprised that a new package, javax.management, should make the top 10. And I'm surprised that a package I've never even heard of, javax.print.attribute.standard, should also make the top 10.

A quick glance at the javax.print.attribute.standard JavaDoc had me confused. What's the difference between the first two classes, Chromaticity and ColorSupported, other than the former's beautiful name? Well, it turns out that the author thought it was confusing too, and explains:

Don't confuse the ColorSupported attribute with the Chromaticity attribute. Chromaticity is an attribute the client can specify for a job to tell the printer whether to print a document in monochrome or color, possibly causing the printer to print a color document in monochrome. ColorSupported is a printer description attribute that tells whether the printer can print in color regardless of how the client specifies to print any particular document.

There turn out to be three distinct sets of attributes in this package. The largest of which seems to have about 30 members, which takes it out of the top 20.

Here, for comparison, is how 1.4 looks:

hydrogen:/tmp$ sort -nr classes-per-directory-1.4 | \
head -20
182 ./org/omg/CORBA
137 ./javax/swing
106 ./java/awt
89 ./com/sun/corba/se/ActivationIDL
86 ./java/lang
80 ./java/nio
77 ./java/io
69 ./javax/swing/text
69 ./javax/print/attribute/standard
64 ./java/security
63 ./javax/swing/plaf/basic
61 ./java/util
56 ./org/w3c/dom/html
54 ./org/omg/PortableServer
54 ./org/apache/xalan/templates
54 ./java/net
52 ./java/awt/image
52 ./com/sun/corba/se/internal/ior
49 ./org/omg/DynamicAny
49 ./com/sun/java/swing/plaf/windows
hydrogen:/tmp$ sort -nr classes-per-directory-1.4 | \
grep -v com/sun/ | grep -v ./org/ | head -20
137 ./javax/swing
106 ./java/awt
86 ./java/lang
80 ./java/nio
77 ./java/io
69 ./javax/swing/text
69 ./javax/print/attribute/standard
64 ./java/security
63 ./javax/swing/plaf/basic
61 ./java/util
54 ./java/net
52 ./java/awt/image
44 ./java/text
44 ./java/awt/event
43 ./javax/swing/event
42 ./javax/naming
42 ./java/security/cert
41 ./javax/swing/plaf
39 ./javax/swing/plaf/metal
39 ./java/beans
hydrogen:/tmp$

So apart from java.util shooting up the chart, things have been pretty static on the java/javax front. Interestingly, just over half the new classes in java.util are new exceptions relating to formatting.

Perhaps the most interesting fact – and it's one I can't easily show here without a graph – is that most packages don't contain many top-level classes.

2005-03-20

Ong-Bak: Thai Warrior

I've been waiting for a decent (realistic) martial arts film for a long time. When one finally came along, I almost missed it; seems the locals don't like subtitles, and the locals who'd understand the original audio have long since seen it on DVD. Plus I managed to be out of the country for most of its run.

It's martial arts movie plot #1: bad thing happens to boy's people/village/master/family member, boy goes to put things right, boy has to break a promise, a good guy dies, more bad guys die, boy returns successful but changed by the experience. There were references to drugs, prostitution, and it was made clear that foreigners were funding the (presumably illegal) fighting too, though nothing much was made of any of these points. I wish it had been clearer whether there's general Thai-Burmese antagonism, or if the Burmese character's specific nationality was irrelevant.

In between, there's some really great fighting. If you like knees and elbows in your fighting, you'll love this.

Elbow techniques have never struck me as being likely to be particularly useful offensively, because you have to be so close in. And I don't like close-in. Thanks to this film, I might finally be convinced that there's some use to a spinning elbow — if you can do it that well.

I can't wait to see more Tony Jaa (Panom Yeerum). May he live long and make as many films as Jackie Chan has. imdb says of him that he "went to university where he studied a variety of martial arts, from taekwondo to judo". (Presumably he didn't major in martial arts?) It would be great to see plot excuses for him to use a different style in each film.

10/10. The fights come thick and fast, and they're great.

2005-03-16

Mac OS needs /proc


linux$ ls -l /usr/bin/top
-rwxr-xr-x 1 root root 49388 Jan 26 16:17 /usr/bin/top

macos$ ls -l /usr/bin/top
-rwsr-xr-x 1 root wheel 88096 20 Feb 11:44 /usr/bin/top

Yuck!

2005-03-15

Words almost fail me

Wired had an article on England's EBay for Sex, containing the following, which is a great example of the thought processes of idiots:

"I have a husband, and sex outside of my marriage is fun," she said. "He doesn't know what I do, but I'm very careful STD-wise and really only do it once or twice a month. It's not much different from having an affair."

So that's all right then.

Next up, a pedophile explains that sex with a 2 year old is okay because it isn't much different from sex with 6 year olds. And besides, it's fun, and they only do it once or twice a month anyway.

I come from a family of teachers, but I couldn't imagine ever becoming one: it's such a futile exercise.

2005-03-12

Brief book reviews

Out, Natsuo Kirino

I've been accused of being misogynist more than once, which is silly. I don't like all instances of anything. Why should women escape Sturgeon's Law?

Good women writers, though, do seem to be very thin on the ground. I don't count books written by women that other women think are okay. I mean fiction that interests or engages me, the only arbiter of literary merit who matters to me.

George Eliot worked. I cried reading Gaskell's Ruth, but unlike with Hemingway's Farewell to Arms, there were reasons for that other than the quality of the writing.

"Out", though, was truly great. Interesting and believable female characters, and plausible male characters too. Something female writers way back to Austen have been embarrassingly bad at.

I won't spoil the story; the blurb does a good job of telling you too much. Technically, I liked the way that, if the story was going too fast, the author would go back and tell a relatively large chunk again from a different viewpoint. I didn't think that would work as well as the more common use of little chunks and/or non-chronological ordering, but it did.

This may be the first modern Japanese story (including cinema) that I've both enjoyed and fully understood. I hope Stephen Snyder translates more of this woman's books.

And anyone who wasn't rooting for Masako by the end — that would be a misogynist.

The Contortionist's Handbook, Craig Clevenger

Amazon told me that if I liked Chuck, I'd like this. They were right.

I like a book with an obvious ending that you've been given all the clues for, but which I don't guess. This was such a book.

The Cheese Monkeys, Chip Kidd

Clever, funny, and pretty... If only it were a woman.

I've never felt closer to arts students than while reading this book. The guy who believes any argument he hears, but would like to escape that. The girl who's clever and doesn't like the one teacher who's obviously better than she is, perhaps because she doesn't want to find that she can't get any sharper. And the mean teacher, who's the best thing to happen to them.

I bought this because I liked the title, which I noticed because it stood out in yellow on blue. How apt for a book about a course on graphic design.

The Virginian, Owen Wister

The first Western. It's so archetypal that I can't help but wonder if this is just the first work based on a particular reality, or just extensively imitated.

If you need a long book that it will be no problem to read to the end, but which you can easily put down and continue later, this is ideal. You can count the shots fired on the fingers of one hand; it's a love story, though I'm not sure whether it's for a woman, a time, or a country. Or a particular kind of man.

The cover painting on the edition I read is Jasper Francis Cropsey's Autumn on the Hudson River. An odd choice for a book set in Wyoming, even if the love interest came from the east coast.

Hope in Hard Times: New Deal Photographs of Montana, 1936-1942, Mary Murphy.

Non-fiction. Many of the pictures are interesting, though some are simply pretty. Maybe that balance is necessary.

I was annoyed by the coyness in places. I'd have liked to have seen a toilet. I'd have liked to see sex workers. I don't know they took those pictures, but I would have taken them, and I hope they had the foresight to do so.

There was a picture showing how they castrated sheep in 1942: make a small incision in the scrotum with a knife, suck, and bite.

I sincerely hope never to need that knowledge.

Welcome home!

My refrigerator (including the freezer compartment) currently contains:

  • one carton of milk, 4 weeks past its use-by date

  • two pats of butter

  • one half-empty bag of throat lozenges


It's nice to get back to all my home comforts...

2005-03-06

Java Unicode box drawing characters

In the best Unix terminal emulator, Terminator, we implement the graphical character set by using the corresponding Unicode characters. We need a shade pattern, a bunch of control pictures, a degree symbol, a plus/minus symbol, box-drawing characters, and less-than or equal and greater-than or equal symbols; all of which are available in Unicode.

Unfortunately, it doesn't look quite right. There are gaps between characters vertically, and the horizontal characters are too low. In fact, if you render them on a line with nothing beneath, you can see that they extend well into the next line down.

This, which has been annoying me for months, turns out to be bug 4896465 on the bug parade, raised against 1.4 in 2003. If you have a spare vote, please consider using it.

I don't understand (or care) whether it's the font's problem or the font rendering code's problem, but I'd really like it to not be the problem of any Java application that wants to use these characters, which it is as long as this bug continues to be ignored.

(At the same time, I realize that character-based box drawing isn't the most important thing that could be fixed, but that's what you take on when you give the world something as useful as Java: hundreds of thousands of people are all going to have a problem or two that's important to them, but unimportant to pretty much everyone else. At least for once this isn't a problem I think I could fix myself if Sun accepted patches.)

Playing with Sun's Font2DTest on Linux, I notice that there's a font called "FreeMono" that gets the box-drawing page right. Unfortunately, it gets just about everything else wrong, and is really quite ugly (unless you happen to like Courier). At small sizes, like you'd use for a terminal, it's impossible to read unless you anti-alias it. Even then, it's too dark for light-on-dark use.

If none of that puts you off, and you make a lot of use of something like whiptail(1) that uses box-drawing, you might want to try:

terminator -xrm fontName:FreeMono \
-xrm antiAlias:true \
-xrm foreground:black \
-xrm background:white

I love anti-aliased text in general, and think it's one of the reasons I'm happier using Mac OS than any other OS — I don't know what MS Windows and Linux do wrong, but there's something not right about their font rendering. But for terminals, nothing beats a well-designed font meant for use at a specific size.

2005-03-04

An annoying Ruby "gotcha"

If you run this on a system where /usr/bin/ruby is ruby1.6 you'll get a line containing "x" for each line in /etc/passwd. On a system where /usr/bin/ruby is ruby1.8 you'll get a single line containing "x".

#!/usr/bin/ruby
`cat /etc/passwd`.split('\n').each() {
|line|
puts("x")
}

Why? Because they interpret the split('\n') differently.

This has caught me out quite a bit, because Mac OS 10.3 has ruby1.6 while Debian testing/unstable has ruby1.8 and I use both systems regularly.

I'm not sure what lesson or lessons I should learn from this. Always specify the version of the interpreter you've tested with? Stop assuming Ruby's any less strange than Perl? Give in and learn Python too, and see if that's any better? Stop complaining when Sun won't change something that's obviously broken, for fear of breaking existing code?