I'd also be interested in the memory usage of strings vs. importing
the functions directly.

At work, we tend to use the string method when it's an undecorated
view function, and the pythonic way when we're going to decorate them:
usually caching, but sometimes login_required, etc.

The mixing and matching doesn't read as bad as it might sound :-)

Chris

On 7/10/07, Sean Patrick Hogan <[EMAIL PROTECTED]> wrote:
> That's a good question and one I don't know the answer to.
>
> But here's one thing to keep in mind.  Let's say that introspectively
> looking up a function is 4x more costly.  If I have 8 entries in my URLConf
> going to different functions, calling by string is 2x faster.
>
> Plus, there's the issue of memory which might be more important than
> processing power as web apps tend to be memory-hungry more than processor
> hungry.  I'm guessing loading the functions would take more memory than
> calling by string.
>
> In the end, I don't think it will matter in any app.  One should probably
> pay attention to what's in their functions more than how they load them.
> That's where the real problems are going to be.
>
>
> On 7/10/07, Kevin Menard <[EMAIL PROTECTED]> wrote:
> >
> > On 7/10/07, Sean Patrick Hogan <[EMAIL PROTECTED]> wrote:
> > > The "pythonic" way is a new addition to Django if I'm not mistaken.
> > >
> > > I personally prefer calling by string because (I'm assuming here) it
> doesn't
> > > load the function unless it needs to.  So, if I have a URLConf that
> > > references 8 view functions, it only imports the one for the correct URL
> if
> > > I call by string which saves me from loading 7 functions that I'm not
> using.
> > >  If I import them all at the top, I'm importing functions that may have
> > > nothing to do with rendering the current page.  Of course, the impact on
> > > resources is probably minimal to none, but it still means writing less
> code
> > > to call by string.
> >
> > Sorry to be taking this a bit OT, but you raised an interesting point.
> > Do you happen to know what the cost impact is for importing a
> > function into the current scope VS the cost of introspectively looking
> > up a function?  Is either cached or is this done on a per request
> > basis?
> >
> > As an aside, I prefer the pythonic way because PyDev is able to give
> > me some help with auto-completion, which tends to mean less errors due
> > to stupid typos.
> >
> > --
> > Kevin
> >
> >
> >
> >
>
>
>
> --
> www.PovertyFighters.com
>
> If you knew you could fight hunger and poverty, conserve the environment,
> empower women, combat AIDS, improve labor standards and win a national
> competition for your university--all with only two clicks a day--would you
> do it?
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to