The Case for Strength
The pendulum has swung once again and I have escaped the world of architecture to get back to delivering software. I left Bank of America (Countrywide) for the second time last week, but not the mortgage industry. I am now the Application Manager for the origination system Nationstar Mortgage.
The challenge for my first week has been getting my head around the codebase. The application is a combination of a vendor solution along with a lot of custom code built up along the side. Like a lot of in house applications which started small, this one has grown in to what I call the “big ball of mud” pattern, where there was not the long term vision and architectural rigor for structuring a scalable, maintainable application. The fun part is it is my job to fix it.
After a week of looking at code, I have acquired new-found love for strong typing. In a mad genius, army-of-one development mode, the freedom of dynamic languages is both liberating and powerful. But as you start to add more cooks to the kitchen, things start to go downhill rapidly.
Case in point, I was attempted to troubleshoot a sporadic NullPointerException that pops-up in production. The culprit method is getting an object out of a list, and calling a method on a nested object it contains. I’m trying to determine if the object itself is null, or if the nested object is missing, so I’m tracing back how to where that object comes from.
The problem is that the instance of the object comes from an ArrayList, which is created from an object in HashMap, and neither makes use of generics. I know what my final object is supposed to be, but I have to trace back through other code to see how that the HashMap is being populated with.
This whole codebase has left me begging for generics. Generics in Java are not just about type safety, they are about documenting your code. For example, instead of:
ArrayList myLoans = new ArrayList(); HashMap properties = new HashMap();
You should make use of generics so that other people aren’t left guessing on the contents:
List<Loan> myLoans = new ArrayList<Loan>(); Map<String,Address> properties = new HashMap<String,Address>();
In the second case, I know I have a list of Loan objects, and I know I have a map where the key is a String and the entry is an Address object. I don’t have to jump around in the code to see how they are used to understand exactly what they contain. Note another difference: I use the collection interfaces (List, Map) in my declaration rather than the implementation classes (ArrayList, HashMap).
From an object-oriented programming perspective, you should always strive to hide the implementation details of objects. And by using the interface, you buy yourself the flexibility of being able to swap out for a new implementation class without breaking the code. For example you could change the ArrayList to a Vector if you needed the synchronization and not break downstream code.
So with my dive back in to the bowels of enterprise software development, I’ve regained a new appreciation for my old friend Java. There is great strength in strong typing which permits you to build much more maintainable applications than the alternatives. Use that strength and make your team happy.
I’ll Buy That!
So it has been a few weeks since Apple announced the iPad. I was pretty excited when I saw it, but gave it some time to digest what everyone else was saying and also the implications. The iPad definitely has its detractors, with most somehow working a feminine hygiene joke into their rants. But in the end, I’ll happily be first in line to buy one. Why?
The game changing aspect of the iPad is Safari. There will be plenty of cutesy apps, but I would sooner chew my own arm off than work with Objective-C. It is a disgusting abomination of a language. But having Safari on the iPad means developing feature-rich RIAs in HTML 5, with fast JavaScript, that can be packaged to deploy so that they appear the same as other iPad/iPhone applications (Dock icons, etc…). Best yet, Apple is giving the finger to Adobe and Flash. The iPad is going to put a nail in the coffin of Flash and help advance web standards by leaps and bounds.
Yehuda Katz of the jQuery team summarized it best in this blog post. I completely agree with him. The iPad is a godsend for HTML and JavaScript developers and anyone who values open web standards should be doing back flips right now. A thin tablet device with a cutting edge browser and wireless networking is going to open up a world of vertical market possibilities for web developers. I was really impressed with what Graham Glass did with his iPhone web application for EDU 2.0, and can only imagine how an application like this could take advantage of the iPad.
Check out the Safari Developer Documentation on Apple’s site sometime to really understand the vast programming playground Apple is creating for us. I’m actually excited about web development for the iPad and am looking forward to getting mine to play with.
Rails Flashback
While poking around one of the Ruby on Rails sites, I stumbled upon the video of DHH’s keynote at RailsConf 2009. Rails 3 looks really cool, but DHH has definitely mellowed from the 2006 and 2007 RailsConfs I attended. Just watching the keynote brought back some good memories of the 2007 RailsConf.
RailsConf 2007 was held in Portland, Oregon, which is about the most awesome city I’ve been to for a conference. It has all the amenities of a big city, but still keeps a quirky small town feel. Between the conference, awesome micro-brews, and Powell Books, it was a really good time.
This was the RailsConf I went to with my Windows notebook while 99% of everyone there was running on a MacBook, so I played the leper. The speakers were great, and it was absolutely hilarious when one of the vendors had the Extra Action Marching Band show up at lunch the first day to perform. It pissed off the stodgy convention center management, but it was a sight to see. Check out James Duncan Davidson’s excellent photos if you want to see how fun a RailsConf could be.
I was thinking of going to RailsConf this year, but it is in Baltimore. I’ve never been a fan of east coast conferences, and I’m worried RailsConf is losing its fire. Just like JavaOne tapered off in to boredom, RailsConf on the east coast could be its jump the shark moment. But if they ever get around to having it in Portland again, I’ll be there.
Cool CBT
After enough time in technology, one tends to become pretty jaded about vendor claims. I’ve seen enough miracle solutions before, most them involving code generation to “eliminate the developer.” It has gotten to the point that if I even hear a vendor mention SOA, I whip out a can of Bear Mace and let them have it.
So it came as a great personal surprise when I actually saw a vendor demo for something both cool and practical. I sit on the .NET Center of Excellence for our oversized company, and part of the role is listening to vendors show off their latest and greatest. Our last demo was from a company called InnerWorkings and I had honestly never heard of them before the demo.
InnerWorkings has an incredibly awesome computer-based training (CBT) system for learning .NET. It goes beyond book reading and is heavily based around coding exercises which are even scored by the system. It has a Visual Studio plugin for working with the vast library of learning material and links to O’Reilly’s Safari Books for reference.
I had never seen a CBT product before this which I would actually considered to be effective. This looked good enough that I would almost be willing to invest my own dollars. If you need to bring a development team up to speed on .NET programming, or a specific area on the bleeding edge, I highly recommend taking a look at InnerWorkings.
(Ext.)Direct Miss
One of the biggest announcements from last month’s ExtJS Conference was the new Ext.Direct functionality in ExtJS 3.0. My criticism at the time was that there was a lot of smoke, but no fire. Almost every session mentioned it in some way or another, but they weren’t producing any enterprise-worthy server code showing how it is implemented.
Now, a month later, more details are starting to emerge, including implementations for various technologies. I sat down yesterday morning intending to take a look at the server side code in the Ext.Direct Pack; in particular the .NET and Java implementations. I was pretty disappointed with what I saw.
To understand my disappointment, you need to understand a bit of history around what Ext.Direct is attempting to do. Ext.Direct is going to be an RPC layer that exposes stub objects on the client JavaScript side that remotes the method calls to the server using JSON (or POST parameters). The protocol definition is designed to be technology-agnostic and easy to implement. In implementation, it would be the near-equivalent of DWR, except it would also run on PHP, C#, Ruby, etc…
Since I’m familiar with CORBA, RMI, SOAP and WCF, I approached Ext.Direct with a more critical eye. The biggest glaring hole in Ext.Direct is the parameter passing. Let’s take a look at a couple examples to demonstrate the problem. All the examples will assume a Java backend, and the service we’ll expose is the PersonService. I’ll work from the interface, since we don’t care about the implementation details:
public interface PersonService { }
Easy
We’ll add a method to PersonService to demonstrate the simplest scenario:
public int getPersonCount();
The payload from Ext.Direct would look something like this:
{ "action":"PersonService", "method":"getPersonCount", "data":[], "type":"rpc", "tid":2}
This is the absolute easiest method to deal with. The operation takes no parameters, and the return value is a primitive. Ext.Direct can deal with this easily, but so could any AJAX library, so no secret sauce here.
Object
One of the key advantages to an RPC protocol is the ability to pass Objects. Well complicate things a bit by adding the following method to the PersonService:
public Person getPerson(int id);
For our example, we’ll assume the Person class looks like this. I’m not including setters/getters to try and keep it short:
public class Person { private int id; private String name; private int age; private Date birthDate; }
In the method I added above, the JSON payload from Ext.Direct stays pretty simple:
{ "action":"PersonService", "method":"getPerson", "data":[1], "type":"rpc", "tid":2}
This should return the Person with the ID of 1, and depends on the server code to correctly serialize the Person object to JSON.
Harder
Now let’s make things painful. I’m going to include a method to add a Person.
public void addPerson(Person person);
This is where the wheels fly off of Ext.Direct. Since the protocol specifies the data element as an array, I’m not clear on how Ext.Direct would deal with this from the client side. Every example so far works with primitives as parameters, so I haven’t determined what it would do with a Person.
Ext.Direct would be much happier if I defined the addPerson method like this:
public void addPerson(int id, String name,int age, Date birthdate);
Then, the JSON payload would look like this:
{ "action":"PersonService", "method":"addPerson", "data":[1,"John Doe", 25, "Sun May 01 1985 00:00:00 GMT-0500 (Central Daylight Time)"], "type":"rpc", "tid":3}
Even in this “happy path” scenario for dealing with an object, your server-side implementation would need to be able to correctly deserialize the stringified javascript date object, which is not anything the current implementations handle.
The protocol specification states that the data element can also be a JSON object with named parameters, but it is not supported in the first implementation. This is going to be absolutely critical if Ext.Direct is going to evolve into a real RPC protocol. For example, using a JSON object for the data element in the above example would result in a JSON payload like this:
{ "action":"PersonService", "method":"addPerson", "data": {id: 1, name: "John Doe", age: 25, birthdate: "Sun May 01 1985 00:00:00 GMT-0500 (Central Daylight Time)"}, "type":"rpc", "tid":3}
This would at least allow the server code a means to try and instantiate an instance of the Person object, as long as the server code is implemented in a language that allows for reflection of the Object.
My grief with Ext.Direct is that correctly implementing the server-side code to support the specification is a non-trivial endeavor. One big piece missing is the metadata. In other RPC mechanisms, there is strongly-typed metadata which can be used to create the stubs. For example, CORBA has IDL and SOAP has WSDL.
Ext.Direct is missing a metadata layer to facilitate the passing of Object values. It is going to be difficult to implement a complete server-side stack to handle the permutations that will arise. Developers will either need to dumb-down the exposed services to handle the limitations of Ext.Direct, or else they will end up doing a lot of custom work on top of the server side implementation to handle the type coercion.
I’m still not convinced Ext.Direct is the right path for ExtJS to be barking down. There are already established, tested protocols for handling RPC via JavaScript (DRW, WCF), and ExtJS already works quite well with basic AJAX over the HTTP protocol. Ext.Direct is adding a level of complexity to ExtJS which could easily turn into a rabbit hole that sucks up all their time. I would prefer they focus their precious development hours on the client library and leave the communication layers decisions to us. RPC is a complicated problem with a lot of history around it, and there is no reason for them to try and invent a new wheel in this space.

