Re: Many Small Files or Larger Utility Files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Stephen,

There are a lot of considerations. If you're adopting a more functional
approach, certainly files can contain lots functions, perhaps grouped
within a class as static methods to take advantage of PHP's autoloading
capabilities. I don't worry about the size of file in this case, but I do
work hard to make sure the functions are related. This helps me find and
use things later.

If you're following an OOP paradigm, then you usually try to break the code
up into classes, trying to limit classes so the have a single
responsibility. Again, while you can put more than one class in a file,
making use of autoloading is simplified by limiting to one class per a
file. When I've programmed using Objective C, I've noticed my classes get
pretty big (as this seems to be more common in these libraries), but I tend
to make my Python and PHP classes smaller.

As Per Jessen noted in his reply, I've also seen performance issues with
code bases that are broken up in such a manner that each request requires
including many files. If it's other people's code, I sometimes even analyze
the call stack for includes and then preprocess the files that are used on
most requests into one file (using a bash script, simple parser, etc.)

The one hard rule I try to follow regarding files is that I keep side
effects isolated from function/class/etc. This is probably more due to my
appreciation for Haskell, but I'm thankful it's listed in PHP-FIG, to:
http://www.php-fig.org/psr/psr-1/#2-3-side-effects

Enjoy,

Adam


On Mon, Jun 20, 2016 at 3:49 PM, Stephen <stephen-d@xxxxxxxxxx> wrote:

> I have made a number of web sites using PHP and mySQL. These included a
> control panel for adding and maintaining content.
>
> I am stepping up and creating a site that will require sessions, private
> areas and user registration functions.
>
> I have looked at samples and note that they all use many small files. I
> see that as being difficult to manage.
>
> But I have also looked at the code for a PHP bulletin board. Many, many
> small files, so I see that it is a common practise. But I see it as
> complicated and difficult to manage.
>
> For my control panel code I have all the routines, about 10, to process
> POSTS in one file. It works fine.
>
> Now activity is low, but that will also be the case with my new site.
>
> So my question: Is small, single function, files the best practise, or I
> am just fine in combing many functions into larger "library" files.
>
> Thank you for your thoughts.
>
> --
> Stephen
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux