Posts

When to add comments

Most code bases have far too much comments, while only a few are really usefull.

PHP is already strictly typed

PHP is already strictly typed, in the same way that JavaScript is. Not through the language itself, but with the help of tooling. JavaScript achieves this through tools like Typescript. (I use typescript as an example, as that is what i normally use.) Typescript adds a lot of new syntax to tha language, which allows for type checking. The transpiler then simply won’t transpile if there are type errors( depending on your configuration).

The modern PHP developers toolbox

The tools a modern PHP developer needs to strive.

What Is Big O

Big O is used to notate the ‘time and space complexity’ of algorithms. It provides us with key insights into how fast an algorithm is, without getting bogged down with details.

Math Is Fun

$\sqrt{x} = \frac{x}{\sqrt{x}}$ Seeing the above equation may look completely logical, or not. When i saw it a few days ago, i thought it was wrong. When i understood that it was correct, i thought it was the most beautiful thing ever. I’m not 100% sure why this intrigued me so much, but it just looks great. There are a few ways of simplifying this. We could multiply both sides with $\sqrt{x}$, like so:

Semantic versioning

Chances are, if you are writing software, you have some dependencies on other peoples code. There is no reason to reinvent the wheel, so you use the code someone else wrote. One of your options is to copy paste it, but then you won’t get any updates if they release a new version.

This is where dependency managers come into play. With a set of instructions, they retrieve the needed dependencies for you, and allow you to lock into specific versions, and update when you want. Before we head into dependency managers, lets first talk about semantic versioning (semver).

Add an editorconfig to your project

One of the hardest things to spot during a pr are whitespace issues. Did someone use tabs instead of spaces, trailing whitespace etc. So, why not make it easy on yourself and help any contributors by adding an .editorconfig file that automatcially fixes those things for you.

What is a default object?

What is a clean solution to display a ‘default’ message to the user, when something they try to access isn’t there (anymore)? We could let the our repository throw an exception, catch it somewhere, and then let our controller handle it. Maybe we could return null, and pass that all the way up and add a fall back message for the content in the view somewhere? Why not try a better solution and work with a default object.

Noop polyfills

A while ago a reddit post showed up, where someone installed version 9.99.99 of paragonie/random_compat. Seeing a package update from 2.* to 9.99.99 may be a bit confusing, but given how autolaoding, polyfills and composer work in php, this is actually quite a clever way of dealing with things. Lets take a look at version constraints, autoloading and composer to see why.

Deploying to Github pages with Travis

If you want to write a blog, or have another kind of static website, you need to deploy it somewhere. So why not host it on Github pages? It’s free and has https by default.