Organic vs Artificial
Introduction
Don’t worry, I won’t bore you by talking about the likes of food & how things are grown, processed, etc. Rather, I’d like to revisit the topic of artificial intelligence, and review its weak points at this moment in time.
If you’ve read my previous articles, you’ll know that I’m not one of those to go with the hype around artificial intelligence. Yes, it is really cool & you can certainly do some really cool things with it. But it’s certainly not as powerful as some people would have you believe.
Experiment
One of the things that I’ve recently worked on in my own time was just a really silly thought experiment. I was just thinking about how one might take a mathematical formula as a string, parse it & then process it to produce the result of the given formula. You can see the messy source code here, if you’re wondering why native JavaScript & no use of TypeScript or anything like that. The short & honest answer, I was being lazy & I wrote all of that within the Chrome developer tools console to simply run it in real time as I’m making changes.
Now I personally don’t consider that anything special, it was fun, I’ll be honest, I really did find that little experiment surprisingly fun. Something different to the typical web application or CRUD API, etc. It was simply something different & something that I’m very unlikely to ever need to build in the real world.
So I thought, it didn’t take me that long to build that, I did it for fun when I had a bit of time to spare. Which as a hands on dad with an infant in the house, that doesn’t leave me with a great deal of time to spare at all.
So I decided, why not try to get some AI tools to see if they could implement this for me, I thought I’d be as fair as possible & simply ask that it implemented some function to take some mathematical expression, parse it, apply some basic principles such as BODMAS & then process it, etc. Basically the kinda thing that I might as another developer, only with more prompts & support in the event of failure, etc.
Results
While I’ve got to give todays AI a pat on the back for giving it a go, it continued to fail to produce code that was 100% correct. Without any delay, here is the code that was produced:
Now if you run that code, you can see that the answer is fundamentally wrong, which is a shame. In the event that a developer such as myself wants to be super lazy & rely on AI to produce some code that takes into consideration context that exists outside of the domain of technology, etc. Be that some legislation, industry policy or law, it simply doesn’t matter, AI still seems to have a really hard time with the wider context.
In my humble opinion, using AI to generate code today is just dangerous, granted, you can use it for some pretty trivial stuff, maybe allow it to do some auto-complete stuff that would otherwise just be tedious. I personally won’t rely on AI until I’ve seen it simply do a much better job than myself.
The Human Factor
Let’s face it, developers won’t be disappearing anytime too soon, therefore another factor to consider with relying on AI to write code is the quality of the code it produces. It’s believed in the industry that you should write code that’s quite expressive, it might expose a limited number of features & functions whereby the complexity is encapsulated elsewhere. In simple terms this means that the consumer of your code, whether you’re writing a library to make open source or whether you’re simply adding another layer to your architecture, etc, you want to expose as little complexity as possible.
This is another subject matter that I find hasn’t been addressed with code that’s written by AI, I for one don’t find that the code is expressive. Now a lot of the code I write in a hurry, yes, that’s usually not overly expressive, but it’s simple enough to understand what’s going on. But I’ve also tried to get AI to produce some very expressive code for me.
I really like concepts such as railway coding, because you can see at a glance what is happening, granted, there’s more layers of encapsulation, but the code simply reads almost like a book. This is where I love to talk about subject matters such as writing declarative code, domain specific languages, fluent interfaces & so on.
I appreciate I might be getting a little opinionated on the whole readability of ones code subject matter here, but that’s my personal preference. I want to be able to glance at some code & see what it’s trying to do. If I want to know how it’s achieving its goal, then I will look at the implementation. But if I’m simply looking at something from a controller, I wouldn’t want to have to write a large amount of boilerplate code to handle all the potential edge cases from a given function.
Comments
I am a firm believer that you should aim to write your code in such a way where code comments aren’t necessary, but sadly, sometimes they’re just needed because the problem at hand can just be extremely complex. Be that some really fancy mathematical stuff that goes way beyond my understanding of mathematics, or something similar. Sometimes you can’t write code in such a way where it’s hard to read on its own. In such scenario, comments are a god send.
Yes, you can do your best to avoid complexity whenever possible & sometimes, entire applications have no need for such complexity. But with the likes of 3D applications, dealing with the likes of plotting spherical coordinates against a 3D object, it’s not super complex. I’ve done it myself, but it’s just the kinda thing where the maths might initially look a little intimidating, especially if you’re not used to it.
But if you were to say look at some code that’s responsible to interpreting wireless signals & whatnot, where some really clever people worked out how to implement the likes of binary shift phase keying, or the likes of 16 quadrature amplitude modulation. That’s an example of something someone has done that’s really clever that requires an understanding of the world beyond code. Asking AI to implement something like that, I really question how good of a job it could do.
Conclusion
I don’t think my conclusion has changed much since I last looked at the power of AI & its ability to write & produce code. In some respects, due to all of the hype, I have wondered if I’m doing something wrong or if I’m simply being too harsh or overly opinionated, etc. But I promise, I am trying to keep it fair, I’m trying to prompt these tools when I spot an error & make suggestions.
I am trying to be as fair as one can be, I’m treating it like a very inexperienced developer that’s just learned the basics. I’ve done this exercise in the past with a couple of friends, hence the creation of some really basic repos that I’ve made in the past. Such repositories are there to simply act as a guide at best, give total beginners an idea of how they can implement things. An example of such repositories might be one this one I named Node Starter.
There’s many, many other factors to consider when using AI, such as how eco friendly it might be. Is the code that’s being produced ethically fair & responsible? There have been stories in the past where there’s some study around AI being racist, sexist, etc. For example, the Guardian wrote an online article about “the rise of the racist robots”. I’ve not personally looked into the legitimacy of it all, but if you do your own homework, you’ll find that there’s no short supply of such articles out there.
So in summary, while I really want AI to do an awesome job at making my life easier as a developer. I still feel it’s a tool that can’t be trusted just yet, I’m all for experimentation, I’m all for seeing AI slowly replace humans, imagine having a fool proof system that removes human error completely? That would be amazing! – I do want AI to succeed in this area, I’m just yet to see it make any major advances beyond what you might expect from some really good intellisense & auto complete.
