Welcome Guest, Not a member yet? Register   Sign In
Controller File Size/Length
#1

Hello All !!!

Thanks for reading this !

I am a self-taught programmer... never had a teacher or anything like it... Just foruns, books and documentations...

Shy

I have a question regarding the size of a controller file.

Is it OK for a controller to have 2000~3000 lines ? Should I divide it into 2 controllers ?

My question is about best practices, but, it is also about server resources ! Will a "big" controller consume more memory than a "small" controller?

THANK YOU ALL FOR HELPING !
Reply
#2

It sounds to me like bad design, but I guess it could be alright. I would separate the database logic into models. Other than that depending on what it is your controller does it may be alright.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Reply
#3

I can only say is: Skinny controllers, fat models
Reply
#4

I have one controller here with 15K+ lines, other than navigating the source, haven't really noticed any resource issues.

Said that, there are few things to consider.

Purely from development point of view, it's much easier to put business logic in models, in case same functionality needs to be used from multiple endpoints. Learned it hard way, we had split apps for main application and registration page, and at some point some password rules changed, which were updated on one, but not other. If we had kept that logic in model, it would have been updated on both sides.

I'd say skinny controllers fat models is very reasonable way to organise your code.
Reply
#5

2000 - 3000 lines is still Okay. I think even 10,000 lines of source code is still okay as long as it applies good algorithm and MVC rule and make it the code easy to read, such as pay attention about indentations.
In addition, especially for speed, the first part to execute in Controller is construct method, if not so many libraries or class load there, for example Models, let's say under 5 models not load there, it is still okay, i think.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB