Reader small image

You're reading from  Clean Code in PHP

Product typeBook
Published inOct 2022
PublisherPackt
ISBN-139781804613870
Edition1st Edition
Tools
Right arrow
Authors (2):
Carsten Windler
Carsten Windler
author image
Carsten Windler

Carsten Windler is a Lead PHP engineer at Plan A.
Read more about Carsten Windler

Alexandre Daubois
Alexandre Daubois
author image
Alexandre Daubois

Alexandre Daubois is a Symfony Developer at SensioLabs, the company that created Symfony.
Read more about Alexandre Daubois

View More author details
Right arrow

Understanding what clean code is

Clean code is the act of writing code by thinking of the future—that is, thinking of the people who will collaborate with you or on the project without you. And when we are talking about “the people who will collaborate with you”, this may even be yourself. If you never did, you should try to read and maintain the source code you wrote a few months (or years) ago. Isn’t it challenging? Well, do not worry—it is hard for everyone. You will surely find this complicated for many years, and there is no quick fix to this. It is the same process for everyone.

There are many reasons for this, as outlined here:

  • You are still learning new ways to code every day
  • You are practicing and you’re getting better at coding
  • Your way of thinking may be evolving because of the people you meet or simply because you are getting older
  • Innovative technologies and libraries are released every day, and some ways of doing precise tasks are getting deprecated
  • The language you are working with (here, PHP) is evolving and new standards are appearing

Talking about PHP, it is remarkably interesting to see the language is evolving greatly and quickly these last few years. Many called for the death of PHP a few years ago. It is true that before PHP 7, the language was truly not going well. PHP 7 and newer versions are a huge breath of pure air for us. New versions are being released frequently and features are being added to PHP (just look at the match expression and the support of enumerations in PHP 8.1!). Strict typing has also been introduced, which is a gigantic step forward too. We will dive into PHP evolutions that ease the writing of clean code later.

It does not really matter which programming language you are using—undeniably, you will get scared each time you look at some old code you did yourself. Writing your code in a “clean” way will help you to minimize this effect and understand it better, instantly, years later. By doing this, you are giving yourself a treat, because you will be coding in a way you are more and more used to—a way of writing many people are used to.

It may be the most impressive thing about clean code: it does not matter which technology you are using, which library, or even which language. It does not depend on the country you are living in and it does not depend on your years of experience, or even if you are coding for a living or as a hobby without financial intentions behind it. Clean code is a skill that at some point, every developer will improve at and face in their life. Of course, you will get better at it if you focus on it, but just learning from your experience of what works and what does not in an IT project is already, in a way, learning clean code. More than the rules, tools, and tips you will find in this book, clean code is a question of experience and years of practice. During your developer career, you will meet different challenges and diverse ways of thinking by meeting people and collaborating with numerous different teams.

You should always remember that coding is a team job. It is rare now to work alone on a project without the intervention of other developers—if it still happens at all. It may be a professional project, an open source project, or even a private personal project. Saying that other developers will help with your project does not necessarily mean that they will write some code. They can also try to find solutions with you to the technical challenges you will be facing, and that applies to every type of project.

In any case, doing things properly will ease a crucial step we all go through when getting into a new project: the onboarding process.

Previous PageNext Page
You have been reading a chapter from
Clean Code in PHP
Published in: Oct 2022Publisher: PacktISBN-13: 9781804613870
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Carsten Windler

Carsten Windler is a Lead PHP engineer at Plan A.
Read more about Carsten Windler

author image
Alexandre Daubois

Alexandre Daubois is a Symfony Developer at SensioLabs, the company that created Symfony.
Read more about Alexandre Daubois