I found myself wondering: with all the ex-zopers fleeing for the hills, or at least towards Django/Pyramid after
Martijn Faassen's pronouncement that our favorite framework is now deceased and possibly even drawing a stench; How is it that all the aspects of component which were previously deemed so valuable are now either hidden behind a fluffy Pyramid API or are not seen to be important at all any more?
It seems to me as if a lot of people have had a 180 degree reversal on previously valued architectural principles.
Of course, Martijn is now working on a new ultra light web framework called 'Morepath' which, as far as I can tell is based on flask's programming interface, Pyramid's comms layer, and reg.py which implements a component registry almost but not quite entirely unlike zope.component. I found myself wondering "why?" Do we really need another Python framework? How is it going to be better than the ones already out there? In particular, in what ways are Morepath's approaches going to be better than those of grok?
I suppose years of watching Django and Pyramid becoming steadily more popular while Zope popularity decreased must have a really bad effect on people previously so heavily invested in Zope. On the other hand, to walk away from something architecturally superior to embrace inferior tech makes no sense to me. I am not slating Martijn's work in any way, please understand, but Morepath is clearly not yet in any way mature and is going to compete with some really mature tech out there.
If I were to be forced to use a framework other than Grok, it would probably be Pyramid. I would find myself missing the consiseness of Grok though; Compare the "minimalist"
example from the Pyramid documentaton:
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def hello_world(request):
return Response('Hello %(name)s!' % request.matchdict)
if __name__ == '__main__':
config = Configurator()
config.add_route('hello', '/hello/{name}')
config.add_view(hello_world, route_name='hello')
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()
The grok equivalent is of course:
import grok
class app(grok.Application, grok.Container):
pass
class index(grok.View):
def render(self)
return 'hello world'
Of the two, which is easier to read and maintain, more understandable and intuitive?
I suppose that depends on your frame of reference. If all you have been exposed to is manually configured routes, then Pyramid's explict
config.add_route('hello', '/hello/{name}')
leaves nothing to the imagination. It's a bit less obvious that grok code above automatically configures the index view class for the traversal context, 'app'. Personally, I prefer by far the grok approach, not only for the traversal approach it takes, but for the elegant syntax it employs to do so. Yes, you can do traversal in Pyramid, but it's far from elegant- in my opinion Pyramid traversal is downright clumsy to implement. Also, I like doing traversal in megrok.rdb fronted SqlAlchemy ORM models using grok.traversable(), and with Pyramid I have no idea how to go about doing that.
IMO one benefit of traversal is an automatic mapping between url's and the data structure, which in some cases can be very useful indeed. At other times, I have found traversal to be helpful in identifying the context for the data rather than the data itself. Contrary to what some people say, traversal plays very well indeed with relational databases!
Anyway, I find it unfathomable that people seem to be willing to ignore a mature and powerful Python framework like ZTK/Grok, ostensibly for the sake of popularity, familiarity and tradition.
I for one will continue using Grok for as long as it continues to make my life easy.