Cookies

With your permission, we use Google Analytics cookies to measure visits and improve the site. Necessary cookies are always on. You can change your choice or withdraw consent anytime in the footer, under Cookie settings. Cookie Policy

Skip to content

Clean Code Rules for AI Code Generation

ReferencePro4 minupdated 2026-10-21

These rules guide code generation to produce maintainable, professional-quality code.

Meaningful Names

  • Use intention-revealing names that explain why something exists
  • Avoid disinformation and meaningless distinctions (e.g., data, info, manager)
  • Use pronounceable, searchable names
  • Class names: nouns (e.g., UserAccount, PaymentProcessor)
  • Method names: verbs (e.g., calculateTotal, sendEmail)
  • Avoid mental mapping and encodings (Hungarian notation, prefixes)

Functions

  • Keep functions small (< 20 lines ideal)
  • Do one thing only - Single Responsibility Principle
  • One level of abstraction per function
  • Limit arguments: 0-2 ideal, 3 maximum, avoid flag arguments
  • No side effects - function should do what its name says
  • Separate commands (change state) from queries (return info)
  • Prefer exceptions over error codes

This guide continues on the Pro plan

You have seen the introduction and the first example. With Pro you unlock this guide and every other one - updated every day, with ready-to-copy examples.

In this guide (Pro): Comments · Formatting · Objects and Data Structures · Error Handling · Classes · Unit Tests · Code Quality Principles · Code Smells to Avoid · Concurrency · System Design · Refactoring · Documentation

€7.99/month · No commitment · Cancel anytime

Components for this task

We hand-picked the agents, skills and commands that handle this kind of work: Agents and skills for code review.

Open-source community guide (MIT) · curated and maintained by Doutor AI.

Need a tailor-made solution?

Not sure where to start with AI in your business? Get a free assessment and a tailored plan - no commitment.

Save hours every week with AI, no hassle

Doutor AI gives you 1,859 ready-to-copy AI prompts, by industry and in plain English - plus a complete technical library for those who want to go further.

See plans