On Wed, 2010-12-29 at 11:20 +0200, Shai Berger wrote: > On Wednesday 29 December 2010 05:24:06 Russell Keith-Magee wrote: > > > > As for "do we intend to solve this issue" -- you haven't been exactly > > clear as to what the issue *is* -- or rather, why it isn't already > > trivially solveable using completely standard OO techniques. > > > > The real issue, as I've seen it, is not in cases such as raised by the > original poster, but in cases where the code that needs the request is > located > some distance in the call-chain below the code that has access to the > request; > then, solving the problem in the way Russell outlined involves having several > places in the code which accept (and sometimes, as in Russell's example, even > keep) a request object only so that they can pass it on.
This is a general problem in all software in all programming languages. It is called the configurations problems [1], [2], and all solutions have problems. Making request a parameter of all objects/functions means that I can't use those functions from a non-web context. Even making it a keyword arg is less than desirable, because I have to alter all these functions in the call stack, and some of them are outside my control, and some them just don't have anything to do with web requests. Using threadlocals is bad because it introduces global variables. However, the request is (or ought to be treated as) an immutable global variable, which are much better than mutable global variables, so this solution is arguably no worse than the others. Another approach is callstack tracing to find a request object [3], which makes threadlocals look good in comparison! Other languages have some different solutions (Haskell has lots, because it has a particularly powerful type system, and it suffers from this problem much more acutely than other impure languages). I don't expect we will come up with a new solution to it in Python. Personally, I will use a mixture of these techniques, depending on the context. If I use threadlocals I ensure that the code explicit handling for the case when there is no request available. Luke [1] http://okmij.org/ftp/Haskell/types.html#Prepose [2] http://www.joachim-breitner.de/blog/archives/443-A-Solution-to-the-Configuration-Problem-in-Haskell.html [3] http://chris-lamb.co.uk/2010/06/01/appending-request-url-sql-statements-django/ -- "The one day you'd sell your soul for something, souls are a glut." Luke Plant || http://lukeplant.me.uk/ -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
