I’ve just finished reviewing Carlos de la Guadia’s Grok 1.0 web development in the train on my way to Berlin for the EU Django conference :-)
End verdict: solid book that explains everything you need to get going with Grok. Also valuable as reminder when you’re more advanced as it is handy to look up, for instance, how to best deploy your application or how to set up users and security.
Next, I’ll give my notes on a chapter-by-chapter basis, as that’s the handiest way for me to give my feedback on the book.
Chapter 1. Grok intro. Grok has three good things going for it: Zope’s component architecture; the object database; object publishing and traversal. All three are explained. The Zope component architecture (ZCA) is, due to its brevity, hard to follow if you don’t know the terms (“adapter”, “utility”) beforehand. Traversal: it just works. You can have an arbitrary hierarchy of objects and Grok will traverse them just fine. Packt’s default layout (huge headers, also for “h3” headers) bites this chapter as page 12 just overflows with headers. Not the author’s error, though :-)
The comparison with ruby on rails and with Django are pretty much spot-on. Grok is heavily inspired by RoR’s “don’t repeat yourself” and “convention over configuration”, but combines those with Zope’s strong and clean component architecture. Django also likes those two RoR characteristics. Django is more focused on relational database back ends and wants to keep most major parts private (its own ORM, its own template language, etc) to keep Django’s admin interface working. Grok doesn’t provide such an admin interface, so it is more free to reuse, for instance, sqlalchemy.
Chapter 2. Starting with Grok. Grokproject is a handy tool to generate a Grok project complete with a buildout environment. It is basically a well-tweaked wrapper around the Paster code generation tool. You get a working application right out of the box, ready for customization.
Chapter 3. Views. As this is the first foray into customization land, some of Grok’s conventions need explaining. Followed by a LONG explanation of Zope’s TAL/TALES template language. Seemingly every Plone/Zope/Grok book needs one of those. Powerful template language and nicely integrated with html, unlike Django’s curly braces stuff. The advantage of Django’s curly braces stuff is that it needs less explaining and that it is less verbose than TAL’s html/xml attributes. (I still really like TAL, btw).
A good thing about TAL is that it is easy to put dummy data in a valid template so that you can see what you’re doing. And so that you can already do some css. And you can build up a proper page and flesh out what data you’re going to need from the code before even diving into python. That way, you get better code. The book does this, too.
Chapter 4. Models. By default, Grok uses Zope’s object database (ZODB). Which is a more natural fit for python objects than an sql database with an object-relation mapper (ORM) around it. The chapter nicely shows the advantages. Including the container mechanism with which you can build arbitrary hierarchies, should your data call for that (think content management system or intranet, for instance).
Chapter 5. Forms. Every framework has a mechanism for generating forms from some schema. Grok does too and the book explains how, including a handy list of all available default schema types (choice field, URI, TextLine, etc).
Chapter 6. The catalog. Or: the jackpot! If you use the zodb, you can add indexes to aid you in searching ALL your data. Full text search in all your various text fields, anyone? Pure luxury. This chapter shows how Grok helps you in setting it all up.
Chapter 7. Security. Zope’s and thus Grok’s security mechanism is powerful. Per-object security out of the box instead of class-level security as offered by default by most other frameworks. It does mean that the chapter is a tad hard as there are a few layers of concepts to work through (users, principals, roles, policies). And some of it is defined in an xml configuration and some of it can be elegantly configured right in the code with Grok statements. The chapter also explains how to add a “pluggable authentication utility” that actually does the authentication and so. I’ve always wondered why one isn’t already included in Grok: I’m so used to having one available from my Plone time... Anyway, the chapter explains how to set one up by hand.
Chapter 8. Layout. Grok has a nice way to set up your templates: a lot can actually be handled in code. The template says to render a viewlet manager and the code takes care of registering small viewlets to those viewlet managers. That way the template doesn’t have to bother about the number of menu items, for instance: it just renders the menu viewletmanager. Real handy to selectively inject something into the template from an object that actually knows best when something is needed. Nicer than Django that doesn’t have something like that out of the box: you need to set something up yourself.
Before getting to that viewlet stuff, the chapter explains how Grok looks up objects at all and how it renders views and templates after that. It came as a bit of a surprise to me to find it here. Perhaps it was the best place after all.
Grok has an opinion about layout. Django (which I’m working with now) basically has no layout story: you need to set that up yourself. The assumption clearly is that you’re better off setting it up yourself after all as sites’ needs are wildly different. On the other extreme, Plone really has a layout story, coming with a ready-made layout and a big main template.
Chapter 9. Grok and the ZODB. ZODB is that super-de-luxe easy-as-pie python object database, remember? This chapter explains the ZODB details like ACID, transactions, ZEO replication (really easy to set up replication of your database!), packing, etc. Good explanation.
Chapter 10. Grok and relational databases. You didn’t think Grok would leave relation databases in the cold, now would you? This chapter shows you how to tie sqlalchemy into your Grok project so that you can use sql objects as first-class Grok citizens.
Chapter 11. Key concepts behind Grok. Grok uses all of Zope’s component architecture. Interfaces, adapters, events, etc. All are explained in this chapter.
Adapters are the things I miss most when developing with Django now. I’d really have to look into using it. You can use interfaces/adapters without pulling in the whole of Zope, so there’s nothing really stopping me... I often have to render something on a map, so just calling for an adapter to IMapRenderable or so would be handier than registering stuff in setuptools entry points or in custom registries. BFG, another framework that uses some Zope machinery, advocates wrapping all the Zope machinery in a small number of custom api methods to hide the complexity (if I remember their docs correctly). That might be a nice idea to try out.
Anyway, the chapter is very useful. A good intro on the various Zope concepts that Grok uses.
Chapter 12. Grokkers. Hey, grok makes configuring your application and setting up the Zope machinery easy. No xml sit-ups. You can do that yourself, too! Build your own grokker. This chapter explains how. For those coming from the Django world: Django effectively does something similar with its model classes: there’s a whole lot of setting-up going on behind the scenes when you add one extra field to your model class!
For me, the chapter had a funny detail. As example, it set up a configuration mechanism for sending emails. That’s the very same subject on which I worked on a grokker last year. This chapter sure would have been a great help to have had next to my keyboard then!
Chapter 13. Testing and debugging. Not much to say here. Grokproject sets you up with a pretty good ready-made testing setup. The chapter shows you all the basics.
Chapter 14. Deployment. Also not much to say here. Solid chapter. The hint to use mod_wsgi is a good one. And providing an explanation on how to set up zeo database replication is good. Setting it up is not hard, but you do need an example configuration.
Again my end verdict: solid book! Recommended if you do grok development.
(There’s a translation into Armenian for this article, too).
My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.
Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):