Re: functions, the best way to implement and arrange them..

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

 




On Jul 12, 2011, at 7:28 AM, Taco Mathijs Hillenaar-Meerveld wrote:

It might be a simple question for the local die-hards among here, but i'm
really wondering about how
developers arrange their scripts and keep their map structures.

today i was looking for the best way to keep my scripts clear and to put
them into maps so i have a clear overview.
the same thing i would do for the scripts, using the functions i have and
throwing them in 1 or more php documents.

i can not find it how it should be done. is it a good idea to put a couple
of functions in just 1 document?
like sessions and login/logout functions?

in my idea i would only need to include a document in the header of my
website and then i'm done, right?

some thoughts, ideas and tips would be appreciated.

kind regards

taco

Arranging functions, classes, and such into files is something that we've used in software engineering for a long, long time. There are some general concepts:

* Keep your files fairly small and concise. Don't put everything in one file. * The contents of your files should be logically consistent. Group functions which work on similar sets of data, or do similar tasks, together. * Classes are a great way to go with grouping functions that act on a cohesive set of data. Generally, one class per file is a good rule of thumb, although there are also cases for including more than one class in a single file. * Functions and methods should be cohesive; they should do only one thing. You can have several functions in a file, and you should have several methods in a class. * Grouping functions temporaly is generally a bad idea. The conceptual exception to this is having a single configuration file for setting up variables in the program that might vary with installation. This isn't really arranging functions, though, as it's generally just setting and initializing data for the application. * When you are writing functions and classes, work to make them general case and reusable as much as possible * It's okay to have included files include other files; in fact, this is generally How It's Done. Remember to use include_once and require_once where appropriate.

Some reasonable chunks of files:
* session handling - it's nice to include all your session handling in one file, this is where you may want to set up a class and instantiate it. * database access - also nice to be able to abstract out database setup and calls * database migration - another area that can easily be separated from the whole * models - each piece of business logic would be a good fit for a separate class and/or file * views - keeping with the tradition of separating logic from presentation, keeping the code for presenting the page in separate files is also a good idea * authorization and access control - if you choose to write your own, keeping it separate from the rest of your application is a great idea.
* data manipulation, string formatting, special processing



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux