Friday, June 23, 2006

Progress, Java, Ruby

I've spent way too much time working with Progress 4Gl. It's a language whose '4'ness is due to it's tight integration with the database.

You can do stuff like this:
FIND FIRST Order EXCLUSIVE-LOCK
WHERE Order.OrderDate = TODAY.
DISPLAY Order.

A procedural style database access (over SQL's set-based style) with in-place access to tables and fields.

However, it can really suck.

Why? Well, you are limited in your ability to code at a higher level of abstraction. This has hit me again and again over the last 7 years while working with a large inherited code-base. You have no object instances, or struct's or function pointers or custom data-types. This limits the ability to have code be concise, or readable.

Recently I've had the interesting task of writing the same system in Progress 4GL, then Java, then Ruby (don't ask how or why!).

I loved some aspects of Java:
  1. Objects and classes - using basic classes with collaborating objects drops a tonne of 'noise' you have to maintain with Progress because of it's primitive support for abstraction
  2. Spring - I just love flinging around singleton instances, setting this on that so loosely. Loose coupling/tight cohesion city!
  3. Massive number of quality open-source libraries out there
  4. IDE support - i saw 'refactoring' happen in IntelliJ, but found almost as good support in Eclipse. Refactoring rules.
Then we got onto rails, and more importantly ruby. I've settled on ruby, I think, because the underlying philosophy seems to be about making life easier for the developer.

In my opinion, the 'noise' you drop in Progress -> Java is similar in Java -> Ruby.
  1. POLS - Principal Of Least Suprise
  2. Humane interfaces (multiple methods doing very similar things). How often do I think 'wonder if this'll work', and yep, it just does, then I lookup ri and find out it's an alias. It also makes code more readable.
  3. Extraneous syntax can be left out - Methods don't need (), lines don't need a terminator.
  4. Consistancy - everything is an object. This helps in simplifying your view on things. Java primitives suck.
  5. Arrays and hashes are built in - and they are objects. Iterators work on both, and simply rock. They make complicated code compact yet readable and concise.
  6. Operators are overloaded to work in ways that make sense.
    Eg: array1 + array2,
Of course, rails is great with it's principle of DRY (Do nor Repeat Yourself), which is a principle I've often strived for but with limited success.

I think matz, the creator of ruby, sums it up best:
Often people, especially computer engineers, focus on the machines. They think, "By doing this, the machine will run faster. By doing this, the machine will run more effectively. By doing this, the machine will something something something." They are focusing on machines. But in fact we need to focus on humans, on how humans care about doing programming or operating the application of the machines. We are the masters. They are the slaves.

I couldn't agree more. Thank's matz.

4 comments:

Peter Harkins said...

One of the design features I find most interesting in Ruby is that rather than multiple inheritance it uses mixins. You mentioned Array being an object supporting an interator -- that's mixed in from Enumerable. Very neat, I like the idea of object composition more than object descent.

Adz said...

Isn't it? And it's open for use in your own code - it's not 'built in' like everything in Progress 4GL is.

Anonymous said...

You can also try python with django(web framework) cuz things are made still easy in all aspects compare to progress,java & ruby.

Adz said...

Yes -- django looks real good. I find I like Ruby over Python (having used a bit of Python prior to Ruby) - but only marginally...