RESTful Goodness - I declare!

Posted on January 24, 2007 at 02:10 PM by John Repko

Rest

Rails 1.2 was recently released, and I've been updating and upgrading Pikaplanner to take advantage of some of the new features in 1.2.

The highlight of Rails 1.2 is built-in REST support, and I've been updating my controllers to provide what amounts to a standard, easy-to use, web-services API.

My first step in the process was to work through some of the examples in Rob Orsini's terrific developer volume Rails Cookbook. Diego Scataglini's examples in Rob's book provide a simple and quick intro to REST support in Rails 1.2.

REST is a great example of Clayton Christensen's concept of a disruptive technology. I've worked with SOAP and RPC in the past, and at first blush REST is less powerful than either. Still, with Rails, REST is easy and cheap to adopt at the service-provider end, and easy to experiment with at the receiver end.

For example, one of the first code areas I worked through was a simple product listing. The goal here is to provide both a web (HTML) and web services (XML) interface to our (sample) product information.

The REST support in Rails makes it easy, and all we need to do to turn our web pages into a web-services interface is tell (though the URL) our application that we want XML (instead of HTML) back.

So: to see the web page listing our products, we'd use "/products", as shown below:

Products

So far, so good, so common—in Rails we've called up pages like this in the ":controller/:action/:id" form (that defaults to a GET on index.html here) zillions of times. What's new, with REST and Rails 1.2, is that all we have to do to have a web services interface is tell the application we want XML back, instead of HTML. So our URL is of the form ":controller/:action/:id.xml", as shown below:

Products.xml

and as you can see we get XML back - a web services interface practically for free (developer time-wise).

There is a lot of magic underlying this simple example, but a handful of key points stand out:

1) All we need for our "web services" interface is to tell our controller we want XML back.

2) We could have gotten JavaScript back (where that is appropriate) in the same manner

3) The key shift in development mindset is that the interface is not imperative (as SOAP and most web services are) but declarative—everything important in the system a) has its own URL for CRUD access, b) exists as a stateless resource, in which complex actions can be created by changes in state of one resource triggering actions to change the state of other, related resources, and 3) is capable of varying the format of responses, depending on what is requested.

That third point is a mouthful, and the core of stuff on which theses have been written.

Declarative programming is a significant mind-shift, one I'll be writing more about in the future.

Feelin' Groovy

Posted on January 08, 2007 at 03:49 PM by John Repko

Banquet Programming platforms are like holiday dinners - to succeed they have to offer something for everyone, and if they/you sample a bit of everything then they (like you) are likely to end up bloated.

Such is the case with Java, a pretty language with clean syntax that, in its full Enterprise-banquet form, has been compared with eating an elephant. Enterprise Java offers everything, and development teams have to make a lot of technical calls before the first line of code is ever written: EJB or JDO? bean-managed, container-managed, or framework-provided persistence? EJB 3.0 or JDO 2.0? Struts or JSF or Spring? The wrong call, of merely the passage of time can make for pretty hard-to-manage code.

Still, Java's been used in enterprise development for years now; it has a large library of code and many trained developers and all of this makes for a pretty appealing banquet-table. What is a development team to do?

A common answer lies in the realm of "opinionated code," in which the development team chooses a set of beliefs, and architecture follows. Ruby on Rails is a good example of opinionated code: everything, from default directory layouts to ORM framework (ActiveRecord) to dependency injection is baked in.

RoR is great, but it doesn't address the great banquet of Java development and platform that's evolved over the past nine years. Enter Ruby-on-Rails-for-the-Java-set: Groovy (the language) and Grails (the platform).

Groovy is a dynamic language based on Java and strongly influenced by Ruby, and Grails is a JEE-spiced framework modeled-on and very similar to Rails. Groovy reached it 1.0th birthday this week, and Grails is nearing it's 0.4 release, so the platform isn't particularly mature yet, but has solid financial backing and is already being explored in "mission-critical enterprise applications".

"So what?" you say—is this instant relief for enterprise development, or a "wafer-thin mint." My first experiences with GoG indicate the former. Setup is fast, and the initial development environment provides ORM (from Hibernate), inversion of control and MVC (from Spring), logging (log4j), and layouts (from SiteMesh). This is opinionated software, the decisions are made and many of the patterns that have made RoR popular (DRY, convention-over-configuration, etc.) are baked in to GoG as well.

Groovy and Grails may not be ready for full enterprise deployment, but the platform is easy to grasp for both Java and Ruby developers, provides much of the development speed and elegance of RoR, and embraces the libraries, seamless integration-to and feel-of JEE. It should be a great platform for prototypes and rapid JEE development, and 2007 should reveal whether it will mature to an enterprise-ready framework.

Tastes great, less filling...

Bonus Prediction: REST ye Merry!

Posted on January 02, 2007 at 05:24 PM by John Repko

Snow

Prediction: APIs rule, and REST will come to rule APIs in 2007.

Google rules the Web 2.0 world. They are the alpha and the omega, from Google Maps (which popularized Ajax and got the whole thing started back in 2005) to being the primary acquirer and exit strategy for many Web 2.0 companies. Google is also the whole alphabet in between, and their publishing of APIs for their applications re-ignited the "mash-up" concept from Web 1.0, and changed the face of web apps we see today.

Google is wise and omnipresent, but they aren't omniscient. Back in 2002, when the current round of API design decisions were made, Google had the choice of creating an API in well-known media-darling SOAP, or the little known academic paper-protocol REST. They chose SOAP. Not that SOAP was such a bad choice, but with the benefit of hindsight Google is now heading in another direction, and Yahoo has already reached the promised land.

SOAP (originally Simple Object Access Protocol) was a neat idea—to replace the bulk and complexity of integration schemes such as CORBA with a simple combination of XML and HTTP. Great idea, but to provide fully-functional enterprise integration SOAP had to expand, eventually absorbing much of the complexity of the protocols it meant to replace.

Enter REST. Representational State Transfer is the brainchild and 2000 PhD dissertation of Roy Fielding. Fielding observed that one of the great advantages of the HTTP specification (of which he was also a contributor) was that the client-server, stateless, cacheable, and layered design made access and architecture for the specification straightforward. REST extends these concepts to application-application communication. Very broadly, REST maps the basic CRUD operations (create, retrieve, update and delete) to familiar HTTP operations (POST, GET, PUT, and DELETE). As an additional conceptual benefit, these operations also map analogously to the database operations INSERT, SELECT, UPDATE, and DELETE.

Boiled down, the idea is to have applications interact through conceptually simple HTTP access for exchange of resources—remote resources, as opposed to remote procedure calls. API creation is then a breeze, because the access methods are already broadly familiar, and the receiving applications need only be ready to respond to requests based on the request information in the HTTP header - say for HTML (web pages), JavaScript (Ajax requests) or XML (application requests). Ruby on Rails has good REST support now (through the SimplyRestful plugin) and will have REST as a part of the core going forward.

In the Ruby/Rails world, URL's are beautiful and informational, and one of the downsides of REST are URLs that are more machine- than human-readable. Still, as applications are increasingly designed with integration and mashup in mind, you can expect REST to rise in prominence in 2007.

Predictions for 2007

Posted on December 31, 2006 at 07:17 PM by John Repko

Since a new year beckons, and this is a blog, it follows that predictions for the new year must follow. Hey, rules are rules. And so, with no further adieu, here are my predictions for 2007:

Easy Calls:

1) Microsoft Vista comes, new machines get it, nobody on XP upgrades. Microsoft will be content to turn over their installed base with new machines sold and old machines obsoleted. Otherwise, upgrades will be slower than currently forecast.

2) Apple delivers Leopard, new machines get it, but upgrades are slower than currently forecast. Tiger is sufficiently good, and external packages (e.g VirtueDesktops) simulate a lot of the new functionality. Apple has a big decision to make, between adding functionality for the IPod/digital home, and functionality for business and enterprise solutions.

3) Linux will continue plodding progress in '07, and boom in '08. Linux has a lot to recommend it - including good security, scalability, and cost. Its openness makes it impervious to horrible, enterprise-inappropriate additions (DRM), and has a huge leg up on 64-bit solutions. If Ubuntu can continue advancement of a plausible desktop system, Linux will start taking Mac users in '07 and MS users in '08.

4) Dynamic languages will keep making inroads on "traditional" (.Net and J2EE) development. Compared to compiled C++, Ruby is one slow language in execution, but there are *so* many available processing cycles that development savings dominate. It won't run Google or the would-be Googles, but it's fast enough for everybody else. The second wave of RoR apps will appear.

5) Ajax is here to stay, and full page refreshes will disappear in 2007. Good packages (such as Prototype), and the ease of integration in new environments (Ruby on Rails) make ajaxification easy for new applications. Existing apps will ajaxify or be replaced by ajax'd apps.

6) Google backlash begins. Past a certain size, it gets really hard to not "be evil." Google has passed that size, and the leading edge isn't willing to give them a pass anymore. Look for one new search engine to break on top of the pack.

Wild Swags:

7) Oracle buys SAP. Alexander the Great "wept, because he had no more worlds to conquer." Larry Ellison does not weep, and SAP is all that is left. The current permissive antitrust environment won't last forever, so Oracle goes Exxon-Mobil(e) in '07.

8) Indian IT giants start buying second- and third-tier US software providers. Outsourced development from the US to India is now commonplace; the next logical step is Indian vertical integration into the American market. Wilder swag: Wipro buys Lotus assets from IBM.

9) Google buys Ebay. See 7) above. "Froogle" has gone nowhere, Ebay got spat out of China. Google has innovative IT at scale, Ebay needs innovative IT at scale. Match made in heaven, and these kinds of deals won't find a favorable approval environment forever.

Final Swag:

10) Innovators rule. Vista is great looking, but is it a compelling upgrade if DRM restrictions give new users less control than they have now? Apple is also wading into DRM waters that make sense for IPods but not for enterprise-anything. Oracle has its hands full with Fusion, and if you like the JD Edwards, Peoplesoft or Siebel software you're running you might not want to Fuse in '07. As Tony Curtis once said: "In confusion there is profit." '07 looks like a great year for disruptive technologies and solutions.

Ruby Joy #2 - tight code

Posted on December 11, 2006 at 09:03 PM by John Repko

Ruby is a high level language, which means you can do generally something in Ruby in less language than it takes to describe it.

This is a life/time-saver in creating large systems, and with Ruby and Rails a little code goes a long way. For instance, in my manufacturing system Pikaplanner, if I'm assigning a product to a product family, I can create an HTML select statement that finds and collects all the product families in a single line of RoR code:

<%= select 'product', 'productfamilyid' , ProductFamily.findall.collect {|p| [ p.familyname, p.id ] } %>

A lot happens in that one line - I query the database (find_all) for all the product families, create an array of them (collect), and fill an HTML Select statement so that if the name of a family is chosen, the id of the family is assigned to the product.

A thousand lines of RoR can produce a useful system, and the blog code that underlies this post is about 3,200 lines of code, with 1,000 of them test code.

A good developer can keep 10K - 100K lines of code in his/her head. If it takes millions of lines of code to make a system, then you'll need a lot of developers, and nobody will understand the whole system. With Ruby/Rails, a single developer can create whole, usable systems, with the benefit of the consistency that comes from understanding the whole system. THAT is TIGHT.

Ruby Joy #1 - beautiful, readable code

Posted on December 11, 2006 at 04:26 PM by John Repko

Java started it: way back before the tech boom and bust the venture capitalist Ann Winblad wrote an article about a previously-unnoted aspect of the then-buzz in Java development: the Java development environment was structure such that, if done right, any developer could read the code of any other developer.

The key to this (to Ann at the time) was the elimination of the "tyranny of the developer" - codegeeks could no longer hold their company hostage as the-only-person-on-earth who could keep their code monstrosities running.

This basically proved to be true, but obscured a larger point: if coders could read each other's code, then coders could "share" each other's code, and anybody's advance could quickly make everybody's code better.

Ruby shares this trait, and goes Java one better—conventions in Ruby/Rails development are so strong and compelling that code "mashups" are not only possible, there (comparatively) quick and easy.

This blog is one example of such a mashup—the developer of the code beneath (SimpleLog, by Garrett Murray) wrote so compelling beautiful and structured an application that adding it alongside a foreign codebase (mine) only took a day or so. The latest upgrade (adding Archives (see left)) only took about an hour.

The Ruby/Rails community is in melt-up - as more developers get more skilled, the ability to extend all of our apps is growing exponentially. This is beyond cool...

Ruby joys

Posted on December 09, 2006 at 08:07 AM by John Repko

"The real adventure of experience is not about searching new countries but about the ability to look through new eyes. " Marcel Proust

I was instantly hooked on the Mac - literally. The original Mac had a scrapbook image of a fish - a nice sunfish in pixel art that instantly changed the way I'd look at computers. With new tools you can do new things.

I've been interested in creating flow manufacturing software for about 10 years now, but the tools of creation never quite fit what I was looking to create: hosted, easy-to-use, flexible, interactive software. "Pure" html was too limited, Java too bulky, .Net too monocultural.

I was pulled by the hype into Ruby on Rails, but what I've found with it has more than justified the hype. With Ruby it has been possible for a single developer to make a full system that's rich and interactive—the DHH applications (like Basecamp) on 37signals are a beacon for lots of new developers. Ruby (the language) is gorgeous - a "bicycle for the mind", to quote another Jobs-ism.

I'll post more on the joys of Ruby as we go forward. It's a gorgeous language with a beautiful structure, and with it it's possible to do complicated tasks in fewer words than it takes to describe them.


../themes/pikasoft/views../../themes/pikasoft/views../../themes/pikasoft.