Coding tools that will enhance your coding quality

Sun 29 Apr 2018

These are some tips regarding coding quality. Take these with a grain of salt and always apply common sense to code by these rules. They are in no way an absolute form or must-do-it-my-way.

Ever since I met a colleague of mine, my learning curve in coding knowledge and standards skyrocketed. He was the nudge I needed to get into turbo modus and taught me very valuable skills. I'm going to distill some of the applications and standards that we use so others might benefit from these.

Coding Standards

PSR-2 is the bible to PHP developers. They are the groundwork of every team. As a team, you need to maintain standards so that projects become more readable and easier to handover. This standard will help you achieve this. In our team, we try to always think about situations where some snippets might be more readable. We often have discussions on this subject and end up agreeing on the most explicit and most readable version.

A great example would be parameters in a function.

public function unreadable(string $name, int $number, AwesomeInterface $object, AnotherAwesomeInterface $adapter, int $amount)
   // Magic

public function readable(
   string $name,
   int $number,
   AwesomeInterface $object, 
   AnotherAwesomeInterface $adapter, 
   int $amount
) {
   // Magic

We have more situations like this where we try to rational to keep following strict PSR-2 or to deviate and apply our own code style. A great tool to keep yourself in check with this standard would be phpcs.

Unit testing

PHPUnit is currently the go-to tool for unit testing in PHP. It is a job no-one wants to do but really the only way to maintain larger projects. Unit testing will show you when pieces of code have been broken even before it gets committed or even pushed through your deployment street.

CI/CD - Continues Integration and Deployment

There are many tools out there for this. My choice is Bitbucket Pipelines. I'm integrated with the Atlassian suite and I like it. There are many alternatives though. Gitlab-CI, Travis, CircleCI to name a few. There is no be all end all. Most git suites already provide these features. The question you should ask if that the features provided are enough for the projects you run.

A great thing that CI/CD does is that you no longer have to think about the deployment itself. You don't upload files anymore with Filezilla... yeah... I've been there. Login to the production server... yet what does that mean? I've seen it way too many often that human error during deployment of files results in projects being broken. CI/CD really fixed that problem altogether.

Also since you don't log in to the server anymore that often, also reduces the temptation to introduce hacks to fix the code.

Programming IDE - PHPStorm

An IDE will help you greatly. PHPStorm is smart. Really smart. It will tell you if there are unused bits of code, imports are wrong, bad practices are in code, functions unknown, parameters badly used and much more.

Point being is that using an IDE will greatly improve your coding quality. The nice thing about PHPStorm is that you can download plugins that, for instance, run PHPUnit or check your code for PSR-2 code style.

I use PHPStorm for my database, it also comes with a nice visualization window where you can view relations and visually interact. The terminal of course! The power of god under your code :) Version Control, it has a great git integration, simple to use diff tool and the rest you can do from the terminal. The file and structure browser to easily navigate through files and a TODO tracker.

Many features that I use on the daily. You don't have to use an IDE yet I've seen huge improvements since we've been using PHPStorm in our team (before something like Atom, Netbeans).

Versioning - Git

We all need versioning. I cannot imagine working without. In a team, it gives you insight in who changed what. You can do code reviews and help others improve their code before it goes into production.

I think that Git has been integrated into the programmer's life pretty well so I will leave it at that :)

Use colleagues to ask questions

Colleagues are always a great resource. Often it takes an extra pair of eyes/brains to crack that son of an error. Headbutting against a problem is not a great thing to do. A problem often gets solved within seconds when colleagues take a peak. Don't be shy to ask a colleague!

You can lose hours of good time and concentration when you try to solve everything by yourself.

Be a good colleague

Don't be harsh. Always apply rational thinking and try to counter-argument why something might not end up being great to do. Explain, think together and spar about the problem that is to be solved. There is no productivity in burning down your colleague's thoughts on the matter at hand.

A great programmer once said:

You were hired to write code. Many developers make the mistake and think that their job stops there. That’s not true. In fact, you have two jobs:

  • Write good code.
  • Be easy to work with.

~ Jacob Kaplan-Moss, Django programmer

That really concludes everything I recommend to improve your working environment. Most of these things can be applied on the spot.