And now a few words from our sponsors

Frameworks vs freeform - 30 Sep, 2023

by Maki

So, it's 2023, you're a full stack developer.

You need to build an application.

Should you use a framework or just build it from the ground up ?

 

Short answer: use a framework.

The long answer is a bit more complex.

 

Let's say you're making a website, and you primarily work in PHP.

Today there are several PHP frameworks available, such as Laravel, CakePHP and Symfony. All of them have something to offer, personally I like Laravel the best, but only because it's the one I used the most.

 

As a full stack developer, whether you're working as a freelancer or in a company, your primary concern is hitting your deadlines. What frameworks offer is a stable environment, with all the heavy lifting done, your security is taken care of, your session management is taken care of, your database connection is taken care of, all you need to do is focusing on your task and do your thing, create your project, the basic structure is done, all your libraries, dependencies, all there for you to use. The time you save is considerable. Not only that, but the structure is cleaner, everything is neat and tidy.

So why should you not use one ?

As I said, you should.

 

So what is the advantage of building an app from the ground up, if using a framework takes care of everything.

Well, this is a slightly more complicated issue. Strap on, this'll take a while.

 

What is this structure that a framework like Laravel makes ?

 

As of today, most (if not all) frameworks use an MVC structure, which stands for Model-View-Controller. A model is what takes care of the logic and the data, a view is what shows the results to the user, but here's the thing: they are not supposed to communicate with each other because you'll want your logic separated from what the user sees. All a view needs is the data it needs to display, it doesn't care how it's been manipulated, how it's being stored, what is the process to get from A to B. A controller is what takes the user input, manipulates it so that is easier for the model to operate it, then sends it to the model for processing, then, when the model is done with whatever they need to do with it, serves it back to the view for the user.

I once tried to explain it to someone who had absolutely no idea of what OOP is, or what design patterns are, and what he said was: "That just seems unnecessary complicated, why can't you just have the logic in the view?".

 

A simple example is how a restaurant works:

you have your kitchen prepping the dishes, that's the model. They are in charge of getting the ingredients from wherever they are (farmer's market, butcher, etc) and cutting, chopping and dicing them, then cooking and plating the dish.Then you have your plate nice and prepped coming out of the kitchen and getting to the table, that's your view, what the customer sees and eats.

What happens in between ?

First of all you need some way to tell the kitchen which dish to prep, then you need someone to get the dish and serve it to the table. Your front-of-house staff takes care of that, they translate what the customer asked for in a way that is easier for the kitchen to read, and then they serve the dish to the table once it's ready. Your kitchen staff doesn't actually take the order, and your servers don't work the line. Everyone has their own task and the kitchen is kept strictly separated from the tables, because they have other things to do.

So, why wouldn't you have your kitchen staff take the orders and serve the tables, that would simplify the whole process...

It would, but it would also create issues:

one: HACCP. Sanitation. You want to keep the kitchen separated from the front because there's a whole host of contamination issues that may occour when handling money, the tills, or even just the plates after they've been on the table;

two: roles. If you need to replace someone, or teach them a different skill, or how to use a different machine, or how to prep a new dish, you don't want to keep all your eggs in a single basket. It's easier if everyone has their respective role, and they are separated, so if you need to hire someone new, you only need someone with a specific skill (e.g. cooking food, customer relation);

three: if a customer needs to complain, or is unsure about what to order, that will take precious time that you could spend cooking for other customers;

four: presentation. the kitchen handles food, and they need to adehere to a specific dress code. You don't cook in a dress, and you don't take orders wearing crocs A server needs a specific image, that might need doing your hair, wear make-up, dressing nicely. A chef needs to trim their nails short, wear a hairnet, gloves, and so on.

 

So how does that apply to your app ? The same way.

If you need to create new logic, introduce new data, fix a bug, you don't have a monolith all in one place, and you won't go insane trying to find what you're looking for, and you will have less chance to mess up something that's working perfectly fine. Everything is neat and separated.

 

So, ok, a framework does that, but why whouldn't I be able to do it on my own ? Design patterns are not actually language, they are just ideas of how to do things better, so yeah, you don't actually need a framework to do that.

The answer is time. It takes time to write down things, it takes time to find the tools you need, it takes time to make sure they work properly. Let's say you're building an ecommerce app, you need to a way for the customers to get the products they need and pay for them. A shopping cart takes stuff from the view, pass them around, calculates the total, applies discounts, writes down the order, and then allows the customer to actually pay for their stuff. What do you need to do that: if you're building it from the ground up you need the actual page, your model, your controller, you need to set up your environment variables, your session, you need to set up your security, etc. What a framework does is to set up all of that for you. The legwork.

 

But what if I already have a template with all of that set up? Well... that's what a framework is. All you're doing is to use your own framework instead of one developed and maintained by someone else.

So why use Symfony, or CakePHP, Laravel, etc ?

As long as you're working on your own, as long as your basic template works, might as well not, but there are several advantages in doing it the other way:

1) Maintenance. You don't need to update your framework when something changes, like if a new version of PHP comes out, because it's maintained by a separate team. Again, time.

2) Teamwork. If you end up working with other people, it's better to know your way around a tool everyone knows, then ask them to learn the specific tool you made. That would take time.

3) A large community. If you end up with a problem, the only person who can help you is yourself, if you decide to do all on your own. Guess what, time.

 

If you need to connect two pieces of wood, you can use your hammer and nails, or you can use a nailgun.

 

So I guess it's settled then, it's always better to use a framework, then just start writing code and hope for the best...

Or is it ?

 

So far I've been praising frameworks left and right, but is it really the best to just use a framework and do your work fast ?

What I personally believe is that, in order to be as efficient as possible, you should be able to do both, but here's the caveat: if you already know how to build an app from the ground up, learning a new framework is going to be super simple, because you will know how it works, all you need to do is to connect the dots. You know what you need, you know what the requirements are, you know that you need this specific thing, all you need to find out is how to achieve the same result with a different framework.

If you start your journey by learning how to achieve something with a nailgun and then they give you a drill and screws...

Basically, by building your application from the ground up you will obtain a strong foundation for whatever you need to do next. A framework is a tool, and in order to be able to use as many tools as necessary, you need an understanding of what the task you want to accomplish is, and how to reach that goal.

 

In an ideal scenario you'll learn that in school, but let's be real, in school you'll learn the foundation to build your foundation. Actual experience is something entirely different, and I'm not harping about "formation vs field experience, which one is better", you'll need both. What I'm saying is that, while your formation is important, all you'll get is a hole deep enough to pour the concrete.

The conversation about frameworks is deeper than just "is it better to use power tools or should you know how to use your hands?", because the answer is both, you should be able to do both. I'm not saying "you should know how to do both" I'm saying "you should be able to do both".

This is just my opinion, I'm not claiming ownership of the ultimate knowledge about life, the universe and everything.

I strongly believe that in order to have a strong foundation to build a stable structure, you should be able to do everything you need to do with as little as possible, while using the best tool you have at your disposal for the day-to-day operations. You want your app to be robust, efficient, fast, strong, indestructible, foolproof (spoiler alert: not going to happen), while being able to think fast if something you absolutely need is not available to you. I made the example of MVC earlier. That's not the only thing a frameworks sets up for you, but it's pretty much industry standard at this point. You don't actually need the theory, because the frameworks takes care of that for you. All you need is a basic understanding of where to put the things you need for the app to work (oversimplification, most frameworks users know the theory as well).

Sometimes the legwork is important, and things you learn in the field are often better than the theory in school. Knowing what it takes to get there will help if you need to learn how to use a new framework, because, in the end, it's not the framework that get's you there, it's knowing where there is.

 

TL;DR: Frameworks are great, and you should definitely use them, but only knowing how to use power tools won't help if you don't have access to electricity.

avanti indietro chiudi

This website uses cookies, we have a legal obligation under the GDPR law to provide detailed information about how your data is stored and processed.

Privacy policy


This website uses a variety of high quality media provided under the Creative Commons License.

Visit our Credits page to check out those amazing creators.