more posts

Thoughts on AI-Assisted Development

20 August 2024azxyc

I've been using AI tools, specifically GitHub Copilot and ChatGPT to help with coding for a while now, and I have a few thoughts.

GitHub Copilot

I use Copilot as a fancy autocomplete engine. I'll start writing a line of code and Copilot will usually guess what I would have written anyway. I've experimented with describing a problem to Copilot in comments and letting it come up with a solution, but it often either gets it completely wrong or gives up and just spits out a placeholder comment if its a more complex problem. Using it as inline autocomplete works pretty well though, and overall improves my efficiency, although I do find myself pausing for a second or two to wait for Copilot's suggestion quite often.

It is also worth mentioning that I have free access to Copilot through GitHub Education. I probably wouldn't use it if I had to pay $10/month.

ChatGPT

I've also been using ChatGPT as a coding assistant since GPT-4 came out in March 2023. I rarely use it to write large amounts of code, but it has almost completely eliminated my need for StackOverflow for common issues. It tends to hallucinate quite a bit when dealing with more complex problems or newer framework features, so I prefer to handle these solo. As an example, I asked ChatGPT 4o to show me how to implement authentication in a Next.js app using "bean-auth". Here was its response:


To set up authentication in a Next.js project using the bean-auth package, follow these steps:

  1. Install the package:
    Run npm install bean-auth.

  2. Initialize Bean Auth in _app.js or _app.tsx:

    import { BeanAuthProvider } from 'bean-auth';
    
    function MyApp({ Component, pageProps }) {
      return (
        <BeanAuthProvider>
          <Component {...pageProps} />
        </BeanAuthProvider>
      );
    }
    
    export default MyApp;
    
  3. Create an auth hook in hooks/useAuth.js:

    import { useBeanAuth } from 'bean-auth';
    
    export const useAuth = () => {
      const { login, logout, user } = useBeanAuth();
      return { login, logout, user };
    };
    
  4. Use the hook in your components:

    import { useAuth } from '../hooks/useAuth';
    
    const LoginPage = () => {
      const { login, user } = useAuth();
    
      return (
        <div>
          {user ? (
            <p>Welcome, {user.name}</p>
          ) : (
            <button onClick={login}>Login</button>
          )}
        </div>
      );
    };
    
    export default LoginPage;
    
  5. Protect pages with a Higher-Order Component (HOC):

    import { withAuth } from 'bean-auth';
    
    const Dashboard = () => {
      return <div>Protected Dashboard</div>;
    };
    
    export default withAuth(Dashboard);
    

That’s it! Your Next.js app is now set up with bean-auth for authentication.


If it wasn't obvious, "bean-auth" does not exist. At least not yet.


"AI makes you a worse programmer"

As with most things, it depends. If all you're doing is telling ChatGPT your problem and pasting its code into your codebase, then yes. Your handwriting will get worse if you never handwrite, and your problem-solving will get worse if you never problem-solve.

LLMs are not programmers, just as a calculator isn’t a mathematician. They’re tools that, when used correctly, can improve your efficiency.

There are plenty of ways to use AI tools correctly, but as a general rule of thumb, if you find yourself using code that you don't understand, you're probably not doing yourself any favours.


Will AI replace programmers?

I don't think so. At least not LLM chatbots. In theory, a superintelligent, learning AI agent could replace a programmer, but then we'll have other problems.


TL;DR - AI tools are useful when used correctly, like every other tool. Keep coding and use your tools wisely.