On Apr 2, 2010, at 8:26 PM, cd34 wrote: > When writing a pylons app, how much code do you put into your > controller? > > One thought I had was to put enough code in to handle basic > operations, but, if the controller required more than 20 or so lines > of code, put that into a class or function so that the controller > itself was reasonably lightweight and easy to follow. But some > controllers only have a few actions, and putting 100 or so lines of > code into 3 actions seems functional and easier to follow with less > indirection. > > Some of my actions have 3-5 lines of code after the decorator and > definition, but, some actions are quite complex. > > Any suggestions or guidelines?
The nice thing about keeping a controller small, is when it has a lot of actions. I have a few controllers in one of my projects that are very large. Though I consider this less than ideal and when I have some time I'll likely go in and refactor to break it down a bit. I guess the issue is that while a controller might start with 3 actions, it could grow... and if you didn't keep it brief to begin with who knows when you might next have some time to refactor it. I think your thought about keeping it to 20 or less lines of code is a pretty good rule of thumb, though sometimes for a big action, I can easily have 10-15 lines merely of assigning 'c' variables, so that prolly shouldn't be a hard limit. :) Cheers, Ben -- You received this message because you are subscribed to the Google Groups "pylons-discuss" 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/pylons-discuss?hl=en.
