Coding and thinking in modules

I like to program. I have great ideas and like to put them into code. What I do not like is the over-complication of things.

Usually when someone creates something, it begins being small and useful. Over time as one adds functionality, things start to complicate. Here is the problem.

I like to make small and useful things. A script, code, or even a class system has to be understandable and logical. I had to learn a lot and make a lot of mistakes to realize that in order to make something simple and transparent, even if it has a lot of functionality, one has to think in modules.

When building an application, all the parts we want to use are usually written. All we have to do is gather these modules and use them.

A very easy way of gathering pre-written modules is to use Composer.

https://getcomposer.org/

This is a PHP dependency management tool. Very easy to use and a lot of fun.

Now, we gathered all the modules we want to use.

Then next step I usually use is write the logic of the system, simply in data classes and logic classes. The more the functionality is broken down into classes, the better.

This part usually does not contain any reference to external modules, classes, file, or anything. It only uses things defined within. In order to communicate with the outside, I use interfaces. Every module that needs to be used in my system gets an interface.

Now we have 3 clearly separable parts. One is the logic of how my system has to work. The second is the implementations of interfaces using the modules and the third part is the modules themselves.

Since the front was not mentioned, we can view putting data out to the front as one of our system’s functionality, thus using a module to present data on the front, so we will not need a new layer.

Probably some want to put the controllers in a new layer, but that is ok and logical, but in my opinion, not necessary.

 

So, this is the style I work in. This way everything gets easy and transparent, manageable and upgradable.

Here are some useful tips and tricks:

http://www.phpdeveloper.org.uk/articles/php-coding-guidelines/

http://www.ibm.com/developerworks/rational/library/nov06/pollice/