On Wednesday, May 18, 2016 at 3:42:50 PM UTC-4, Scott Hunter wrote:
>
> The web2py book, under Efficiency Tricks, says:
>
>
>    - Do not put many functions in the same controller but use many 
>    controllers with few functions.
>
> When an appliance is compiled, each of the functions is compiled into its 
> own .pyc file, the same as would happen if they were in different functions 
> (although the names will differ).  So does the above recommendation only 
> apply to non-compiled appliances?
>

Each function gets its own .pyc file, but that .pyc file contains a copy of 
the entire controller -- the only difference between each of the .pyc files 
is the very last line, which has the form:

response._vars = response._caller(the_function_that_was_called)

So, even with compiled controllers, there will likely still be some benefit 
to keeping the controllers smaller (though less benefit than with 
non-compiled controllers).

Anyway, I would probably let organizational rather than efficiency 
considerations dictate what's in each controller. Chances are, excessively 
large controller files also indicate poor code/routing organization. If you 
keep your code well organized and your URL routes sensible, you probably 
won't have a lot of large controllers.

Note, you can also reduce controller line count by moving some of the logic 
into modules and importing (this will be even more efficient than 
compiling, as once a module has been imported, it doesn't need to be 
re-read at all).

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to