Sunday, March 1, 2009

On Groovy, SCJP and Hateful Diatribe Towards Java 1.5

Having finished a 3-day webinar on Groovy, and more precisely on Grails, I'm quite impressed with this cool language and framework. I'm still debating on how best to implement this new technology in today's IT world. There are some valid concerns (.ie. scalability) as well as some FUD to be expected. But then again, the same was to be said about Java back in 1995.

There are palpable and real issues that are forcing (or guiding) people to create a myriad of application frameworks or treat the JVM as a target run-time platform (either via Scripting like the Groovy folks or by directly compiling to it like the Scala folks.)*

* If you think such endeavors are not needed for today's IT business, you have been living too long under a website rock. Chicxulub II might be heading your way... or not.


In the meantime, it is crunch time for me: after years of procrastination, I'm going for the Sun Certified Java Programmer (SCJP) exam this coming Wednesday (followed by the SCEA exam in a month or so). The matter of fact is that I haven't had a chance to review as much as I would want to. I've been living under the yoke of Java 1.4 for too long, oblivious to the supposed bliss of Java 1.5 (supposed bliss... more on that later.)

I'm quite familiar with Generic Programming and assertions, coming from what I consider to be a hard-core, down-to-the-bolt Ada and C++ collegiate background (oh, the nostalgia.) But the devil is in the details, and I can't underestimate the nitty gritty details and peculiarities of this new Java kludges that has befallen upon us.

Yep, kludges. I don't like Java annotations and Generics that much. They make me feel kinda icky.

Yes, I'm not that hot for Java Generics.

I can hear pundits saying "are you crazy" or something to that nature. But bear with me. For generics, it's a mild dislike. The fact that the compile performs type erasure thus turning List <T> into a plain List behind doors) makes me uneasy. A generic type T is not the equivalent of "any type" at all. It is simply the equivalent of java.lang.Object.

That is, any method accessible through type T has to come from Object for that type of usage. This is not the same as in Ada or C++.

In C++ (and similarly in Ada):




class Dude
{
public:
template <class T> void hangout(T buddy)
{
buddy.haveBeer(); // workie
}
}


In Java:




public class Dude
{
public <T> void hangout(T buddy)
{
buddy.haveBeer(); // no workie
}
}


In fact, it won't compile at all:


$ javac Dude.java
Dude.java:23: cannot find symbol
symbol : method haveBeer()
location: class java.lang.Object
buddy.haveBeer();
^
1 error



In Java, the bloody thing equates the generic type to a plain java.lang.Object. Unlike in C++ or Ada, you can't treat the generic type as an interface contract. You can only use it to declare a generic algorithmic template limited to a java.lang.Object or a specific class or interface. It is an improvement from previous versions of Java, but that's as far as it goes.

It is pretty evident that true generics and the Java implementation are two different beasts. In Java, the only thing you can see in a generic type are methods defined by Object (or a class/interface if you explicitly name it). True generics, on the other hand, provide a type signature or contract, similar to (but not the same as) interfaces. The former is used for eliminating type casting in a safe manner. The later is to define interfaces and contracts.

It would be absolutely nice if Java were to implement generics as in C++ and Ada. And no, this desire is not driven just by cosmetics and academic pedantries. There are practical ones. However, given the constrains imposed in how to implement generics in the Java language, this will have to do.

Anyways, people still code in Java without closing database connections, so I think we have bigger things to worry. Which leads me to the next.

Now, onto Annotations.

Maybe I'm a Neanderthal. Maybe I live in the stone age. But whatever. I can still not understand why this is a good idea (right off page 21, Common Annotations for the Java Platform[tm], Final Release):





@Resources ({
@Resource(name=”myDB” type=javax.sql.DataSource),
@Resource(name=”myMQ” type=javax.jms.ConnectionFactory)
})
public class CalculatorBean
{


I mean, seriously, what the hell????


Do we really want to go down that route? Why in the name of Baal would we want to hard-code the JNDI name of a data source? Or of any resource for that matter? Having spent countless of hours doing Tier II/III support and dealing with Java legacy apps (there is such a thing... sadly) written by people who didn't pay attention to Software Engineering 101 back in school, I have to say, I really don't want to see that kind of crap creeping up in any software system near me.

Annotations used like that are nothing more that configuration details hard-coded in your source code. This is a facility that is open to abuse, plain and simple.

I will grant the benefit of the doubt in that I'm maybe too old school. I have no problems dealing with multiple XML files to configure this or that, or to inject stuff in Spring or whatever. Maybe I don't see the grand scheme of things. Maybe I still have a lot to learn about annotations.

But as hard as I've tried, I do not see any way to inject from an external configuration source such a value on an annotation.

We have come a long way from separating environment configuration from code. Not only is the actual database IP address and port part of the environment. The JNDI name that it binds to is also part of the environment, at the container level. I'd much rather have such things defined in a external source and injected at bootstrap time.

And this is the thing: as ugly as XML configuration files are, they do the job. You can make frameworks to hide them, but there is a right way and a wrong way to go about it. Annotating configuration details on the source code is the wrong way to go about it. In a large system, and specially with the type of developers we get nowadays (the types that never close database connections), this is just asking for trouble.

I do love what annotations have done in some areas such as declaring EJBs, security roles and transaction levels. But hard-coding JNDI resource names in source code, I'm sorry, that's a path I do not want to follow. That path only leads to where it smells funny.

I can hear people saying that this is the way it should be done, it was implemented in agreement by the Java Community Process and all that. But hey, so were EJB 1.0 through 2.0. So was the idea that distributed transactions were the way to go to build everything down to that small, internal IT operations website that was to be used only by a dozen of people that connected to one single database.

Or maybe I'm wrong and I'm living in a parallel universe or something...

Monday, December 29, 2008

Best XML Quote

XML is like violence. If it doesn't solve the problem, use more.

I'm not sure who came up with this quote. I stumbled upon it in Slashdot. And a quick google on it shows that it is being repeated over and over as an anonymous quote. Regardless of who first came up with it, it encapsulates a always-present malady of the IT world: the abuse and misapplication of technologies and principles.

You know there is something wrong when two applications are communicating via XML when both belong to the same owner, are written in the same language, run on the same network, are not exposed to third parties and yet communicate via XML. By third parties, we mean systems that at best are owned by different organizations within the same company, and at worst, are owned by different entities and are external to each entities' physical networks.

A typical example of this type of abuse is having a web application A having to go through another web application B to retrieve information from a database C, when A and B are written in the same language and A, B, and C being within the same network vicinity. Worse still when the intermediary application breaks down the database results into malformed XML documents.

Not only does this ignore the perennial impedance mismatch that is characteristic of all modern applications that communicate with databases. It also compounds the problem by using the wrong technology to communicate results in this manner: XML. It is not only cumbersome, but it is also inflexible in representing ever-changing data relationships in the database as well as CPU/memory inefficient.

You only use XML when two distinct applications that are external and separate to each other and need to communicate through discrete and well-defined interfaces. Nothing else really justifies plastering XML all over communication protocols.

Monday, December 22, 2008

Why Kolmogorov's pOjOx?

So the 1-mill question I get is why I named my blog this way. Well, in good modular fashion, the answer is composed by three not totally independent components, glued together by their amorphous interfaces with ad-hoc literary middle ware.

Some in the IT industry will rise their fist and yell "yeah" when they read my explanation. Others will simply not like it as it constitutes a slap in the face of their daily professional practice. If you are not allergic with overly and premeditated verbose rhetoric, read on.

Why p0j0x?

For starters, p0j0x, that's my quasi-hacking rendering of POJO (Plain Old Java Object) in l33t speek, a tribute to the old hax0r posters from the long-gone days of the Usenet. Perhaps it is a bit of nostalgia for the days when people were more concerned with demonstrating their technical excellence instead of using IT as a materialistic platform to chase, in rabid, morbid, virulent, almost psychotic and certainly obscene and plain dirty fashion, for 6-figure salaries, hard talk and the dream of retiring to a life of wasteful consumerism by the age of 40.

More than nothing else, the name p0j0x stands for my not-so-veiled disdain for the sacrifice of technical excellence combined with my admiration of simple technologies to get things done. In this sense, POJO-based frameworks such as Spring (in almost complete opposition to this abused abomination that EJBs turned out to be.)

Why Komogorov's?

Simple. Just do a simple google search. What do you get? Andrey Nikolaevich Kolmogorov, one awesomely intelligent dude. Specifically, it is a bit of a tribute and reference to the Kolmogorov's Complexity of objects, systems and the like. Bear with me for a bit.

The Kolmogorov Complexity of an object is pretty much the amount of resources required to represent that object given a (potentially universally) descriptive language. Since we know we can model all computational systems in terms of automata, or strings in a given language, we can say that the Kolmogorov Complexity of a system is how much it takes to represent the damned thing. If you choose any language, be it Java or what-not, to represent it, that is, to implement a program P that outputs it (or in more general terms, gets it to work), the size or length of that program, the resources it consumes, represents the complexity of its representation.

So Why Then?

Well, it is the case that as our systems get larger and larger, so the complexity of implementing them, or representing them. And complexity is something that cannot be simplified or neglected. The systems that we develop nowadays are intrinsically complex. So far so good.

But here is where we are running amok. With all the technological advances we have made on IT and Computer Science as a whole, it seems that we are getting dumber and dumber with every passing year.

We complicate things for the sake of making them complex. Things that should never have been distributed to begin with are now modeled, forced into distributed architectures, with flagrant violations of anything resembling engineering common sense.

We add, cut and paste and glue together stuff, crap if I may say, using whatever new technical hooplah that is the hot new thing to learn and prostitute - I say prostitute since 'implement' is too grand an adjective to use in this particular context.

Zap XML here, slap JMS there, concoct EJB-based abominations with layers upon layers of fluff, e-fat, binary carcinogenics, all converging into a nonsense singularity that rips the very fabrice of space-time in any non-retarded universe. All for systems that never had any substantial distributed complexity to begin with.

What should have been a Web+App+one-single-database gets exploded like a horrendous, oozing zit to the expense of the customer and to the psychological detriment and violation of those poor IT souls shackled to them by chains of legacy maintenance and eventual intellectual dumbification.


So in a way, the name I've chosen for this blog, Komogorov's p0j0x is nothing more than an accusatory finger (followed by a face-slap) to the horrendous practices of those in the IT sector who, at this time and age, should know better what not to do when implementing a system and charging money for it. In the name of Baal, there is nothing other than human stupidity, mediocricy and avarice that could possibly explain (and yet never justify) it.

Putting aside the politics and challenges that naturally arise in the interactions with business users and customers, some things should just not happen. With all things being equal, developing horrendous code is one of them, specially when done on a regular, self-perpetuating basis. And those of us in the IT sector who have chosen to make a living should strive to avoid that at all costs.

Certainly we do not have a fiduciary obligation to our customers as lawyers and doctors do. But we do have a moral obligation, a moral one, an ethical one, a professional one, to the customers and to ourselves if we really want to deserve be called engineers and if we really have a grain of self-respect and dignity as college-educated professionals.

For the most part, that's what this blog is and will be about.

Thursday, October 16, 2008

Gah! My Computer Ate My Posts!

Work in progress. It takes a while to migrate blogs. Stay tuned.