DEV Community

Cover image for AI Helped Me Write Less Code But Only After I Knew What to Ask
Alistair Rowan Whitcombe
Alistair Rowan Whitcombe

Posted on

AI Helped Me Write Less Code But Only After I Knew What to Ask

One of the most common promises of AI in coding is this:

AI will write code faster.

That’s only half true.

In my experience, AI doesn’t automatically produce better or smaller code. It often produces more code unless you already understand the problem well enough to guide it.

Here’s a real example that changed how I use AI in development.

The task

We want to filter active users and format their names from an array.

Simple requirement:

  • Take a list of users
  • Keep only active ones
  • Return their names in uppercase

Here’s a real example that changed how I use AI in development.

Version 1: Verbose code (AI’s first attempt)

This is the kind of code AI often generates when you ask vaguely.

function getActiveUserNames(users) {
  const activeUsers = [];

  for (let i = 0; i < users.length; i++) {
    if (users[i].isActive === true) {
      const upperName = users[i].name.toUpperCase();
      activeUsers.push(upperName);
    }
  }

  return activeUsers;
}

Enter fullscreen mode Exit fullscreen mode

What’s wrong with this?

Nothing functionally.

But:

  • Too much boilerplate
  • Manual looping
  • Harder to scan
  • Easier to introduce bugs later

This code works, but it’s not expressive.

Version 2: Smaller, clearer, faster to understand

Once I told AI what I actually cared about clarity and intent the result changed.

const getActiveUserNames = users =>
  users
    .filter(user => user.isActive)
    .map(user => user.name.toUpperCase());

Enter fullscreen mode Exit fullscreen mode

Why this is better

  • Expresses intent clearly
  • Easier to read
  • Fewer moving parts
  • Easier to test and maintain

Performance differences here are negligible, but developer speed and correctness improve.

AI didn’t optimize this guidance did

Important point:
AI did not magically produce the better version.

It happened only after I:

  • Understood the problem myself
  • Knew there was a simpler approach
  • Asked for a more functional style solution

AI amplifies understanding.
It doesn’t replace it.

Another example: conditional logic cleanup

Verbose version

function getDiscount(price, isMember) {
  if (isMember === true) {
    if (price > 100) {
      return price * 0.8;
    } else {
      return price * 0.9;
    }
  } else {
    return price;
  }
}

Enter fullscreen mode Exit fullscreen mode

Cleaner version

const getDiscount = (price, isMember) => {
  if (!isMember) return price;
  return price > 100 ? price * 0.8 : price * 0.9;
};

Enter fullscreen mode Exit fullscreen mode

AI will often default to the first style unless you explicitly ask for:

  • Refactoring
  • Readability
  • Idiomatic code

Why smaller code usually wins in real projects

In real-world systems, shorter code isn’t about cleverness.

It’s about:

  • Fewer bugs
  • Easier reviews
  • Faster onboarding
  • Clearer intent

This matters even more in production environments including real ecommerce projects like Shopperdot, where clarity beats clever tricks every time.

Readable code survives longer than “smart” code.

Where developers go wrong with AI

Many developers:

  • Accept the first output
  • Assume “more code = more correct”
  • Skip refactoring

That’s how AI-generated code becomes technical debt.

AI’s first answer is often a draft, not a solution.

A better way to use AI for code quality

Here’s what actually works for me:

  • Solve the problem mentally first
  • Ask AI for an initial implementation
  • Ask again: “Can this be simpler?”
  • Refactor manually
  • Verify with tests Used this way, AI becomes a code reduction tool, not a code generator.

Real-world takeaway

AI is great at:

  • Writing working code quickly
  • Generating alternatives
  • Refactoring when guided

AI is bad at:

  • Knowing what “clean” means in your codebase
  • Choosing style over verbosity
  • Understanding long-term maintenance

On production systems including those behind platforms like Shopperdot every extra line of code is something you’ll have to understand again later.

AI can help you write code faster.
But only you can decide when less code is better.

Top comments (0)