Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 Jan. 16, 2011 09:24:57

Santiago C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

compiled methods


Hello,

is there such a thing as "compiled methods" in Django i.e. methods
whose return value is calculated only once and then stored? Or is
there a canonical Djangoish way to implement this?

An example:

Suppose we have phone objects that have a canonical form, such as
"alcatel a-341 i" and a paraphrase type p and a method variants() that
calculates all variants of the canonical form, given the paraphrase
type p, such as:

alcatel a-341 i, alcatel a 341 i, alcatel a341 i, alcatel a-341-i,
alcatel a 341-i, alcatel a341-i, alcatel a-341i, alcatel a 341i,
alcatel a341i, a-341 i, a 341 i, a341 i, a-341-i, a 341-i, a341-i,
a-341i, a 341i, a341i

Obviously it is very bad for speed to calculate the variants of each
phone object every time the object is needed for some action.

Santiago


--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 16, 2011 09:32:53

Daniel R.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

compiled methods


On Sunday, January 16, 2011 9:24:49 AM UTC, Santiago Caracol wrote:
>
> Hello,
>
> is there such a thing as "compiled methods" in Django i.e. methods
> whose return value is calculated only once and then stored? Or is
> there a canonical Djangoish way to implement this?
>
> An example:
>
> Suppose we have phone objects that have a canonical form, such as
> "alcatel a-341 i" and a paraphrase type p and a method variants() that
> calculates all variants of the canonical form, given the paraphrase
> type p, such as:
>
> alcatel a-341 i, alcatel a 341 i, alcatel a341 i, alcatel a-341-i,
> alcatel a 341-i, alcatel a341-i, alcatel a-341i, alcatel a 341i,
> alcatel a341i, a-341 i, a 341 i, a341 i, a-341-i, a 341-i, a341-i,
> a-341i, a 341i, a341i
>
> Obviously it is very bad for speed to calculate the variants of each
> phone object every time the object is needed for some action.
>
> Santiago
>
>
This is usually known as memoizing, and there are various ways to achieve
it. Django actually includes a memoize decorator in django.utils.functional,
but you'll find lots of other recipes around the web.
--
DR.

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 16, 2011 09:57:22

Santiago C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

compiled methods


Thank you very much! The term "memoize" was exactly what I was looking
for.

Santiago

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 16th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support