Files
snippet-pastebin/docs/CODE_STYLE.md
johndoe6345789 dd33d9823d Add comprehensive E2E tests for functionality, mobile responsiveness, and visual regression
- Implemented functionality tests covering page navigation, header behavior, form handling, and error management.
- Created mobile-responsive tests to ensure touch interactions, viewport adaptability, and safe area respect.
- Developed visual regression tests for home page layout, typography, color consistency, and interactive elements.
- Added a test runner script for easier execution of E2E tests with various options.
2026-01-20 01:29:32 +00:00

154 lines
3.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Heres a practical, engineering-grade set of coding principles that actually keep a codebase healthy over years—not just during the honeymoon phase. Think of this as preventative maintenance, not moral philosophy 🛠️🧠.
1. Smallness Is a Feature
Large things rot faster.
• Small files
• Small functions
• Small modules
• Small responsibilities
If a file feels “important,” its probably doing too much. Decomposition beats cleverness every time.
Size is friction. Friction accumulates.
2. One Reason to Change
This is the only part of SOLID that really matters in practice.
• Every file should exist for one reason
• If a change request makes you touch unrelated logic, the boundary is wrong
Violations show up as:
• “While Im here…” edits
• Fear-driven refactors
• Accidental breakage
3. Make State Explicit (and Rare)
Hidden state is technical debt wearing camouflage.
• Prefer pure functions
• Push IO to the edges
• Name state transitions clearly
• Avoid “ambient” globals, singletons, magic context
If you cant explain when state changes, it will betray you at scale 🧨.
4. Clarity Beats Brevity
Concise code is nice. Readable code survives.
• Prefer obvious over clever
• Use boring names that describe intent
• Avoid dense expressions that require mental simulation
The best compliment for code:
“I didnt have to think.”
5. Structure > Comments
Comments decay. Structure persists.
• Encode intent in function names and types
• Let data shape explain behavior
• Use comments only for why, never what
If you need a paragraph to explain a function, split the function.
6. Types Are a Design Tool
Even in dynamic languages.
• Types clarify contracts
• They force edge cases into daylight
• They prevent “just trust me” APIs
A good type definition is executable documentation 📐.
7. Tests Define Reality
Untested code is hypothetical.
• Tests lock in behavior
• Refactors without tests are rewrites in disguise
• Focus on behavior, not implementation
Healthy ratio:
• Few unit tests per function
• Strong integration tests per feature
8. Errors Are First-Class
Failure paths deserve the same respect as success paths.
• Handle errors explicitly
• Avoid silent fallbacks
• Fail fast, fail loud, fail usefully
Most production bugs live in “this cant happen” branches.
9. Consistency Is More Valuable Than Correctness
A consistent codebase is navigable—even if imperfect.
• Same patterns everywhere
• Same naming conventions
• Same folder logic
Inconsistency multiplies cognitive load faster than any algorithmic inefficiency.
10. Refactor Continuously, Not Heroically
Big refactors are usually a smell.
• Refactor as you touch code
• Leave things slightly better than you found them
• Dont let cleanup pile up into fear
Entropy is real. You either fight it daily or lose spectacularly 🌪️.
11. Design for Deletion
The best code is easy to remove.
• Avoid tight coupling
• Prefer composition over inheritance
• Keep feature boundaries clean
If you cant delete a feature safely, it owns you—not the other way around.
12. Tooling Is Part of the Codebase
Linters, formatters, CI, and automation are not optional polish.
• Enforce rules mechanically
• Remove human judgment where possible
• Let tools be the bad cop
Humans are bad at consistency. Machines love it 🤖.
The Meta-Principle
A good codebase optimizes for future humans, not present cleverness.
Every line you write is a tiny act of communication across time. Write like Future-You is tired, busy, and slightly annoyed—but still clever enough to appreciate clean design.
Entropy never sleeps. Engineers must 😄