AI and Programming: The good and the bad


AI is what's all about nowadays, and with good reason! There's a lot of great uses for AI in most people's day to day computing. Today I'll elaborate on AI when it comes to programming. I'll talk about the good things, the bad things, and things in between.

Before I go further, I want to make a clear distinction between AI for developers vs. AI for consumers. For example, as a business owner, you can benefit from using AI. For example, a chat bot on your website which uses your business' knowledge to answer questions from users has no downside. On the other hand, as a developer, AI can help you build faster, but it can also hurt you and your product in the long term if you are not careful.

So this post is not about including AI features in a software product, which is great, but about using existing code completion AI tools such as GitHub Copilot or Google Gemini in your regular software projects.

The Advantages of using AI

As a developer, using AI in one way or another can be quite helpful you in your day-to-day. Below are some of the most relevant ways that AI could help.

Speed

One of the biggest benefits of using AI for daily coding is simply speed. Both writing simple boilerplate code and solving particularly complex problems can be sped up, as long as the AI understands your problem. How much faster can vary from a little to considerable, depending on your level of expertise as a developer and the code you are working with.

Senior devs with experience in a project might already know the code that needs to be written. They know the classes, methods, and functions that need to happen to be able to implement a feature. In this case, the AI can be a useful 'autocomplete', but the improvement is not that impressive.

On the other hand, junior devs or developers new to a project could benefit from the suggestions, as they don't yet know what needs to happen, or how to do it in a way that's coherent with the rest of the codebase. In this case, the speed up is more considerable, although it does not come for free. It makes the developer dependent on AI, and it's easy to avoid learning the ins and outs of the project, framework, language, and particular tech stack.

Explaining things

I think this is one of the best uses for AI. When you don't know a concept or don't quite fully understand something, it's great to have an AI explain it to you. You can then ask follow up questions to help you fully understand. AI can even give you examples, so it's great at this particular use.

One downside though is that it's not perfect. AI can – often very confidently – give you outdated or just plain wrong information. For things that are very popular and don't change much, such as algorithms or language features, it's great. For answering questions about particular libraries or frameworks, it can work, but it can also give you outdated or obsolete information, or get confused.

Skimming though documentation

Another good use of AI is to skim through the documentation for a particular library or framework. You can ask specific questions, so you don't have to go through the docs. For example, you could ask things such as: Does Axios support streaming binary responses? or Does Express.js support sessions by default or do I need a library?

Writing concrete code

If you need a particular function, such as debounce, then maybe you don't need a library. You can ask the AI to implement it for you. This is not without its risks but most of the time it works. :)

For example, a common use case I see is that you have a date in a particular format, such as 28/02/2020, and you want to create a JavaScript Date object from it. AI is very good at these concrete problems. Here is the code Gemini came up with:

function parseDateString(dateString) {
  // Expected format: DD/MM/YYYY (e.g., 28/02/2020)

  const parts = dateString.split('/');
  if (parts.length !== 3) {
    console.error('Invalid date string format. Expected DD/MM/YYYY:', dateString);
    return null;
  }

  const day = parseInt(parts[0], 10);
  const month = parseInt(parts[1], 10); // Month is 0-indexed in Date constructor (0 for Jan, 11 for Dec)
  const year = parseInt(parts[2], 10);

  // Validate the parsed components to avoid creating invalid dates
  if (isNaN(day) || isNaN(month) || isNaN(year) ||
      day < 1 || day > 31 ||
      month < 1 || month > 12 ||
      year < 1000 || year > 3000) { // Basic year range check
    console.error('Invalid date components:', dateString);
    return null;
  }

  // Create the Date object. Note: month - 1 because Date constructor expects 0-indexed month.
  const dateObject = new Date(year, month - 1, day);

  // Final check to ensure the date is valid (e.g., 30th Feb would be invalid)
  if (isNaN(dateObject.getTime()) ||
      dateObject.getDate() !== day ||
      dateObject.getMonth() !== (month - 1) ||
      dateObject.getFullYear() !== year) {
    console.error('Date object created is invalid or doesn't match input:', dateString);
    return null;
  }

  return dateObject;
}

Testing

I'm sure there are more elegant tools when it comes to AI and testing but even just using Copilot or a chat prompt, you can make the AI generate unit tests for your code, which can help you speed up the testing process.

Note that this does violate the Test Driven Development (TDD) principle, where you have to first write a test, then write just enough code to pass that test, then write some more tests, refine the code so those new tests pass, and so on. That being said, TDD is not the only way to write software, so that's okay.

Navigating New Codebases

AI is very good at navigating codebases. When you have to make a change in a project you have never worked before, particularly if it's a one-time thing, the AI can make the whole experience so much faster.

You can use an AI from your terminal with something like Gemini CLI and tell it things like 'I want to add a new ENV variable where do I have to make a change' or 'Explain the architecture of this app broadly' or 'What's the best way to add a this new feature in this codebase?'.

The concerns of using AI

As a developer, there are a few things in particular when using AI that can hurt you more than help you. So it's very important to pay special attention to them.

AI prevents you from using your brain

I've been programming for quite a while now, and my brain is quite used to solving programming problems. When trying Copilot for the first time, I found the following happening:

1) I start typing something, while thinking about the implementation. For example, I might need to create a function to insert a Person record into a database:

const insertPerson = (person: Person) => {
  // cursor here
}

2) While I let the cursor rest there, I'm already thinking things such as:

  • What fields does the Person type have?
  • What kind of interface am I using to interact with the database? Is it an ORM? An API?
  • Do I need to do some validations before inserting?
  • Do I need to raise some kind of exception?
  • What should I return?

3) Copilot suggests some code, which completely breaks my thinking process of step 2 and forces me to read what it suggests, which might or might not be completely irrelevant.

As such, I found it highly disruptive. My brain was already churning on a problem, and AI stopped me from doing that.

It could just be the way I use it. I could trigger the suggestions on-demand, and that would fix that problem, but the problem itself is deeper than just the UX. It's that for new developers, it makes you get used to never using your brain!

An example about Chess

Chess is a great game, but it does have one problem: Chess Engines. Computers have become so good at chess that humans can't beat them anymore. New chess players start using engines to analyze their games without really knowing why they suggest a particular move, and in doing so, they never learn how to analyze their own games using their actual brains.

If you don't analyze your games using your own brain, your brain will actually never learn! That's why beginners are told not to use chess engines when starting out, as they do more harm than good.

Another analogy could be learning math. When you are learning arithmetic, it doesn't help you to use a calculator. You have to actually do the process yourself, so you can learn! Once you know the process, you can use the calculator.

AI hurts new developers

My wife is learning to program, and she has several fellow students who rely heavily on AI to do their homework. The problem they have is always the same: They admit they are useless without an AI, but they still use it! They tell themselves they read and understand the solution after, but then they can't reproduce it without the help of the AI.

Tell me and I forget,
Teach me and I remember,
Involve me and I learn.

The sad reality about programming, and most skills in life, is that unless you go through the long and painful process of struggling to find a solution, you won't actually learn anything. If you use an AI you can merely remember a solution, but you wont really understand how it works.

My advice for new developers is simple: Don't use AI for coding. Sure, you can use it to explain things, or get some guidance, but the less you use it, the better.

It's good to struggle with an algorithm, it's good to take your time and read the documentation of a particular library. You'll learn by solving the same kind of problems over and over again. By then it won't matter if you don't remember, because you actually understand.

AI hurts experienced developers

Not only beginners, but experienced devs also struggle with AI. I've read several blog posts about devs who, after using tools like Copilot for a while, found that their brain was not 'turning on' automatically when solving a problem. Instead, they just stare blankly at the screen waiting for a suggestion, and go from there.

A lot of things they knew, such as method names, syntax, algorithms, slowly faded away. This reminds me of back before cellphones were a thing. People used to actually memorize other people's phone numbers!

Sure, there were address books, but you'd know the number of your mother, your sister, your best friend, all by memory. And nobody found it hard, it was just the way it was. Well, I'm not saying modern phones are a bad thing, but abusing AI can certainly make you lazy.

AI can give false positives

AI can very confidently give you bad results. It's very common that I ask a question and it answers something, only for me to reply back: 'But this doesn't work in the new version' or 'This is a bad approach because X', and then AI will be like 'Oh yeah you are right, here's a new solution'.

This is not a big deal for experienced developers, but new developers don't know what's right and wrong, and AI will just confuse them even more. It will also cause them to waste time troubleshooting, even with more AI help.

AI code can be insecure

AI can very confidently give you code that's completely insecure, from XSS and SQL injections to leaking private keys and everything in between. If the person using the code doesn't have enough experience to realize the given code has security flaws, then using AI can do more harm than good.

FOMO (Fear of Missing Out)

There's a lot of hype around AI, and many developers feel like if they don't use it, they will be left behind. This is just silly. You could certainly write code faster with AI, but then you have to actually maintain and understand that code.

AI is not a replacement. You still need to use your actual brain. Code still needs to be coherent, so it can scale properly as it grows in size and complexity.

This has been known in software since forever, and it's called technical debt:

Image courtesy of Accesto

AI can help you deliver faster, but without the standards of clean code, refactoring, design patterns, software architecture and all those same ol' things we've always been doing, all you are building is technical debt. Eventually, adding a new feature will be so slow that making a new app will be faster.

AI is not replacing anything. I think Copilot is a good term. It's not a pilot, or autopilot, it's a copilot. It's there to help, not to take control.

Conclusion

With great power comes great responsibility. AI is very easy to abuse, and can make you pick up bad habits. At the same time, it can make your life easier, and help you grow as a developer.

The key is how you use it. If you are learning or a new developer, I recommend not using it to generate code directly, but mostly to explain concepts, search through documentation, or if you are stuck, suggest a solution.

If you are an experienced developer, you can use it to generate code, but try to think of a solution before asking the AI because if you do it too often, your brain will become lazy and you will struggle to go back to the way it was before. While it might be cumbersome what I found works for me is disabling Copilot by default, then enable it with a hotkey so I can use it when I actually want to use it.

But of course, that's just like, my opinion man. Some people prefer to stop using it altogether, others such as myself, use it in more discreet use cases. I'm sure there are very capable senior developers who just don't care and will always use it. As usual, there's no one-size-fits-all solution.

What do you think? Should you never use it? Use it sometimes? All the time?

Want updates on our latest blog posts?
Subscribe to our newsletter!

Previous Post
Future Devs Are Here - at Apple Developer Academy
Next Post
Benefits of InspectorPro 9 🔨 Part 2