Wednesday, February 8, 2012

Grails, Bootstrap and a pile of crap

Today we're going to pick on a good idea gone bad. The good idea being the ability to kickstart a Grails application with Bootstrap from Twitter. What's gone wrong is the actual implementation. But let's start from the beginning.

Create a new application

grails create-app example
You've seen this over and over again, right? Nothing new here. Let's install the kickstart-with-bootstrap plugin. For that in Grails 2 we'll modify the grails-app/conf/BuildConfig.groovy's plugins file like this:
plugins {
    runtime ":hibernate:$grailsVersion"
    runtime ":jquery:1.7.1"
    runtime ":resources:1.1.5"

    build ":tomcat:$grailsVersion"

    compile ":kickstart-with-bootstrap:0.5"
Easy enough. Let's compile the application first (grails compile) for the build system to fetch all the plugins and do its other bits. After that we'll execute grails kickstart-with-bootstrap (the one that just came about with the kickstart-with-bootstrap plugin), answer all questions positive and we're done. At this point you can create a domain class and a controller but that's not really the point of this blog. The point here is to pick on the way the master kickstart layout looks like.

The good part

Well... the appearance is really great! But let's face it: it's so because Bootstrap looks great. It has all the usual stuff, the top bar, nicely looking fonts, the layout is floating. That's all nice and dandy...

The ughly

Let's open the newly created grails-app/views/layouts/kickstart.gsp. Here are a few points I'd like to make:
<%--  <div class="container">--%>
What for the love of god was going through the author's mind to leave commented out code in official release? And believe me this is not a single place. There are actually 21 of those!

But that's as long as purity goes - let's try to find something scarier:
   <g:if test="${ params.controller != null
      && params.controller != ''
      && params.controller != 'home'
      && params.controller != 'login'
I mean what the heck is this?! We're in a reusable layout! Ok, you might think I'm bitching about one place in the layout... Well actually no. There is more:
class="${ params.action == "list" ? 'active' : '' }"
class="${ params.action == "create" ? 'active' : '' }"
So a list should be shown, right? Or maybe we're actually creating an entity... Hm,... What was going through the author's mind at this point???

Does it by any chance belong in a reusable layout?!


I personally think that such a plugin is a blessing for someone that starts a new project now and then. The original Bootstrap plugin just doesn't cut it. But for the love of God do it right! By providing such a half-done tool to others you're actually doing more harm than good.

I'd love to get in touch with the original author to straighten things out. I love the idea of having a plugin that supplies a set of scaffolding templates and a layout to get me started with a nice look and feel quickly. Never mind the fact that it doesn't use the resources plugin. I actually like it. But it needs to be done the proper way, the way it is reusable!


Burt said...

Why publicly yell at the guy? Did you even attempt to contact the developer and suggest constructive changes?

Matthias Hryniszak said...

I realize I might have gone a little hard on him... But honestly I'd love to see someone go really hard on me if I do something wrong so that I can go and learn to do it right.

Plus you really need to remember that the lower quality the plugins are the overall platform with its surrounding ecosystems gets a worse overall impression.

Matthias Hryniszak said...

And yes, I did contact the guy and offered help in bringing this stuff to the level. I think the idea itself is brilliant - it's just the way it was done that's wrong...

Burt said...

So if he's willing to accept your help, why be a jerk? I've seen some ugly code in plugins, and usually send a GitHub pull request or a patch.

Matthias Hryniszak said...

You're probably right... I need to get on the level too. Thanks for reminding me!

Aaricevans said...

You have done a great job by sharing this informative post. I would like to appreciate your good work and also would like to encourage you to keep it up.
Magento Development

Anonymous said...

I agree with Burt there Matthias. When imperfection is flamed, it discourages imperfect people to contribute something. I put myself in that category. You're a big scary developer guy :)

I've been trying to get r:require module="bootstrap-css" working in my grails app, wondering why Grails 2 doesn't use bootstrap by default. I was sure they would. Or a simple example at least!

Matthias Hryniszak said...

I agree to the extent that there is an opportunity in having lots of people working on the platform. Where I disagree is when people publish as "release" something half-done, with quality perfectly reasonable to speculate on and call it a day.