Magic is to Python as Java is to PHP
travisswicegood.com
travisswicegood.com
Apparently, in "PHP circles" they don't like object oriented design because PHP isn't Java. I'll go inform the Zend Framework and PEAR communities that they're doing it wrong...
I disagree with the author, however. I think that magic is a bad thing, but this is really an in-house debate. Django and Zope are on the extreme ends of the spectrum of Magic to non-Magic, and I have worked in both frameworks.
Magic does not necessarily mean "poorly defined" as some people presume. Zope does an excellent job at defining the magic that it does. I just do not like the concept of a framework that changes the essential nature of the language in which it is written.
I think of a framework as a way to avoid writing the 80% of the code that any given web application needs. One could say, well, that 80% is magic, because it just happens, but there is a fundamental difference between a framework that changes the nature of your code, adding behavior that you would never suspect from the language itself, and a framework that provides functionality that you either invoke, or add to.
Magic is great for some people, but a real PITA when you don't want the magic to happen in the way it does. Suddenly you find yourself delving deep in to the guts of the framework, reverse engineering the decisions made by the developers, finding workarounds. Suddenly the magic becomes an impediment - you are now expending much time and effort working through a system whose entire point was to save you time and effort. The framework is no longer the elegant helper taking away a lot of work that you would otherwise have to do. It IS the work you have to do.
Again - this is an in-house debate, and no doubt a die-hard Rails developer will disagree, as is their right. But for me, I much prefer as little magic as possible.
The Zope community learnt many lessons from the magic used in Zope 2, and radically altered the fundamental patterns for Zope 3 away from magic.
These days people who live in Zope 2 environments (eg Plone) make extensive use of Zope 3 technologies and patterns via the Five (2+3) bridging mechanism.
Ie, in the Zope world at large, "non-magic" is now considered best practice; its not fair anymore to consider today's Zope a framework that changes the essential nature of the language.
Its been interesting to see the initial Rails elation getting tempered later by grumblings about the pricetag of such magic; the Zope world had gone through the same thing but a few years earlier. Today's Zope has already learnt from this and moved on.
In fact the community has even been able to combine some of the philosophies of Rails (eg avoiding XML sit ups) with the Zope 3 paradigms, to create the Grok framework which remains wholly Zope 3 compatible. This really has the potential to strike a good balance.
First off, an IRC channel does not speak for a whole community of users, and an IRC channel that covers a topic that a subset of a community is interested in certainly doesn't cover whole community of users. I mean, Python isn't PHP, it has a lot of uses outside of web development and they don't know or care about the feelings of the #django and they probably don't know what this "magic" thing is either.
Even so, nobody in the world should ever say "Wow" to anything anyone ever does on IRC. It's all happend before, it will all happen again, it's filthy, it's nasty, it's IRC.
Or to paraphrase a great character:
IRC. You will never find a more wretched hive of scum and villainy.
At any rate, so far as I can tell the author doesn't know Django very well, which is fine, I don't know it that well either, but rejecting "simple solution #1" that requires writing: login_required(some_view)
Instead of login_required('some_view')
Because you want to specify all your views by module path strings instead of actually importing one... that's just silly. What is wrong with importing a view to pass it to a method? Nothing, as a fan of Python for the past ~8 years, nothing is wrong with that, it's simple, it works, do it. If it offends your sensibilities, well, your sensibilities are silly.Never mind the "simple solution #2" (in the comments by ez, but someone on IRC should have thought of it):
@login_required
def limited_object_list(*args, **kwargs):
return object_list(*args, **kwargs)
Yes, crazy simple, a tiny, itsy-bitsy wrapper that does exactly what you need it to do and lets you keep your urls.py looking how you want it to. That would have been my route (although once you have to write actual view code you might as well write your own view, after all the generic views are just there to solve common use cases and they are called "generic" views instead of "customizable and flexible" views for a reason.. besides, they are easy to reproduce if you need more complex view logic).So, instead of the existing, simple and working solutions the author wants to add a login_required argument to every generic view, instead of just using the existing, simple and working solutions?
Yeah, that makes sense.
Once you've been burned by it a couple of times, you become very wary.
I think python is somewhat of a refuge for people who have learned the dangers of magic the hard way and decided it should be avoided when it isn't necessary.
What originally attracted me to python was that I wanted a non-magical perl.
That may not be such a big factor anymore, but it shaped the language and culture.
"In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it."
This guy wants dependency injection, which would solve his problem, and is as non-magical as it gets.