Skip to main content

Command Palette

Search for a command to run...

50 Principles of High-Quality Code

Updated
5 min readView as Markdown
B
Senior Software Architect with 30+ years of experience building enterprise systems using Java, Spring Boot, and cloud-native technologies.

Writing code that works is easy. Writing code that still works beautifully five years later is engineering.

Every developer can make software that passes today's tests.

Far fewer can build software that is easy to understand, safe to change, scalable under growth, and enjoyable for other engineers to maintain.

After more than three decades of software engineering, I've realised that high-quality code isn't about clever syntax or the latest framework.

It's about following timeless principles.

Here are 50 principles that consistently lead to clean, maintainable, production-ready software.


1. Code Is Written for Humans First

Computers execute code.

Humans maintain it.

Optimize for readability.


2. Make the Simple Thing Easy

Complexity should be earned—not introduced by default.


3. Every Function Should Have One Responsibility

If a function needs "and" in its description, it's probably doing too much.


4. Prefer Clarity Over Cleverness

The smartest code is usually the easiest to understand.


5. Name Things Well

Good names eliminate comments.

Bad names create confusion.


6. Keep Functions Small

Small functions are easier to read, test, and reuse.


7. Reduce Nesting

Deep indentation hides logic.

Return early.

Flatten code.


8. Avoid Duplicate Logic

Don't Repeat Yourself (DRY).

Duplicate knowledge becomes inconsistent knowledge.


9. Comments Explain Why, Not What

Code should explain what it does.

Comments should explain why it exists.


10. Design for Change

Requirements always change.

Code should adapt without breaking everything else.


11. Hide Implementation Details

Expose behaviour.

Hide complexity.


12. Depend on Abstractions

Concrete implementations change.

Interfaces last longer.


13. Minimise Coupling

The fewer dependencies, the easier the maintenance.


14. Maximise Cohesion

Things that change together should stay together.


15. Fail Fast

Detect problems early.

Never hide failures.


16. Handle Errors Explicitly

Unexpected failures deserve deliberate handling.


17. Validate Inputs

Never trust external data.


18. Write Defensive Code

Assume incorrect input will eventually happen.


19. Keep Business Logic Independent

Frameworks should support your domain—not own it.


20. Prefer Composition Over Inheritance

Flexible systems grow through composition.


21. Immutable Data Reduces Bugs

Changing shared state causes surprises.


22. Limit Shared Mutable State

Concurrency becomes dramatically simpler.


23. Make Side Effects Obvious

Hidden behaviour creates hidden bugs.


24. Separate Commands from Queries

Functions should either change state or return data.

Avoid both.


25. One Source of Truth

Avoid conflicting representations of the same information.


26. Write Code That Is Easy to Delete

Temporary code often becomes permanent.


27. Refactor Continuously

Small improvements prevent massive rewrites.


28. Technical Debt Is Like Interest

Ignore it long enough and it compounds.


29. Keep Modules Independent

Changing one module shouldn't break ten others.


30. Optimise After Measuring

Never optimise assumptions.

Measure first.


31. Readability Beats Brevity

A few extra lines often improve understanding.


32. Consistency Beats Personal Style

Teams outperform individuals.

Consistency wins.


33. Test Behaviour, Not Implementation

Tests should survive refactoring.


34. Automate Everything Repetitive

Humans forget.

Automation doesn't.


35. Small Pull Requests Win

Smaller reviews produce better feedback.


36. Make Code Reviews Educational

Reviews should improve engineers—not just code.


37. Document Decisions

Future developers won't remember today's discussions.


38. Remove Dead Code

Unused code becomes future confusion.


39. Prefer Explicitness

Magic saves keystrokes but costs understanding.


40. Keep Dependencies Under Control

Every dependency introduces future maintenance.


41. Design for Observability

Logs.

Metrics.

Tracing.

Production should never be a mystery.


42. Secure by Default

Security isn't a feature.

It's a requirement.


43. Think About Failure Before Success

Distributed systems fail.

Plan accordingly.


44. Keep Architecture Boring

Novelty should solve problems—not create them.


45. Make the Right Thing Easy

Good APIs naturally encourage good practices.


46. Code Should Tell a Story

Reading code should feel like reading well-written prose.


47. Leave the Code Better Than You Found It

Small improvements accumulate into exceptional systems.


48. Quality Is Everyone's Responsibility

There is no "quality team."

Every commit contributes.


49. Great Engineers Reduce Complexity

Adding code is easy.

Removing unnecessary code is mastery.


50. Never Stop Learning

Languages change.

Frameworks evolve.

Principles endure.

Keep improving.


Final Thoughts

Technology evolves at an incredible pace.

Languages come and go.

Frameworks rise and fall.

Architectures change.

But the principles behind high-quality software remain remarkably consistent.

The best engineers aren't remembered because they wrote the most code.

They're remembered because they wrote code that thousands of others could confidently build upon.

Clean code isn't an aesthetic preference.

It's a competitive advantage.

What principle would you add to this list?

I'd love to hear your thoughts in the comments.

More from this blog

B

Bill LIao's Blog

137 posts

A technical blog on modern backend development, software architecture, and practical AI agent workflows