opinions: one program or many smaller programs?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
CyborgPrime
Forum Newbie
Posts: 3
Joined: Wed Nov 12, 2008 2:31 am

opinions: one program or many smaller programs?

Post by CyborgPrime »

Hello-

I have a question- I almost always code my php as one self contained program, but I noticed some books recommend making a separate php program for nearly every function.

Aside from modularity, what would be the advantage to making many small subprograms rather than 1 self contained program - seems like a maintenance nightmare to me..

Also I suppose one advantage might be that only the sections of the program that need to be running are loaded, slightly improving the speed of the code.

*edit - also passing things back and forth between sub programs seems like a good way to invite bugs..
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: opinions: one program or many smaller programs?

Post by josh »

There is no commonly accepted definition of a program. In practice, a program is any portion of a "code base" that can fulfill it's purposes without having to have the "rest of the system" around. In that sense, a line of code, a function, or an object could be a program.

In practice, it is good practice to encapsulate code into "programs" that can be re-used across code bases. Most experts commonly agree that objects are far superior method of organizing program logic.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Re: opinions: one program or many smaller programs?

Post by Chris Corbyn »

If you can split your program infrastructure into "services" then you can go ahead and break those out into separate applications. The benefit being that you can maintain and upgrade each one independently of the other, or share certain "services" between applications.

A good examples would be an e-commerce service which is running a REST API with it's own DB so that you have an abstraction layer between your commerce code and the payment gateway(s). Now if you have 3 or 4 applications owned by the same company, they can keep all of their commerce business logic/reporting/reconciliation tools in one centralized location.

I think you have to draw a line somewhere though. You probably can't (and shouldn't) split that many components of your application into their own web services.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: opinions: one program or many smaller programs?

Post by josh »

Having your system send messages between different services is a recipe for problems. I'd always prefer the code to reside on one server, however, if your code is properly modularized, you should be able to take it and use it apart from the rest of the system. The easiest way to measure that is with a unit test.
Post Reply