Howl

this is where i come to cry.

>

PHP has come back

March 18, 2017

PHP is generally considered a pretty bad language. It has a lot of flaws, most of them you can see on PHP sadness, a really great resource if you want to get depression from code. But it’s got some neat features: it’s easy to develop in even for absolute beginners (has a very low entry barrier), and it’s easy to deploy. Its ease of deployment can be seen from the fact that the 11-year-old me managed to create a WordPress blog, without any knowledge of computer programming if not a bit of HTML with <center> and <font>, by simply unzipping the wordpress source and uploading it to an FTP server. Allow 30 minutes for all the files to upload (hey, my connection was shit and I didn’t know how to unzip a file server-side), and follow the 5-minute installer of WordPress: boom, good to go. Its ease of development can be seen by the fact that 12-year-old me made his first commit on GitHub… with some bad PHP code. But it worked! I was doing number comparisons using strings, the indentation was possibly one of the worst things you’ve ever seen, but it worked. I didn’t even know what a function was: a friend sent me a pastebin with an implementation using a function, and I was “wow cool i don’t know what this is but it looks nicer” and added it.

Since then, I’ve proceeded to rewrite all the code for OsuLevelCalculator, but that project still is like my first words as a child. Now I’ve grown up by a few years, and I feel like PHP is coming back, but under two different names: React (JSX) and Serverless frameworks. That’s right.

Let’s start off with JSX, shall we? This is an example of JSX I’ve found from somewhere on the internet:

<div className="red">Children Text</div>;
<MyCounter count={3 + 5} />;

// Here, we set the "scores" attribute below to a JavaScript object.
var gameScores = {
  player1: 2, 
  player2: 5
};

<DashboardUnit data-index="2">
  <h1>Scores</h1>
  <Scoreboard className="results" scores={gameScores} />
</DashboardUnit>;

Hmm… Where have I already seen that?

<div class="red">Children Text</div>
<div class="counter"><?php echo 3 + 5; ?></div>

<?php
$scores = [
  "player1" => 2,
  "player2" => 5,
];
?>

<div class="dashboard-unit" data-index="2">
  <h1>Scores</h1>
  <div className="scoreboard results">
    <?php
      foreach ($gameScores as $score) {
        ?>
        <div class="score"><?php echo $score; ?></div>
        <?
      }
    ?>
  </div>
</div>

We’re embedding HTML straight into our code. If this doesn’t remind you of PHP, I don’t know what does. We have separated the view and the controller exactly to have a separation of concerns and not having to deal with unmaintainable code, yet this now is modern React code? Jesus.

Then, Serverless. Serverless is like some shit in a chocolate-bar shape wrapped in a chocolate wrapper. It looks nice, but just when you start using it you realise it’s not really good. The problem with serverless architecture is that the only real thing you can do with it without using anything else is just Software as a Service. But why would you let a third party do computations which you can easily do on your own? This basically means that to become useful, Serverless applications must connect to a database, which for Amazon Lambda implies that they should probably use one of Amazon’s databases, if you’re using Cloud Functions you should probably use one of Google’s databases, and so on. So they become pretty useless.

Anyway, getting away from my rant and back to the PHP topic, let’s nail down what Serverless compared to classic servers: it only uses the resources it needs (it “autoscales”), and it requires the software that is ran on top of it to be stateless. Rings a bell? Personally it reminds me much of how php-fpm scales the amount of workers used based on the number of requests and how every PHP script ran needs to always initialise the connection to the database, redis, load all the includes each time it is ran. Which makes for a slow response time.

Why is every hipster now hyped for React and serverless? They’re just the comeback of what we already ditched as being inefficient. Why are we using black boxes to deploy our code to the web? We should learn from the past to understand what didn’t work and move on, not make history repeat itself.

/rant

© Morgan Bazalgette 2015-2017