The course I’m teaching on Advanced Server-Side Languages has completed its upgrade to ColdFusion 9. Sure, we’ve already been using some of the new features—especially the primitive literals1, but today was the lecture on Object Relational Management. Today, I felt like we really bit into the heart of CF9.
Before CF9 and Hibernate and the entity* functions, the ORM lecture centered around Transfer and the Illudium PU-36 Code Generator. It’s a mixed bag, really—both approaches have their strengths and weaknesses2.
The lecture takes about the same time either way: 90 minutes. In that time, we create a simple blog with Posts and Categories without a single line of SQL. The code is split along MVC architecture, even dividing out the Model CFCs from the Service CFCs. Sure, it’s not a record amount of time, but in that 90 minutes the students get to see what ORM can do for them.
It may shock some of the ORM fanatics out there, but it turns out that it’s almost the exact same amount of code3 as the non-ORM version of the blog we develop earlier in the course.
I start off the course with them translating their Posts/Categories/Users blog from PHP. Which is then refactored into UDF libraries of database calls. Which is then refactored into CFCs and Fusebox-esque display templates. Which is then refactored into black-box MVC with persistent Gateways and page renderers. The whole point is to organically progress from procedural to reusable to OO, to help underline why it is important to think ahead and design properly.
So they’ve spent dozens of hours building, and rebuilding, and rebuilding this simple blog … when I show them how to scrap it all and rebuild almost the entire thing in 90 minutes without SQL. Obviously, there’s always a mixed reaction from the students.
Oh, and the script-only components are growing on me. I thought attribute-postfix notation was going to be ugly as sin, but it’s not so bad. I’m still not sold on JavaDoc properties, but then I never was when I was using Java, either. We are back to curly-brace hell … but I can admit that there is much less visual noise this way. It works out great for Model and Service CFCs, but then we can stick to tag-based View CFCs. It’s nice having the option4.
Let’s be honest—I have to teach ORM, so am I going to continue to teach 3rd-party software which is great but is still 3rd-party … or am I going to teach the stuff that is now baked into the language? I’m not asserting any value judgments either way.
Yes, yes, I know: the point of ORM isn’t necessarily to save code, or to make it any less complex. The point is to make it more deterministic and maintainable. However, less code that is “easier” to work with is often touted as a side-effect of ORM, and that’s complete bunk.
But I’m not giving up on my crusade for E4X-style literals. Because after E4X comes LINQ, which means a much-needed upgrade to QoQ … sometime around CF14.