惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

大猫的无限游戏
大猫的无限游戏
J
Java Code Geeks
小众软件
小众软件
D
Docker
腾讯CDC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
V
V2EX
博客园 - 叶小钗
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Stack Overflow Blog
Stack Overflow Blog
B
Blog RSS Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 【当耐特】
IT之家
IT之家
博客园 - 司徒正美
M
MIT News - Artificial intelligence
T
The Blog of Author Tim Ferriss
The GitHub Blog
The GitHub Blog
罗磊的独立博客
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Why AI Generates 500 Lines of Code in One File...? (Part ...
Cathy Lai · 2026-06-24 · via DEV Community

Cathy Lai

TL;DR

AI tends to generate the "path of least resistance" based on what dominates its training data and examples, not necessarily what is architecturally best for a long-lived codebase.
Knowing this, there are steps we can take as seasoned developers to improve the code in multiple passes (part 2).

"Amazing" AI Code?

So your non-technical friends have told you about creating a complete landing page in a few minutes! Everything works. They can modify, create, delete elements and AI executed each perfectly. And fast. They love the site, and will definitely create more pages/sites this way.

You have a look at the code, and it looks like

❌ Messy code:

export default function XmasMugLandingPage() {
  return (
    <main className="min-h-screen bg-red-50 text-gray-900 overflow-hidden">
      <div className="absolute top-0 left-0 w-full h-full bg-gradient-to-br from-red-200 via-white to-green-200 opacity-70"></div>

      <section className="relative z-10 px-6 py-10">
        <div className="max-w-7xl mx-auto">
          <div className="flex flex-col lg:flex-row items-center justify-between gap-10">
            <div className="w-full lg:w-1/2">
              <div className="inline-block bg-red-600 text-white px-4 py-2 rounded-full text-sm font-bold mb-6">
                LIMITED CHRISTMAS EDITION
              </div>

// ... (messy code all in one function with 
//.      utility classes repeated 20 times)

The definition of "good" AI is obviously different from your expectation! ...!?

Why Does AI Generate Code This Way?

When we ask AI:

Build me a landing page with hero, pricing, FAQ and contact form.

The AI has several competing goals:

  • Get the answer correct
  • Avoid missing dependencies
  • Avoid introducing bugs
  • Fit within context limits
  • Produce something that runs immediately

Not because this is good architecture, But because it maximizes the probability of a correct response.

AI Has No Long-Term Ownership

A senior engineer thinks:

Someone will maintain this for five years.

The AI's priority:

I need to successfully answer this prompt.

Those are completely different optimization functions.

This explains: giant components, duplicated utility strings, repeated business logic and copy-pasted sections.

Tailwind is easier for AI to generate

With CSS Module:

// in a CSS file
.card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
}

// in a HTML file
<div className={styles.card}>

In Tailwind

/// all in one file
<div className="flex items-center gap-4 p-6">

Obviously, AI will have less to worry about if it's all in one file.

Why AI likes shadcn

The AI can see the source code of:

  • components/ui/button.tsx
  • components/ui/card.tsx
  • components/ui/dialog.tsx ...

inside the project. No hidden implementation, and it can modify components directly.

With a library:

import { Button } from "@mui/material"

the AI cannot edit MUI's source code. It has to understand the MUI API - and that's harder.

Can We Improve On This?

With more and more apps written this way, it seems important that we developers learn to teach AI to tidy and refactor the code! Here are some outlines:

  1. Generate The Page
  2. Ask AI To Identify Repetition
  3. Extract Components
  4. Separate Content From Presentation
  5. Establish Boundaries

In the next article, I will expand on each step and provide a walk through.

Do you have a similar experience with AI generated code? Does some of the AI tendencies surprise you??