HN
Today

Write code like a human will maintain it

The author explores a subtle, yet critical, pitfall of using Large Language Models for coding: their tendency to replicate and amplify existing code patterns, leading to maintainability debt. This resonated with Hacker News, sparking a candid discussion among developers grappling with how to harness AI's power without sacrificing code quality or devolving into 'vibe coding'. The core message? Treat your codebase as the training data for your AI assistant, because what you feed it, it will reflect back.

144
Score
109
Comments
#1
Highest Rank
3h
on Front Page
First Seen
Jul 10, 2:00 PM
Last Seen
Jul 10, 4:00 PM
Rank Over Time
314

The Lowdown

The author, Scott Robinson, shares a personal revelation about the double-edged sword of using LLMs for code generation. While these tools rapidly produce functional code, he noticed a creeping laziness in his own development process: rather than refactoring common logic into shared helpers, he'd let the LLM generate duplicated access checks across various parts of his application.

  • LLMs are adept at generating functional code, often leading to a temptation to overlook best practices like DRY (Don't Repeat Yourself).
  • Robinson found himself accepting multiple instances of identical conditional logic generated by the AI.
  • The initial allure was outsourcing maintenance to the LLM, assuming it would handle future changes.
  • However, LLMs learn from the existing codebase. Each shortcut or duplicated pattern becomes a signal to the AI about the project's 'style'.
  • Consequently, the LLM perpetuates and even compounds these bad patterns, making future refactoring or global changes increasingly difficult without significant manual intervention.
  • This realization led Robinson to understand that he wasn't outsourcing maintenance but actively training the LLM to develop ever-worsening coding habits.

The article serves as a cautionary tale, urging developers to remember that LLMs are powerful tools that reflect the quality of the environment they operate within. Therefore, maintaining high code standards is more crucial than ever, as these standards directly influence the AI's future output.

The Gossip

Prompting for Perfection

Many commenters shared strategies for guiding LLMs toward higher quality code, emphasizing that effective prompting can mitigate the issues raised in the article. This often involves creating detailed `.md` files (like `AGENTS.md` or `CLAUDE.md`) with explicit rules for code quality, architectural patterns, and even specific review checklists. Users reported success in getting LLMs to identify redundancy, improve test quality, and adhere to best practices by essentially 'training' the AI with their coding standards. Some even employ multi-stage review processes with different AI 'agents' to ensure comprehensive code quality.

The Evolution of Engineering

The discussion branched into a philosophical debate about the changing nature of software development in the age of AI. Some argued that traditional code readability and maintainability, geared towards human understanding, might become less critical if AI is the primary 'maintainer.' They suggest optimizing for AI consumption and accepting a new form of 'coding lock-in.' Others pushed back, asserting that code structure, clarity, and human-understandability remain paramount for cost-effectiveness, performance, and long-term viability, even if AI assists in writing it. There's a clear divide between those who embrace 'AI go brrrrr' for speed and those who fear a loss of control and increased technical debt.

Context and Comment Quandaries

A significant thread explored how LLMs interpret and perpetuate codebase 'context,' particularly concerning comments. Commenters noted that LLMs often generate verbose, redundant, or even context-breaking comments, akin to the 'homicidal maniac' quote about maintaining code. This highlights the challenge of making LLMs understand the 'why' behind code rather than just the 'what.' There's concern that AI-generated bloat and poor comments can further degrade code quality and human comprehension, requiring developers to carefully curate AI's output and explicitly instruct it on comment philosophy.