Page 1 of 1

opinions: one program or many smaller programs?

Posted: Mon Apr 19, 2010 5:33 pm
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..

Re: opinions: one program or many smaller programs?

Posted: Tue Apr 20, 2010 5:56 am
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.

Re: opinions: one program or many smaller programs?

Posted: Thu Apr 22, 2010 3:50 am
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.

Re: opinions: one program or many smaller programs?

Posted: Fri Apr 23, 2010 1:59 am
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.