Blog posts

Welcome to my personal programming blog. As most of the topics are on programming, if that's not interesting to you, you might want to skip this one! If you are really keen, you can see an archive of all my blog posts.

So it turns out PHP rules the web?

PHP is often the butt of jokes online, but I've always thought that quite unfair. Turns out, that I am certainly not the only one, as outlined in this article 'The Internet of PHP' where I learn that PHP is powering 77.2% of the top 10 million website backends, with the next contender being ASP.NET at a measly 6.9%. A large amount of this is Wordpress (obviously), but either way, it's a huge amount of the web and to me the summary of this article captures why:

There are languages that are even faster (Rust), have an even larger community (Node.js), or have more mature compilers (Java); but that tends to trade other values.

PHP hits a certain Goldilocks sweetspot. It is pretty fast, has a large community for productivity, features modern syntax, is actively developed, easy to learn, easy to scale, and has a large standard library. It offers high and safe concurrency at scale, yet without async complexity or blocking a main thread. It also tends to carry low maintenance cost due to a stable platform, and through a community that values compatibility and low dependency count. You will have different needs at times, of course, but for this particular sweetspot, PHP stands among very few others.

There is another thing unmentioned here: Because of this large community, stability and ease of use, it also is well practiced by Chat-GPT and Github Codex. The training data is well-fed and familiar with popular frameworks like Laravel and even libraries such as Filament. I've found Chat-GPT's AI pair programming fluency to be of higher quality than that of Node and Python - perhaps because the language has undergone less changes over the recent years.

For me PHP is a good choice for static sites requiring a CMS, blogs and enterprise style software, (e.g. anything involving dashboards, tables etc). It's not always the best choice for these projects (h/t Python with Django), but it's a certainly worthy contender. That being said I was still slightly surprised at how insanely popular it is!

The way things are going...

I have now been using Chat-GPT, and Github's Copilot for coding for 3 months, and I just have to say, some days I am just breezing through tasks that would otherwise take me ages. For me, it's perfect as it excels at the tasks I actually struggle with, e.g. boring boilerplate, repetitive, data entry type things, leaving me to feel more mental space to think about the big picture as well as staying more organised.

The thing is in many cases I will have to tweak or alter some code - both the above tools are essentially super-charged autocomplete which essentially just speed up my typing ability. They still need me to direct how the code all fits together as well as read and correct mistakes.

Soon I may have a project using a low-code framework Oracle Apex, which recently I have spent some time watching a few tutorials and examples of projects built. I am pretty excited about this, as I can definitely see how quickly it could be used for certain types of project. Still it's not 'no-code' - having a decent knowledge of REST APIs, SQL, and CSS seems to be a must for anything but the most basic app.

Sometimes I still wonder (and slightly worry) as primarily a web developer, how much actual coding will I be doing on a daily basis say in 2-3 years time. The way things are going, it might be very little, and at some point there may be professional app builders who know very little code - but still I find it hard to believe that they would not be at a disadvantage in some way. Coding is such a rewarding activity, so it would be sad for that skill to become obsolete, but building stuff quickly and well is also great - I guess we will see!

Chat-GPT is not coming for my job just yet!

The dust has settled a bit after the wide release of Chat-GPT and my excitement has tempered somewhat. It is capable of some very cool stuff, but its main limitation is accuracy. There are a lot of mistakes, and it asserts itself so confidently you have to be very careful when using it. Despite this I have been using it daily, finding it especially useful for SQL and React and as a general search engine for programming language questions. It is very good with error messages for instance, and if doesn’t instantly give me the answer, often Chat-GPT will. It is also surprisingly good at converting data. I turned a hastily written design brief into a well formatted JSON structure, a task that would have otherwise been 15mins of cutting and pasting.

I think it's almost certain that at some stage AI will be able to build full applications, and work on them from natural language but how long that takes is anyone’s guess. In the present, I spend more time than in the past wiring up open-source libraries, and working in consoles rather than coding, and I mainly expect AI to just mean that my work becomes more like that. So in the meantime, whilst I don’t think it’s coming for my whole job just yet, I am keeping a very close eye on it! 😀

Check out the Perception Census...

Here is one cool project I have been working on recently. This is the perception census, a huge study of perceptual diversity undertaken by world-leading academics Anil Seth from the University of Sussex and Fiona Macpherson from the University of Glasgow.

Image of the perception census website

You get to go through a tour of perception and finding out how your brain works, whilst taking part in important research. It's been a joy to work on!

Using Chat-GPT to do my job

I am so excited! Today after reading articles about Chat GPT I decided to see if I could start using it to help me do my job. Here is my first bit of work:

How can I prevent a user from signing up with a particular email address, without retaining the email address itself?

If you want to prevent a user from signing up with a particular email address, but do not want to retain the email address itself, one possible solution is to create a hash of the email address and store the hash instead of the email address itself.

A hash is a mathematical function that converts a piece of data, such as an email address, into a fixed-length string of characters. Hashing is a one-way process, which means that it is not possible to reverse the process and recover the original data from the hash. This means that you can store the hash of an email address without retaining the email address itself.

To prevent a user from signing up with a particular email address, you could hash the email address and store the hash in a list of blocked email addresses. Whenever a new user signs up, you could hash the email address they provide and check if it appears in the list of blocked email addresses. If the hash matches a hash in the list, you could prevent the user from signing up.

This approach has the advantage of allowing you to prevent a user from signing up with a particular email address without retaining the email address itself. However, it is important to note that this approach is not foolproof, as it is possible for two different email addresses to produce the same hash. This is known as a collision, and it is a potential weakness of the hashing approach.

Write code in Laravel and PHP to do the above:

Here is an example of how you could implement the hashing approach in Laravel and PHP to prevent a user from signing up with a particular email address without retaining the email address itself:

// Get the email address provided by the user
$email = $request->input('email');

// Create a hash of the email address using the SHA-256 hashing algorithm
$hash = hash('sha256', $email);

// Check if the hash appears in the list of blocked email addresses
$blocked = DB::table('blocked_emails')->where('hash', $hash)->first();

if ($blocked) {
    // The email address has been blocked, so prevent the user from signing up
    return redirect('/signup')->with('error', 'This email address is not allowed.');
} else {
    // The email address is not blocked, so continue with the signup process
    // ...

Just stunning and scary! At the least, I think this is going to be a huge threat to stackoverflow :D - but I have already now asked it for code solutions to three problems and it has been helpful, and the fact it remembers and allows refinements is huge. I asked it to creat the database migration, and it also gave me that. The idea of it being hooked up to your whole software project, it will be just so powerful.