Fun with Groovy and Grails

Brian LeGros | July 16th, 2007 | programming  

Ok, I’m a ColdFusion/Java programmer. I like ColdFusion for the web-tier, but sometimes I feel its way to verbose. I like Java for the application tier but I’m not a fan of static typing and some of the things that Java brings with it (i.e. – checked exceptions). I’ve been hearing/reading a lot of cool stuff about dynamic types in .NET, all of the cool stuff that Ruby can do, and how Smalltalk has had similar features for years now. With all of the press things like JSR-223 and the DLR have been getting, I figured it was time for me to start learning some new things (I will somehow figure out how this will lead to less responsibility later).

So I looked at JRuby for a little while and got too intimidated to learn a new syntax and new language constructs. This may seem silly, but I’m afraid of everything. So in the spirit of trying to learn too little at once, I started to look into Groovy. Dick Wolf from the Java Posse is always talking about it, so I figured, maybe its an easier transition for my Java syntax mind. After doing a few tutorials and playing with the console that ships with it (cool little Java app), I got pretty comfortable, pretty fast. The syntax is based on Java with, what my Ruby friends (Tan and Dyler) would call, syntactical sugar available to make things like file IO, regular expressions, database connectivity, and collections much simpler. The availability of closures alone just made it that much easier to get into Groovy. Groovy also has the notion of formal properties so that was nice too. Oh, and Groovy is written entirely in Java and supports JSR-223 so bi-directional Java/Groovy integration is really straight forward.

In any case, after a few walkthroughs, I wanted to get some instant gratification, so I tried out Grails. Now one of the first things I noticed about Grails which was a disappointment, but not a big deal, was how slow the generation tools were. Even though you are running them a discrete number of times for an application and its just to get started … slow. Now that being said, wow this is a cool framework. I may later find that’s its not all that great, but what I thought was cool about it was I understood the technologies used to build it! The build tools and generator tools are coordinated from Ant using Ivy for dependency management. The web server that comes bundled with each app is Jetty. The framework uses Spring WebFlow as the foundation for “wire framing” the site’s paths and routing. Spring is available for use with your Java classes (and I think Groovy classes as well). The GORM project is a wrapper around Hibernate 3 that Grails uses for its scaffolding (instead of ActiveRecord as in Rails). I thought it was also pretty cool that Grails uses closures as the foundation for its framework, rather than the extension of a set of base classes. Additionally, there is a notion of services which they advise using to implement business rules, so extending an existing Java SOA would get a cinch.

Some more cool stuff about Groovy and Grails, an Eclipse plugin exists that has some helpful IDE features, the generator tools generate IDE metadata so any Grails project can be imported into Eclipse, IntelliJ, or Netbeans, and Groovy and Grails both have lots of documentation to read through. I was able to get a scaffolded site up and running and start messing with the Spring and Hibernate mapping files (for fun) in under 5 minutes.

Groovy is 1.0 and Grails is at 0.5.6, so I’m not sure if its something we could begin using at work, but it feels much more natural to bridge the Java gap than JRuby, learning curve and all. As I mess with Grails and Groovy some more I’ll try to post some code samples. Now, like a good programmer, I’m going to learn a framework before I have any real clue on how the underlying language works.

;)

I’m so glad Java on the web tier rocks

Brian LeGros | June 24th, 2007 | programming  

So yeah, Java on the web tier rocks, at least from the awesome assessment I just got done making from the Java Pet Store 2.0 Blueprint Implementation (JPS). My hopes were pretty high going into this project that I would see some good programming practices in the web tier that would inspire my thought process with respect to ColdFusion. Unfortunately, if the JPS application is any clue what the Java community thinks “Web 2.0″, then they’re in trouble. Here are a few things that have been giving me headaches as I’ve been going through their source code:

  • Table-based layouts :)
  • No XHTML compliance
  • Gobs of Javascript code located inline within the HTML document
  • AJAX implementations preached as features of JEE 5 are truly just code written to interact with the Dojo library. I have seen only one instance in my, all be it limited, analysis that showed me Javascript code generated by any Java web-tier software. ColdFusion’s AJAX integration and binding capabilities will put their implementation to shame.
  • Uses an RSS control (via JSF I think) to consume an RSS feed and render it as HTML. Looks interesting but where is the RSS integration to provide feeds? How many developers, besides RSS aggregator builders, actually want to consume feeds? <cffeed> will be a welcome substitute for what they have.
  • There is this crazy set of classes to encapsulate the functionality of working with Lucene for searching the site. Can’t wait to implement <cfindex> and <cfsearch> to get rid of these 7 or so classes.

Please keep in mind I am no JEE expert and although I’m excited about interacting with new specs such as JPA, I don’t know much about them. That being said, I do however feel comfortable enough with good web practices to realize that this technology demo is not web savy. I feel I understand the purpose of the JPS application as a technology demo for JEE 5, but the use of web standards that it promotes is severely lacking. What I am able to accomplish using Java in the application/business-tier is amazing and I don’t see myself deviating from that any time soon. What I am able to do with ColdFusion in the web-tier vs. what I’m seeing in the JPS definitely convinces me that I won’t be using Java for the web-tier with any of my applications.

So far the raw conversion of the JPS in Java to ColdFusion has been trying, and after 6 hours, I’m ready to take a break. Hopefully, I can motivate myself to get into the “nitty-gritty” of the Javascript code they’ve written using Dojo to see what I need to reproduce from a CF perspective to satisfy their code. I figure once I’ve gotten the app working using a very stripped down CF approach, I can begin to do what I actually wanted to do from the start … make the application actually look good and simplified.  I may skip the use case analysis because I’m not good at collecting requirements, but the UML I think can be done quickly and simply to show its benefit.

I put your lunch in the fridge … next to the ColdFusion container

Brian LeGros | June 3rd, 2007 | programming  

Well, no sooner do I finish blogging about the new scripting integration in Java 6 then did Sean Corfield start to play around with it in the context of CF8. His examples have given me a better understanding of the capabilities of the Invocable interface as it applies to JSR 223 compliant languages. Looks like he had some issues initially going from PHP to CF but the transition to JRuby seemed to have gone pretty smoothly.

From the little I can tell, a CFML engine implementing JSR 223 would open up tons of possibilities for Java containers (possibly even integration of JEE specifications — JTA). ColdFusion application servers could be built using the same scripting engine but provide different features. I could see Smith and possibly Railo benefiting from this initially so I guess I can understand why Adobe was against complying. Adobe has such a monopoly on the CF app server market, even creating the CFML engine to be JSR 223 compliant might cause a demand for it to be open-sourced.

Man, wouldn’t that be awesome?!? An open source CFML engine based on Java. I wonder what types of performance hits we’d have to take, if any? I guess that’d be the great thing, we could choose our implementation at that point. I can’t see BlueDragon, Railo, and Smith not jumping right onto that band wagon and evening the app server playing ground. From some of the review’s Sean’s done on alternative CF servers (also here), I could see this as being that factor that makes people stand up and take notice. Right now, only Adobe can truly say they are 100% CFML compliant because they control the language and the direction of the language, not to mention the audience. An Adobe endorsed CFML engine would mean such great things for our community. I could really see a lot of innovation from tool makers and app server creators alike. Imagine if Mark Drew could create a local context to execute CFML code w/o needing hooks for server to be configured?

Ok, so I’m ranting now, but some cool stuff none the less. Nice intro to the CF community on these technologies Sean.

Dynamic languages and the virtual machines that love them

Brian LeGros | June 1st, 2007 | programming  

Talk about crazy groupy love going on for languages running within a VM huh? It’s so exciting to start seeing other languages in the main stream being the basis for new languages rather than C/C++ which seems like the usual choice.

After the announcement that Microsoft would be releasing the DLR, I stumbled upon an article at InfoQ. I don’t know much about how to write runtime environments, but the article made some sense to me. I found the author was kind hard on JRuby since I’m interested in using it, but I do dig a lot of things .NET in general has to offer (first-class generics, formal properties, how easy registration works, the use of delegates, etc). I’m also very interested in what Java offers in this problem domain. It seems like with JSR 223 included in Java 6 and JSR 292 hopefully going through in Java 7, Java and the DLR could provide similar features for dynamic language development when they’re completed.

I don’t have much of an opinion on which approach is better in terms of forming the foundation for dynamic languages, but I think the future of these platforms will likely be determined by: feature support, environment availability, and plain old cool APIs.

Platform Availability: As far as Microsoft’s effort, I noticed that the DLR has been open sourced but the CLR has not. This leaves Mono to integrate with the DLR for platforms other than Windows. Java on the other hand has been fully open-sourced (minus a few proprietary libaries they can’t open up legally from what I understand) and has always had a plethora of platform support. I feels like Mono will really have to step up in terms popularity to compete with the ubiquity of the JRE. Novell is a sponsor of the project, so I really hope it takes off.

Features: I definitely like the idea as a developer of being able to switch around to different languages mid-stream, but I’m not sure that there are that many different constructs in languages that I feel would make me more productive. Additionally, some of the things that the DLR is trying to do in terms of some sort of shared typing system kinda freaks me out. Isn’t the strength from some of the dynamic languages in how they treat their types versus conventional treatment of types in languages such as .NET and Java?

Cool APIs: One of the biggest things I would love to do is build some type of API in Java for JRuby which allowed JRuby to take advantage of some of the JEE frameworks which make programming in Java for enterprise so cool. For example, I’m not sure if this is feasible or not, I’d like to integrate JTA into JRuby one day such that a JRuby developer could put together objects in a business layer and then in an config file of some sort construct AOP advice that would add transactional proxies around the appropriate business objects so that robust transaction management could be introduced into Ruby (if something exists already that is robust as JTA, please correct me). This may be a pipe dream because I’m not too familiar with what is possible via the Invocable interface in JSR 223. Aside from my rant, I think just having access to Java or .NET APIs when is cool since they are so much more mature from a commercial standpoint.

So with that being said, my last question is this: Where is the standardization for ColdFusion as a dynamic language as it applies to JSR 223? From what the JSR spec says, it appears that Macromedia was one of the largest supporters. Do languages written based on Java have to be open source to be compliant with the dynamic language support in Java? I’m not even sure why I’d want it, but it just seems like a missing, logical step to me for some reason. ColdFusion has done an amazing job over the last few years of “glueing” different languages togther, why not implement this spec?

Oh well, I’m probably going crazy over nothing, but if anyone has any feedback, please let me know.

cf.objective() 2007 : Maximizing Your CF/Flex Applications with Java

admin | May 7th, 2007 | conferences  

My boss, Max Porges, gave his Java talk on Sunday and did a great job. As far as this blog is concerned, I will blow as much smoke up his ass as required to make my working environment even better. In all seriousness though, he went over a great introduction to the tools and environments we use in-house with respect to Java and how easy it is to be productive. He showed a lot of productivity examples using Eclipse and a few comparisons of using CF versus Java and what the benefits were to doing each. Good stuff and hopefully encouraging to the community.

cf.objective() 2007 : Real World SOA: Building Services with ColdSpring and Transfer

admin | May 6th, 2007 | conferences  

Well, in my normal indecisive fashion, I’m giving the CF community its check mark back. Sean Corfeild fails to disappoint. Even though he’s not working with Adobe anymore, he went into the details of how Adobe.com absorbed Macromedia.com and built a robust service layer used by “tons” of web applications. He outlined the basic necessities of building a SOA as below:

  • Data Dictionary (aka Canonical Data Model)
  • Service Directory for discovery purposes
  • Creation of software APIs as services (SaaS)

He gave some pretty cool statistics regarding SOA growth in the USA. He showed a study which revealed that SOA-based applications have grown by 20% over the last year and are expected to increase by 6% annually. His prime example of this was SalesForce.com, but I’ve heard nothing but bad things about their success, so who knows.

Sean outlined the distinction of 4 tiers commonly found in SOA:

  • Controller/Presentation
  • Service
  • Business/Local Model
  • Database/Persistence

In Adobe.com they implemented all of the tiers using ColdFusion and Oracle for the persistence tier. Here are a few points he made regarding good practices:

  • When creating services for the Service Tier, try to use stateless services which can be used to emulate business processes.
  • When requesting a service, authentication should be a major concern. Sean suggested using SSO solutions with randomized tokens being passed. When using this approach, it was mentioned that a policy for token clean-up should be addressed up-front.
  • When constructing datatypes for the canonical data model, consider using primitive types which are shared between environments.
  • Perform a full analysis of the protocols available in your environment and the ability of each environment to work with that protocol (e.g. – SOAP and Java not as easy as it may seem whereas with CF it’s much easier).
  • When creating the canonical data model, expose the minimum amount of commonality in your data. Exposing information specific to some systems but not other may cause dependencies though misuse of the API and accidental tight coupling with consumers.
  • When creating a common exception data model, keep the means by which an error is reported as simple as possible. Distinguish success and failure. For success, return the result of the RPC call. For failure, return a basic exception model containing a type, message, and details. In doing so, programmatic mappings can occur as well human readable messages.
  • Solving caching concerns are difficult. If you can utilize an existing commercial protocol for messaging, like JMS, do so to avoid having to write code for this problem.
  • Unit test the crap out of everything.
  • Don’t allow legacy data models to dictate your canonical data model. Start from scracth to avoid being stuck in stale models.
  • Avoid SOA explosion and extreme API granularity.

It was funny to see Sean say that they chose REST’ful web services instead of JMS for internal messaging. His reason was they could get things done more quickly with web services, but acknowledged JMS would have been a better solution and they got lazy.

This talk was extremely reassuring and a just a great talk. Great job Sean.

cf.objective() 2007 : Case Study : Adobe.com

admin | May 6th, 2007 | conferences  

Nothing much here, but it was cool to see how crazy Adobe.com really was in terms of setup. They has “tons” of applications effectively running uniquely in multiple JRun instances, load balanced across multiple Solaris machines, accessing a very simple database layer with some fail-over in mind. I think he said about 75-80% of the content for the site was static. Everything in terms of languages was mainly ColdFusion. They has some Flash and some Flex. What was really crazy, was to see an actual service layer modeled out which is used by each application. The service layer had other abstractions, like hooks into JMS, but it mainly was used with CFCs in the backend.

The session overall was very informative. It motivated me to realize that if you work towards the goal of SOA, it is possible, especially for a company like WestGate. We’re gonna hit Sean Corfeild up for some good JMS suggestions later this weekend as a result of a tangent from the session, so that should be cool too.

My pet store is better than yours!

admin | May 3rd, 2007 | programming  

So I’m sitting in the airport and I was looking over the Java Pet Store (https://blueprints.dev.java.net/petstore/) application from which the CFPetMarket application is based. After some reading over the last few weeks I think I’ve been able to clear up some confusion in my head. Initially I thought that the application was exercising plain old Java. Then I realized I’m an idiot and the standard way of constructing web-apps in Java is via the JEE framework. Now that this is setting in, I’m thinking crap. Check out what they are attempting to exercise via the sample application:


This application also demonstrate the use of various features of the Java EE 5 platform such as:

  1. JavaServer Faces: Many of the AJAX features are implemented as reusable JavaServer Faces components.
  2. Java Persistence API: The application uses Java Persistence APIs to create an object/relational mapping layer.
  3. Dependency Injection: The application uses dependency injection instead of deployment descriptors.

Crap. So I can use XML Forms to show a comparison to JSF, but I’m not sure how I can implement AJAX features w/o using an API like Spry. ColdFusion has a couple tags for <cfselect>, <cfupdate>, and <cfinsert> but nothing as robust as a standard interface API for object persistence. As far as the dependency injection stuff, deployment of a CF app in a stand-alone server install doesn’t support bundling, so I’ll ignore that for now.

Does anyone have any ideas for what I can do to setup the Pet Store app in CF to mimic the functionality that the JEE 5 framework can provide?

I can WAR an HTML file

admin | April 17th, 2007 | programming  

This is pretty much all I was able to accomplish over the last few days as it applies to JRuby. I haven’t dug into the Ruby language or Rails framework at all yet (besides the command “bin/rails myapplication”), but I’m loving playing with the tools JRuby provides to integrate with Java. Check this out:

jrubyc /mypath/myclass.rb

This is the command to compile Ruby code to Java byte-code. Ok, not that impressive, but just cool to write down. There is even a just-in-time compiler which ranks as extra cool. Check out this page in the JRuby wiki for more info.

I’m probably blowing the WAR magic out of proportion since it’s really just a glorified Ant task bundling up some dependencies for JEE servers to work with Rails. Here is the tutorial I used to create the WAR. I dropped it in Tomcat and it seemed to deploy w/o issue.

Maybe in a few days/weeks I’ll be able to figure out how to use the language and do something meaningful. In fact, my goal is to learn nothing about Ruby and just learn Rails. Ultimately, I can only hope to dream of the creation of the SPRUG (SPace coast Ruby Users Group) over here in Melbourne. With just the knowledge of Rails, I should be able to continue the tradition of Ruby UG’s everywhere. Just kidding fanboys! Keep “The Active-Record” alive and relax; I’m an idiot. I WAR’d an HTML file thinking it was a Rails app.

NOTE: Check out Charles Nutter’s blog if you get a chance. Since JRuby’s 1.0 release is coming soon they have a lot of fun runtime comparisons between regular old Ruby and JRuby. It’s a pretty good read from one of the head developers on the project.

Come for the Java, stay for the VM?

admin | April 9th, 2007 | programming  

OK, I shamelessly ripped off the “Come for the Java, stay for the Cocoa” line from some banner image I saw taken at an Apple conference. I’m moving on…

I was listening the the Java Posse this morning on my quick commute to work (Java Posse – Episode 111) and the topic was Withering Java. Who knows wtf that means. The whole podcast was about the functional programming paradigm (examples in Haskell) spawned by a talk at the Java Posse Roundup on the language Scala. You can read about Scala and Haskell at Wikipedia.

It was cool to hear about another paradigm besides the popular procedural and OO paradigms. I remember learning about functional languages in college, but doing very little (=nothing) with them. From what the panel was saying in the podcast, it seemed like functional languages are starting to be shaped by the more practical in the field of comp sci to be used in industry solutions. Although it seems like the paradigm has been around for like 15+ years, I’m encouraged to see it making its way out of academia.

The podcast went on to talk about how great it would be if it became common in shops for multi-language environments to spring up around a single VM, the JVM to be specific. One of the panel members kept going on about how he’d hire JRuby programmers for the presentation tier, Java developers for the application tier, and functional programmers for expert portions of the application tier and deploy everything to a JEE server. It was a good feeling to be able to say “HUZZAH!” in the car when I heard this. My co-workers and I have been using ColdFusion and Java in this fashion for a long while now. We have a separate architecture and implementation processes for Java and ColdFusion but everything deploys to JRun and potentially to any JEE server. I’m really hoping that with the release of JSE 6 that Adobe could utilize the new javax.script package to more fully integrate Java and ColdFusion. How nice would it be to plug a scripting engine for ColdFusion into your JEE server instead of running as a web app on a JEE server? All the sudden you have access to JTA, JNDI, and JMS resources with the ease of scripting in ColdFusion. Any issues ColdFusion currently has with truly entering the enterprise could potentially be solved.

NOTE: Now I have to ground myself after that rant. It looks like Macromedia was a big sponsor of JSR 223, so it’s probable I’m just over estimating what’s possible with Java 6.

There was a bunch of other stuff in the podcast about byte-code optimization and language comparisons that make it worth a listen. This was by far one of the best Java Posse episodes I’ve listened to since I’ve started.