Skip to content

JDK 7 Finally Works With Files Like Python

Wow – it has been a long wait for Java to improve its representation of files and file related operations. I just stumbled upon the JDK 7 File (NIO 2) tutorial and it looks like Java will finally be able to do the kinds of straightforward file operations that Python has been able to do for years. There’s even a rough equivalent to Python’s os.path.walk() that should have been in JDK 1.0. I’ve been working with Groovy a lot lately and it makes Java much simpler to read and write. I’m hopeful that with these upcoming changes that Groovy will capture some more developer mind-share.

links for 2009-06-30

  • Groovy's concise syntax frees developers from typical Java constructs that are required for code compilation but don't facilitate expressing what a program is really trying to accomplish. In this revival of the Practically Groovy series, Groovy developer and guest columnist J. Scott Hickey walks you through a series of comparisons between normal Java code and the same Groovy code to show you how this exciting language frees you to focus on the important aspects of coding.

links for 2009-06-29

Pantec Matrix – More Bonehead Engineering

(Update apology – thought this was a Sony product originally – it isn’t)
This post could also have been subtitled – “Where’s QA?”. My son just bought a new phone to replace a piece of crap flip LG that never worked very well. The winner of my 13 year old’s ‘coolness factor’ evaluation would have been the iPhone but at $30/mo for a data plan he couldn’t foot the bill and I sure wasn’t going to cover it. So, the Sony-Ericson (Pantec?) Matrix was purchased. The form factor is nice, keyboard for texting and a dial keypad pops out in a different direction. It all seems quite usable/functional. Then he tried the music player and we got a surprise.

The AT&T sales guy at the store told us that you could put iTunes songs on the device. I thought this was odd but since AT&T exclusively markets the iPhone I thought maybe they’d cut a deal of some kind. Anyhow, of course, an .mp4 could be converted to .mp3 but my son just went ahead and dragged an iTunes library song to the 2Gb Sony custom Sandisk card and popped it into the phone. Then he fires up the music player and the phone reboots!! Yes, reboots – so we did the usual re-seat the card; cycle power dance and still, each time he starts up the music player the phone shuts down without warning and restarts. To cut to the chase, once the .mp4 was removed from the memory card an .wmv file played just fine.

Ya gotta wonder, how did this behavior ever make it out of the factory? What possible algorithm says, “Encounter unknown file type in music player; shut down and restart” – bizarre. I can imagine you wouldn’t want to execute an unknown file type but reboot? Good QA is apparently a lot harder to come by than I once imagined.

links for 2009-06-25

links for 2009-06-23

Maven Mojo – Understanding the Big Picture

Maven is a build management system that emphasizes convention over configuration. This means that working with Maven requires you to structure your source code hierarchy in a very specific way. I was put off for a while with all the demands Maven made about how I do things but after working with Maven for a month now the light has finally gone on for me about where Maven brings value to our build process that Ant couldn’t match.

The advantage Maven offers over Ant is the emphasis on convention allows for the implementation of an inheritance hierarchy of Project Object Model files to provide a flow of behavior across a tree of related projects. Each Maven project defines a pom.xml file that specifies the behavior for that project. Behavior means how the project is built, packaged, and deployed. In addition, the pom.xml is where one specifies the dependencies for the project and additionally, execution of the various activities can be customized in the pom as well. The dependency specification mechanism employs the notion of a shared hierarchy of Maven repositories from which jar files are automatically downloaded if they’re not found locally. Moreover, without much effort our local repository (Archiva on Tomcat) was configured to be updated when a jar file was downloaded from the Maven central repository so the next time that dependency is required it is found locally.

This is by no means a trivial amount of work but it really pays off as projects grow. Each sub-project specifies a parent pom.xml file and inherits all of the behavior and properties of the parent. In this way, just like in coding using inheritance, the only behaviors that I need to add or change in the child are the ones that differ from the parent. Of course, some of this can be done in Ant as well through includes of a build file or the referencing of a properties file but the semantics of Ant just don’t match up to the relationships as intuitively to me. With Maven, you have to be clear about how sub-projects relate to their parent in order to use the tool effectively. This in turn forces one to be precise about the relationships between projects.

Projects can specify their relationships to sub-projects as either dependencies or as “module sets”. Module sets made sense to us at first but we’ve learned recently that by making everything dependencies we can actually reduce the amount of code that needs to be checked out. If I’m working on code that has dependencies on libraries built from several other projects, because they’re dependencies, the jar files will be automatically downloaded by Maven. This means that I have less set up to do when I go to work in a particular area of code. Of course, this doesn’t replacing updating from source control and running a clean build to ensure I haven’t broken other areas but it does mean that I can get to work more quickly.

Pom projects are folders that contain just a pom.xml file and no code. These projects are used to organize sub-proejcts (module). The benefit is that when I’m in one of these projects and I invoke ‘mvn clean deploy’ – all of the specified modules will be built and deployed too. Yes, one can do this with a hierarchy of Ant build scripts but since I’ve used both now, I’m very convinced that how modules relate and interact is much clearer to understand in a pom hierarchy than in an equivalent set of Ant build scripts. The other part of the Maven solution that I believe is superior to Ant is that all the behavior executed by Maven is defined in plugins that are downloaded from the central Maven repository as well. This may seem unintuitive at first – why would I want my tools definitions to be abstracted in such a way? The answer is that the various plugins available in your build are being expanded upon and improved by others so that when you run a compile or deploy task, you dynamically can get the latest version of the plugin and new Maven behaviors become available simply by defining them in the pom.xml. Of course, like with dependencies, you can specify a version too so that you can use an earlier implementation if you prefer to do so.

In summary, I’m really sold on Maven. It is making our build-deploy system more comprehensible and flexible. I’m not asserting that it is always advised to scrap a solid, functioning, Ant run system for Maven but if you’re reaching the limits of what Ant can do for you (a sure sign is lots of programmatic type features in your build.xml) Maven is certainly worth evaluating. Maven also plugs into the Hudson build management system which I recommend highly too.

links for 2009-06-16

links for 2009-06-13

Unions – are they working for everyone or just themselves?

I’m a lifetime democrat and supporter of workers, unions, and labor measures like upping the minimum wage. With those credentials established – I have to decree that the teachers and construction unions in my area are acting with shameless disregard for the common good.

For the last 5 days of school my 7th grade son has watched movies and had 1/2 days. With everyone in Washington and elsewhere shouting about educational standards why are 5 days of the school year devoted to nothing? The teachers told the kids they needed “to get grades in”. This has got to be one of the sorriest rationalizations for misconduct I’ve ever heard. So, in the dark, while the movie is going on – the teacher has his/her abacus out and is calculating grades?! I don’t think so – hey here’s an idea – teach the kids or give exams for 5 days and after the kids are gone, work a couple more days to put in the grades!! I’ll be working all summer – a couple of extra days – if it takes that long – doesn’t seem like much. Mail the final report card home.

The local highway workers manifest another mystifying labor behavior – for many hours everyday there is nobody on job sites. Our local highways are choked down to one and two lanes – the lost productivity and quality of life that this causes is incalculable. Why isn’t work going on during all daylight hours? Because unions mandate a certain number of positions perhaps? Is the number of crews fixed? How is it that I can work a 10 hour day but I don’t see 10 hours of work on the highway construction sites? Don’t we have a vast number of people that are looking for work? Perhaps this is all my dark imagination and really there is a shortage of equipment and skilled labor – can somebody offer a better explanation for why the whole northern Illinois highway system re-construction effort seems to running at a snail’s pace?

The real question is – when unions are working on community projects or for our communities like teachers – do they have some responsibility beyond a contract/pay check for their members? I have no doubt that unions are important for protecting workers from more powerful forces in our society – but what about society at large – does worker protection trump all other concerns?