Laravel the best practices of 2017
As is well know Laravel is one of the best frameworks of PHP on this days, has a large comunity and an fililosophy based in simplicity.
In this article I will name some of the recomend practices, for your code be more cared and understandable for your mates.
1. Use Test Drive Development (TDD)
Although this applies to any modern programing language, in the Laravel comunity use of TDD is encouraged, with uncountable benefits build automated test will bring you peace like programer, and never will worry to break your source code when add some new features.
TDD is a part of teory of agile metodologies where this say if you have a new feature you need apply next cycle:
- Write a test
- Pass the test
- Only if is necessary
- Repeat
Recomended book: Test Driven Development: By Example
2 . For heavy tasks use Queues
The Queues allow allow time-consuming tasks to be postponed to a later time. This task can be a mail send, where the action of the same without queues would be little optimum in response time to the user.
Recomended reading: Queues Docs
3. Simple code
There is a lot of reading and much debate on this topic, a simple code does not mean having a “mundane” code or done without care.
The philosophy of simple code is totally the opposite, it means to take care and to be proud of the program that we are creating, means that our source code is not a pain for another programmer and is understandable using the conventions of the language.
On the other hand having a code with these characteristics requires precision when composing a class or method, where you can do a task in a very complex or simply directly an example of this can be:
This is a totally correct and testable way:
The same version a little more simple
Recomended talk: Things Laravel Made Me Believe — Jeffrey Way
These are some of the things I learned in the way of programming and in the use of Laravel.
If you found the article interesting (or not) leave me comments, what are the practices that you learned on your way as a programmer?
