TL;DR: We’re coding for the web all wrong. And it’s mostly because of the languages we’re using. We’re piling hack upon hack upon hack. Good coding principles and practices are becoming more common in web development, but I can’t help wishing we could take a few steps back and start with tools that help us write better code in the first place.
WARNING: contains opinions. Some of which may be uninformed.
Anyone involved in software that knows me well will know a couple of things about me:
- I have a different approach to web development than a lot of people – mostly because I have a background in safety critical software, which is written very differently to code for a website.
- Despite that background, I’m pretty pragmatic. Horses are for courses. Tools are just tools.
And I’m always looking to write better PHP. Which is why I’m currently reading Adam Wathan’s Refactoring to Collections. A book which tries to apply some declarative programming principles to PHP coding. This, in short, means he’s come up with some nice ways to write code that says what you more want to get done, and less HOW to get it done.
And it’s great and it’s already transforming the way that I think.
But…and maybe this is addressed in later chapters that I’ve not read yet…I can’t read stuff like this without thinking about simplicity and performance. Here’s me wanting to do some simple transformations on some arrays, and I need to:
- use composer to pull down the package that contains the Collection class;
- load an autoloader that loads the dependencies;
- probably, in doing so, include a load of code that I’m never going to run.
And thats before we even write a line of code. Once we have some code written using collections, method chaining, etc, then because I’m using other people’s implementations of higher-order functions, I’m totally removed from how efficient and scalable that code is.
This is a more general problem with declarative programming. It’s really nice and easy to read, but you don’t have the implementation detail. So how are you to know if using these collections going to make code that scales?
I find myself thinking “Why aren’t collections part of the standard library of PHP?”
That’s because, PHP isn’t a declarative language, it’s an imperative language. Adding collections to it is a fudge that makes it something that it isn’t.
So if you really want to do declarative programming nicely, you have two options: use a different language (options limited), or pile layer upon layer of abstraction on top of an existing language to make it something that it isn’t (options many and varied!).
This is just a pedantic, ex-SPARK95-coder’s rant, wishing that we could choose base-level tools and languages that help us write better code in the first place, inspired by JJJ and the guy who (allegedly) couldn’t deploy an app because Angular had 40,000 files in it.
It can be better. Software really, doesn’t have to be terrible.