I think this is probably fine in a model file. You've got references to a number of web2py globals in those functions, so if you move them to a module, you've got some extra hassle importing framework classes and passing globals as parameters. If at some point you've got *a lot* of long functions in models (particularly ones that are only occasionally used) and it becomes important for you to shave a few extra milliseconds off of each request, then maybe think about moving them to a module. Don't worry about optimizing too early. Anthony
On Wednesday, April 13, 2011 8:26:17 PM UTC-4, 黄祥 wrote: > hi antony, > > thank you so much for your adviced, in my case (please see attached file), > would you prefer to put it on models or modules? > right now i put it on models, please give an advice or suggestion? > > thank you very much in advance. > > steve van christie > > > On Thu, Apr 14, 2011 at 7:17 AM, Anthony <[email protected]> wrote: > >> If it's just a few (small) functions, go ahead and put them in model >> files, as reading a few extra function definitions will probably have a >> negligible impact on performance. In particular, if the functions are used >> in many/most requests, you would save little by moving them to modules >> because you would end up importing them on most requests anyway. >> >> On Wednesday, April 13, 2011 8:11:00 PM UTC-4, 黄祥 wrote: >> >>> hi, >>> >>> i try to follow the advise about functions from : >>> http://web2py.com/book/default/chapter/11#Efficiency-and-Scalability >>> >>> - Minimize the code in models: do not define functions there, define >>> functions in the controllers that need them or - even better - define >>> functions in modules, import them and use those functions as needed. >>> - Do not put many functions in the same controller but use many >>> controllers with few functions. >>> >>> i have a functions (e.g, add data, select data, update data) that been >>> used in many controller, i got an adviced to put my functions on the >>> models instead of on modules to make it simple, but the book said do >>> not define functions in models. >>> my intention is not to repeat the same code in many controller >>> (inefficiency) and make my code simple >>> >>> any suggestion or advice for this? >>> >>> thank you so much. >>> >>> steve van christie >> >> >

