2 good ways to code - Resemble or Assemble?
When it comes to web development the choice of your technologies can ensure at some 70% the chances to build something strong. Creating every single piece of our projects was the old tactic many of us started from. A lot of issues happen with such techniques which go from simple bugs to dramatic security issues since you have to handle a lot of things by yourself such as caching, security, database, routing, etc.
Although everyone involved in such practice swallows his/her problems and makes it his secret, it's still there and those who are much worried about the quality of their code do not hesitate to go out and start looking for standard codes and practices.
Today, time has changed and we have evolved. We have better and more secure tools/solutions which enable us to quickly start any project in no time which has been developed by experienced developers and teams. In that, we have full-featured frameworks, micro-frameworks, and components from other developers.
Although there are still a lot of debates on either to go wild with raw code or use a well-tested framework, every conscious developer should know that frameworks or at least third-party component aren't something to avoid in most cases. There are a few reasons for that:
- Need for security
- To save time
- Easy code maintenance
- Learn from professionals or other coders
- Flexibility in collaboration
- Speed
- contribute to the open-source
- etc
As I discussed this recently. One must go for a framework sometimes, but not all the time a framework can do the deal. Plus, using a framework means having the same code base(structure) as many other millions of codes in the world. What I call resemblance In some cases one might need to go raw. Going raw too implies many other ways among which we have the shopping of components piece by piece. What I call assembling.
In this post, I would like to discuss some pros and cons of these two techniques of coding.
Resembling
A well-known and well-used technique. This is a principle through which most coders go from the same base of code. This tactic may maybe been the source of most frameworks. People thought of creating frameworks because they wanted to avoid the same routine every time they were starting a new project. It was therefore important to put in place a model(framework) to use.
This technique has gone very fast and far. It's used in both front-end development with frameworks like Twitter Bootstrap, materialize, foundation, etc, and in back-end development with our giant ecosystem of frameworks like CakePHP, CodeIgnator, Symfony, Laravel, etc.
Pros
- Fast development
- Good file organization
- Database abstraction
- Easily adaptable to the MVC model
- Tested by many people
- Validation
- HTTP messages handling
- Efficiency
- Good coding practice
- Easy routing
- Modern template systems
- Many ready-to-use modules(authentication, pagination, etc)
- etc
This is probably a few of them. One of the best cases to use a framework is when you work on huge and collaborative projects.
Cons
- Not adequate for small projects
- Requires another learning time
- Require a good level of core language
- Difficulty in choosing a framework to use
- If the framework is no longer maintained, it may impact your project
Of course here too, it's just a few. Depending on a case those may constitute or not a problem.
Assemling
Unlike resembling, this technique is not used a lot, for it requires some coined understanding of a programming language. This is rare in the communities. Fewer people use it and less know about it or how to go about it. It's mostly used by people who have deep knowledge of programming languages and its environment. It's a technic widely used by frameworks. Check most frameworks files, they are brought in piece by piece from many vendors. It's the core principle of micro-frameworks. Start from just the minimum. Then shop for every piece needed. No left-over pieces. Everything brought has its use, otherwise is no need to use it. This is a modern form of coding from scratch. Most micro-frameworks are halfway through this technic, then you can top up.
Normally if you are creating an application using a framework, all you have to do is to grab it and you can start, but when assembling you pick all packages you may need one by one. For example for a website I could pick up HttpFoundation and HttpKernel from Symfony to handle HTTP messages, then I pick up nikic's fast-route for my routing. I can also get respect validation for my validation issues. If I have to work with databases I could grab laravel's illuminate database package too, and so on.
This looks simple and fast to do. You build up your application with only the needed tools.
Pros
- Fast & sure
- No overload
- Easily maintainable
- You add or remove any piece at any time
- You can build your own code on top
- You decide on your code structure
Cons
- May become hard to handle in time
- Component interop might cause problems
- Too much freedom could lead to non-respect of some coding standards
- Need to be an advanced coder
- Need to learn how each component you use works
- You may use unsecured/untested packages
- You may not have packages for some tasks
In this technic composer and packagist could be your good friends.
Wrap it up
The two ways of building are great. The cons are not that bad to prevent you from going for one or another. In all these two ways of building require a good understanding of your programming language and most practices.
I personally prefer the second method if I don't want to think of writing my own framework(something you need to think twice before doing). And recently I started getting very used to slim micro-framework. I feel too lazy to learn a whole framework, though I love them. I rather learn them through their packages one by one. Laugh at me.
Good, as usual, I never hide anything I know from you. This is another piece of my discoveries. If it added something to your day, kindly share it with your friends.
Thanks for reading.
Cover photo credit: Jing and Jang via photopin (license)