What surprises me about Rails and Grails users

It wasn’t all that long ago when I remember hearing people slamming Java Server Pages simply because your could write scriptlets. JSP was evil, the worst thing ever created, garbage, yada, yada, yada. Never mind that sometimes it was actually useful to do so, for doing visual things of course. So the power that be created tag libraries which helped a little bit, but creating taglibs was a pain. It has gotten a little easier with JSP 2 and all, but for the most part people don’t use them.

So what does this have to do with Rails and Grails? Well, going through some examples of both frameworks shows one thing I have yet to hear the purists cry about: generating content from within a class. Ah yes, reminds of the pre-JSP days when we were building HTML in a servlet! Not that this is a recommended practice of course, but the fact that this is even being shown is a surprise.

Why? The early adopters of tools like these tend to be the ones that are on the forefront of all the new technologies and let’s face it, can be pretty opinionated (yes that includes me…) and harsh when it comes to “not doing it right”. So while it doesn’t really bother me if someone wants to spit out some response text from a controller I’m shocked that more people haven’t cried foul. Maybe they are trying but have been drowned out by all of the partying going on over these two frameworks. Or perhaps, gasp, they grew up and realized it just isn’t that bad of thing after all.

1 Total TweetBacks: (Tweet this post)


Don’t miss anything, subscribe!

Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments

LOL What the hell are you talking about? The “hello world” examples?

Nobody uses classes to generate HTML in Ruby or Grails. That hasn’t happened since the servlet spec came out.

Both Grails and Rails are MVC frameworks that use script pages for the view.

LOL, no I’ve seen other examples of content generated other than the “hello world” examples.

The ones that I don’t mind are things like messages in AJAX style apps and such. I surely wouldn’t generate mass content out of a script that’s for sure.

I think you (author of the post ) are missing a very important point about JSP. JSP was meant to be a purely rendering technology. Look at the way it’s built and IMO you can see it pretty clearly. It’s meant for something else to prepare beans, place them into contexts and for JSP to place them on the screen (document, whatever else). Scriptlets in JSP can serve only two purposes: intentional (being able to say “yes, you can do logic in JSP, what are you talking about?!”) and unintentional (if you use scriptlets you get yourself into deep crud very quickly and very thoroughly).
There are two arguments: 1) whether or not logic should be mixed with rendering or should be separated into completely separate [packages/locations/technologies]. This can be argued either way, first one it cleaner, second allows for more rapid development; 2) JSP is a rendering-only technology and warts like JSTL’s SQL tags should be shot for. I am not sure how you argue with this one but by all means, I will be very interested in comments.

Thanks for the comment Gverig! I agree that JSP was meant to be a rendering technology and I don’t particularly care for things like the SQL tags (although they are nice for quick prototypes I must admit). As for logic, if you need to do view logic I’m all for it and I’ve had occurrences where I needed to do some kind of view logic and no tag existed for it and thus we had to drop down to a scriptlet to accomplish the task.

Even when JSTL came along it still wasn’t powerful enough. One of the things that I liked about Velocity (and I believe Freemarker can do this as well) is that I can actually call methods on context items. I’ve done this with apps that complex formatting requirements and other such things. I didn’t want to do the logic in the page so I did them in a class that I had access to via a script.

I guess the point I was trying to make however was that a lot of people shot JSP down just because you could do scriptlets which really wasn’t fair IMO. JSTL helped, but isn’t perfect either. Not to mention that it can be overly verbose compared to other techniques. Why in the world did they go the XSLT route of choose/when/otherwise when if/elseif/else is so much more common??

Have you ever had to write a JSF renderer? That is basically the same thing. It makes me wonder if we are not stepping backwards instead of forward.

Don’t get me started on JSF. Talk about a backwards, overly complicated way of doing anything. Sounds great in theory, but it was obviously built by developers who have little experience building web applications. Yuck.

Web development just isn’t hard enough to justify something as bad as that!

I think one of the reasons that JSPs were attacked for allowing scriptlets but Rails doesn’t get this treatment is what scriptlets (and most of JSP in general) does to the readability of the page. With scriptlets, you see braces ({}) all over your HTML, whereas with Rails you usually see HTML wrapped in blocks which can use do…end (more readable).

Also, JSPs don’t have a standard way of writing form elements. You usually end up putting scriptlets right in the middle of an HTML tag attribute. Rails has helpers that generate HTML form elements while not ruining the readability of the view.

Leave a comment

(required)

(required)