Archive for April, 2004

'Seven Ways' OnJava article

Friday, April 30th, 2004

Some interesting things in Robert Simmons’ article at onjava.com [http://www.onjava.com/pub/a/onjava/2004/04/28/hardcorejava.html].

Number 1 says to use a stronger compiler. Possibly a reason to look at the new jikes I guess, but as I’d have to buy new computers to handle the heaviness of IDEs, or accept coding at a slower speed, nothing I’m likely to move to. When I do use Eclipse, I turn on a lot of the warnings and like them.

Code reformating is an interesting one. I’m firmly in the ‘it messes up CVS, so stop sodding reformating the code when you commit your changes’. However, I’m happy to go with it if it’s hooked to the commit. Need to look into this at some point. Figure it out in CVS and SVN and I assume use Jalopy.

Introduce final everywhere. Robert Simmons seems to think this is an easy win, but I’m utterly not convinced. It’s not transparant to the developer [as checkstyle would be] and would become a crutch [developers would not expect to have such problems when they forget to put final in, we would need checkstyle to start complaining if final was missing].

Incidentally, I hate the for(Iterator itr = collections.iterator….) style that Robert’s using in his example. It’s amazingly ugly and evil, but sadly has 1 advantage, that the ‘itr’ variable is in a tighter scope. This can be solved in the while loop way with an extra set of braces, but it is equally ugly.

Removing commented out code is good, though I think it should be done by the person who is responsible for a project. This is possibly an oddity of mine; I believe in code responsibility. Ownership with an open door. I often delete old comments etc, but I also comment things out if the business needs imply that that functionalityy will need to go in someday.

Removing anonymous classes is wrong. They’re the closest thing we have to closures. I suspect that Robert has seen them overused a lot. I generally only ever use them for Listeners in GUI work where they seem to fit well. Occasionally a Comparator, but I hate writing non-generic comparators. Robert also has it wrong when he suggests copy and pasting the anonymous class. You should make it more generic, rather than copy and paste some hacked out anonymous piece.

Robert’s 6th tip is mis-titled. Took me the second time to notice what it was as the title made me think it was a different Listener pattern. Instead it just suggests that the collection for Listener support should use Weak references. Well, this is not something the developer does often, it’s something Sun and whatever Framework is being used should listen to.

Lastly we have something about constants. No real argument here. I tend to do this kind of thing with the loose and easy:

public final static Object RED = "RED";

ie) I worry more about the ‘int’, than the fact that someone might put an object in which isn’t a ‘Colour’.

So upshot of the article? I might investigate Jalopy and Checkstyle again, get Jalopy integrated into my SVN and CVS modules and Checkstyle into my ‘maven site’, and will add it somehow to the nightly-build report at work.

O'Reilly/Safari login confusion

Tuesday, April 27th, 2004

In case anyone else is in the same position; my login to safari.oreilly.com stopped working a couple of weeks back when they merged their user account systems into a single-sign-on system.

I got a reply back from the people behind Safari [InformIT] tonight. Took a bit longer than you’d hope, but clearly specified the problem. O’Reilly have changed things around, it will still work if you use safari.informit.com.

And indeed it does. One thing to note is that your password is the one it always has been, not the new one that O’Reilly created.

O'Reilly Eclipse book marks a new trend?

Tuesday, April 27th, 2004

This may have been happening for a while, but I just noticed that the O’Reilly Eclipse book is published on Safari before it is marked as available at Amazon.

Usually books seemed to take a little while to appear on Safari, and Amazon often seemed to be about the first group to get print books. Hard to tell from this end of the wire, but such prompt releases help to increase the benefit of Safari.

One thing that O’Reilly, and many others, do seem odd on is that Amazon will have a page up before O’Reilly do. O’Reilly’s forthcoming (someday) JUnit book is one such book. Amazon even have a picture. O’Reilly don’t seem to mention it as existing.

[http://www.oreilly.com/catalog/junit/ does however exist, it’s just blocked]

Tip for SVN Log

Monday, April 19th, 2004

Finally I understand why I was so confused about SVN log a while back.

’svn log -v’ will create a Changelog based on the version that your local svn files believe you have checked out.

Let’s say you checkout revision 45 (r45). You descend a few directories down and make lots of changes, until you have a file down there which is on r57.

If you goto the top directory, you would expect the whole system to be on r57, but this is not true. It’s still on r45.

So to get a changelog, make sure you do a full svn update first to bring the files up to the latest revision.

’svn info’ is your friend here by the way. It will tell you what revision of a file/directory you have at the moment.

An IO time: Apache, OSJava and Groovy

Sunday, April 18th, 2004

I’ve had a fun few days of coding. Nothing big, but it feels good to do the code exercise.

First off, I’m porting a bash script at work to Groovy whenever the odd hour or two presents itself. It’s meant a lot of time on the Groovy IRC channel, which is very enjoyable and I’m quickly falling in love with Groovy. Implementation wise, the parser seems to have a fair few minor bugs, but the concept behind the language is good.

While I’ve not done much with PNuts and Beanshell, other scripting languages are hard for me to work with a lot as they are not a part of the Java community. So despite liking Perl, Python and Ruby, and having read quite a bit about them [in fact, I learnt Perl just before Java in 98 and use it constantly], they’ve never fit with my Java work. Groovy however is from the Java community and feels right.

I get the feeling that many are using Groovy as a Java replacement, with a few using it as an embedded language. Well, that’s not for me. I plan to use Groovy as a scripting language. Many of the classes I write will be in Java, because it’s more mature for me. One of the problems I’ve hit is that there is not much file level support. ‘zip -r’, ‘find’, ‘perl -pi -e’, ‘rm -r’ etc. So I’m now working on adding that.

First stop. OSJava’s GenJava/gj-core. This is my personal utility package and contains a find implementation from a while back. Nothing fancy in terms of options. So the weekends work has been to make it fancy in terms of options. Basically a complete rewrite. It’s not all tested yet, but all relevant UNIX find options have been added. It’s also very useful from the Java side, you can attach a listener to the find ‘command’ and get at the results sooner.

At the same time, I’ve had to implement wildcard functionality. Also quite fun to do. Now I have WildcardUtils.match(String text, String wildcard).

Next step here is to finish testing, then break it out as gj-find, a separate sub-project to gj-core. I quite like this approach and half think Jakarta Commons should try the same thing. A chaotic single project that releases a large entity, then spawns tighter, smaller components.

Speaking of which. Commons IO 1.0 RC1 is now available in www.apache.org/~bayard/io/. It’s much overdue, and my failure to get it moving has been holding it up. Any opinions are welcome, either to my email or if you’re on commons-user or commons-dev, to those lists.

Commons IO 1.1 would hopefully contain the gj-find stuff, so if that moves quickly I may not even break it out.

The end result will, I hope, be for Groovy to depend on commons-io (?) and to have something seriously sweet like:

find( directory, { "DEPTH" : "true" } ) { f | f.delete() }

Admittedly, a file.recursiveDelete should exist, but the above is sweet, sweet scripting. How about:

find( directory ) { f | f.replace(repl, with) }

None of it legal Groovy yet, but hopefully someday.

Keynote wins over VMWare

Wednesday, April 14th, 2004

So having played with VMWare to see if my Dell Inspiron 4150 can become my new main laptop, I’ve decided that it can’t match the Powerbook G4 400mhz.

It’s probably more powerful hardware, but it’s lumbered with XP as the main environment. It’s in a cheaper casing [well, it was cheaper after all, a thousand dollars cheaper] which makes it a pain to use.

VMWare is nice, but not nice enough. It isn’t enough to turn XP into a Mac beater, plus there’s the security worry of a Windows box. I’m not prepared to connect it to other people’s networks, and not prepared to waste tons of effort on virus management or software firewalls.

So instead the money will be spent on a new battery for the Mac [current one gets 15 minutes!] and a copy of Keynote which I will try using for lectures.

Maven

Wednesday, April 14th, 2004

I’m firmly in the liking Maven camp.

Dependency grabbing is a first big win for me. We need a CJAN and Maven is bizarrely the first real thing that enough people use to make such a thing happen. Creating my own repository of jars would be a pain in the arse. I have been tempted at work to stop people hitting the iBiblio repository and only use an internal one if we decided to control what jars were legal to use.

I hate building things with Ant. I’ll type ‘ant’ and it will fall over. I’ll look and discover I have to edit build.properties and find jars for it, downloading from god knows where and finally get it all patched together so the Ant file will build.

Either that or I’m downloading lots of Jars in the distribution or getting them out of CVS. The CVS case seems to implicitly have the Hibernate problem. I get ‘commons-lang.jar’ and not ‘commons-lang-1.0.1.jar’. ie) The project hides the dependency version.

I have two major environments in which I use Maven as an admin. Work and OSJava. I’ve customised things increasingly in both places. The OSJava stuff has been customised a lot on the website side [due to Hani’s complaints actually] and no longer uses the Maven menu which I dislike. Having now found what I like there, I could dump Maven and create a global Ant system to replace it, but why bother. I’d only have to design the website and match the features I use.

The Work stuff is good, because it stops every developer there having to constantly hack Ant scripts. At an early point someone was doing lots of custom jelly things in the maven.xml, but I’m slowly weeding this out. My belief is that maven.xml should rarely exist. For the things that have a need to exist, I have created a work-plugin which effectively becomes the standard extra functionality. Mainly it lets me manage all of the companies build system a lot more easily than if there were a plethora of Ant scripts out there.

As you asked, my problems with Maven, and I’ve suffered with it since 0.1:

Dependencies of dependencies are not solved. Someone seems to have tried to fix this very early on as they used to have pom/ folders on the first Maven repo, but they were never filled. It seems quite simple and recursive a thing to do. JJAR was closer to this the day Maven was born than Maven seems to be. [JJAR was Geir Magnusson’s dependency handler that is in Jakarta Commons Sandbox and became obsolete and died when Maven emerged. It could be called from Ant and give people their dependency system].

No concept of dependencies having different needs. Ones that should be packaged for runtime in the dist, unit-test only ones, etc. Again, 0.1->0.4 used to have a comment saying it had to separate runtime and compile time ones. I think that came from Maven and not me. It seems to be an issue that has dropped out now so I have to do my own true property.

Changing website between rc1 and rc2. I like having a simple, easy to use documentation system. It’s not beautiful, but it’s better than what I’d create with the time I can devote. I’ve tweaked the colours a bit, made my own navigation.xml etc. However in rc2, people are raining on my parade with a changed site. I need to see if I can set some property to old.site=true, but I doubt it. This will keep me on rc1 indefinitely as I’m not suddenly changing my l&f at another project’s insistence.

Jelly. I’m okay with Jelly. Yes it’s a bit odd, but for basic needs, one language is much the same as another. The biggest problem with Jelly is that it’s not a very active project. I can deal with the brackets if must be, but Maven are right to get off of Jelly as they are the only real users I’m aware of.

Documentation. It’s better than it used to be, but not as good as it once was. Maven 0.4 or so had good docs. Pete Kazmier did some good work here, but as I think happens to a lot of documentors, found himself more and more involved in product development than product documentation. Then it got really bad. The site documented CVS HEAD and this was horribly out of touch with the latest stable release. Then it got better as the site and stable got closer to each other due to less releases. Now it seems quite unchanging. Things like Wiki’s can help here, but in Maven’s case, and many others, I think it merely adds to a greater confusion as there are more locations to find the information in. Unmanaged.

Arrogance. Maven advertising contain(s?)(ed?) a lot of arrogance. Take the automatic ‘Development Process’ which is put on the end of every navigation list. Hooking everyone up to claim they use Maven’s processes. The site should be very empty by default and require active turning on of things. It’s easy to add a line to add Javadoc report generation, it can be a pain to figure out how to hack it out. Make the default Maven site/functionality simpler.

Too late to keep going on. I should just blog this separately :)

OSJava: New releases and a new found energy?

Tuesday, April 13th, 2004

Very tiny hope blossoming that I might have the coding habit again after spending 2 months without a single Apache, OSJava, JBeanTester itch or anything codelike done outside of work.

I’ve not leapt into code, but I’ve at least managed to release new versions of Norbert, Trail-Taglib and OSCube.

Norbert is a robots.txt parser. The new release removes the dependencies and has it throwing a nice Exception instead of magic and logging.

Trail-Taglib is a dynamic breadcrumbs taglib and the new release sees what feels like a simplification to the normalisation algorithm, ie) the ignoring of query strings.

OSCube is, embaressingly, a framework of some kind. I know they’re all the rage at the moment, and this lacks all the intelligence and sanity of others. It’s the evolution of the scraping-engine I have, but without the scraping. An xxxx-engine. I’ve used it for a real-time value simulation engine, and it’s suitably cryptic and full of hidden gotchas that it’s ready for a public release so I can use it at work.

I find myself quite often designing, if not coding, systems which have a scheduler, a bit of work, some db-storage, and a success/error notifier on the end, while needing a configuration system and access to a DataSource, and it seems to fit this bill quite nicely.

Next up, I really need to dig into simple-jndi and teach it about hierarchies. Currently it only half gets them. This might also be a good time to teach it, and me, about DirContexts as they map to my hierarchy problem I think.

All found at www.osjava.org by the way.

Slow day….more sugar/java needed

Tuesday, April 13th, 2004

Painful day. I’m trying to cut back on the sugar before I hit diabetes and if the day had ended at 6pm I’d have managed. However I needed a quick jack [3 toblerone pieces] before a meeting about the Java teaching I’ve agreed to do at 6:30.

It’s going to be interesting. Teach programming and Java to a dozen newbies in 14 3 hour classes. While I’m going with Eckel’s TIJ, I’m not going to go the purist OO route and overload them with objects, though I do have a nice idea for the first class. We’ll play I-spy.

Basically the idea is that after the first go, they have to start I-spying things about the first object I-spy’d. I’ll either tell them to I-spy something about the coffee mug they chose first, or something that can be done to/with/by it. Then I’ll use noun/verb/adjective as a similie, and finally point out that that is all there is to objects. Maybe a bit silly for a graduate management class, but maybe it’s just pointy-haired enough to succeed.

After that I’ll have to get elbows dirty with the syntax. This always freaks people out [at least from my Pascal days it did] and I’ll need to cover syntax quickly and get a lot of experience with the compiler in the first few classes. #1 lesson always being:

“99 errors is not a bad thing. It could just be 1 error with 98 symptoms. Solve the first one, and worry about the others later. “

Then it’s on to the various APIs of Java, including parts with language tie-ins like Exceptions.

My first ever time in which I’m the instructor and not the assistant or just the helpful person in the corner. Also my first experience of the American education system since I was a 10 year old in Dallas, so we both might get a shock.

My biggest decision at the moment is whether to buy Keynote or use my preferred HTML frames structure. That and writing a syllabus.

svn log 1, me -10

Tuesday, April 13th, 2004

So I’m a crack idiot. ’svn log’ does provide logging on changes to sub-directorys, ie) is recursive by default. Various hints in the book seemed to suggest it did but I couldn’t believe it until I svn logged the revisions in two different directories and compared them. The child was a subset of the parent.

Additionally, ’svn -v log’ is nice as it includes the files that changed.

You can also happily pipe into the gnuify-changelog.pl if the changelog format is important, though I just want the information and not the actual form. I ended up modifying it a touch to split on the / | / and print the whole date-line. If you get errors about references being concatenated, it’s because you have a user who is not in the list. Gnuify is in the subversion releases tools/dev directory.

The only pain I now have is that we have many projects in the same repository and I want an option to hide changes to files that are not a match of my current path when printing verbosely.