I can’t explain the entirety of why I prefer Grails over any PHP framework, but here’s a few:
GORM – the ORM tool with Grails – makes it easy to express relationships and queries programmatically. Having ‘typed’ class properties allows the framework to infer much more about how to operate than the simple “public/protected/private” which PHP forces on you.
Private by default – all class properties are private by default, unless otherwise specified. getters and setters are created during compilation, but can be overridden with manually-written code. This saves a tremendous amount of boilerplate code that people used to write in Java (and now most PHP frameworks emulate, because the PHP language itself doesn’t support any other approach).
Domain-driven design – data models are created in ‘domain’ classes, which are inspected and DB models are created automatically, including relationships, timestamp columns, and automatic ids. Plugins exist for audit logging for any data changes. This allows me to simply design my data objects and run the app – the creation and management of the database (whichever one I want, and Java supports many DBs) is handled for me. Yes, I can override it’s behaviour and decisions if I want to, but I rarely want to do that. Additionally, coming preconfigured with an in-memory database allows for rapid sketching out of ideas without even needing a ‘real’ database to start with.
Scaffolding – some PHP frameworks offer this as well, so it’s not a total win just for Grails, but it is something which allows people to be pretty productive very rapidly.
Yes, this is a PHP website, and yes, I still use PHP on a regular basis. I would still encourage people to look outside of the PHP world to learn from other camps, and take time to study those ideas and implementations. You will look at PHP differently, and likely be a better developer for it in the long run.
]]>