Motivation

In software development, most of the time what you need is a small piece of code to run. If you are working with a framework, it becomes very heavy to do simple tasks in shorter times. That’s why I decided to write my own framework for my daily tasks.

To write or to not to write

There are hundreds of frameworks out there, of course it is very unnecessary to write your own framework! Well, this almost true, except when it comes to start working on your custom product. If you want to write a crawler, a trading simulator, a repetitive task handler, it’s best to work on a very lightweight framework so that you don’t have to waste time on getting rid of the heavy parts of the bigger framework. Lets consider what do we have in the market for PHP.

Drupal

Even though it is considered as a CMS, Drupal actually became a framework and attracted many developers to contribute to the project. But the very idea of Drupal does come from ‘less code writing’. Drupal tries to speed up the project by reducing the number of lines that the developers are writing. If you need your corporate website, a CMS to manage your content on your website, manage your landing pages, news, articles, than Drupal is cut out for the job. But if your project requires and appointment mechanism, a custom behaviour e-commerce platform with multi stores, or a CRM, you should consider other solutions. You might ask ‘but there are modules for all the things that you have listed’, which is true, but it is a horrible idea. Because to extend the functionality or to manipulate over the existing module’s behaviour is nearly impossible. Even if it’s possible, it’s always a work around which will become a burden to maintain. You can’t (and shouldn’t) hack into the module code and change anything manually, because they will be overriden on a module update. You can try to write your own module to use certain ‘hooks’, ‘pre_’ functions to override the main modules behaviour, but that will be so much time consuming and exhasting. Writing everything from scratch is literally the only solution most of the time. No modules comes with a perfect solution for your customers’ needs, they will always, always ask for another feature or a change on the behaviour.

Laravel

Laravel is pretty cool, there is a big community behind it, it’s taking advantage of all the modern day tools and there are many modules that you can use out of the box and still can build your custom work without. But it is enourmous. It should only be used for exclusive solutions. Because you need to invest on Laravel too much. Learning the API is like learning another language. Software developers knows that it’s so easy to forget about the technology that they use for years when they start to work on another project. There are a million products out there and it’s impossible to be fluent on all of them at a given time. One can jump in between languages, work on a project using lets say nodejs, then jump on python after it’s completion, then focus on SQL heavy project. But after months, when you visit your nodejs project, you simply don’t remember anything as if someone else has written that code. You need to get familiar from scratch, remember the syntax and switch to that language. Considering the ecosystem growing out of control, jumping in between languages is a pain. When even this is a big problem, remembering the syntax of a framework is nearly impossible. I remember how many times I start reading the documentation from scratch when I am re-boarded to a former project. It’s just unsustainable in real life. If you are one of those lucky guys working for a giant like Nokia and only have to deal with a certain language/framework, then fine, good for you. Otherwise, any other huge framework is just a pain, especially for smaller tasks.

Look at this Request sample from Laravel

Route::get('/user/{name}', function ($name) {
    //
})->whereAlphaNumeric('name');

There is no way one can remember this syntax without checking every element on this example.

Slim framework

So why not using a micro framework like PHP Slim? Well, lets see an example:


$app = AppFactory::create();

$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
    $name = $args['name'];
    $response->getBody()->write("Hello, $name");
    return $response;
});

$app->run();

Does it look like something that you can remember visiting your project after a few months? To me, the answer is no. Lets say it’s no big deal to read the documentation, but how long will it take to check the documentation? I checked their documentation and it’s 44 pages long. It takes days to read everything from scratch. So it really does not look that slim to me.

What would be great to have on a micro framework?

Well, that’s pretty much it! Let’s get to work and start writing our micro framework!