a devlog on machines & languages

6 Coding Style

I have developed a very specific way of writing code over time. While extending an application causes a collapse in discipline in order to get things done, I do try to stick to it where feasible. With the rise of coding LLMs, this task has become a lot easier. I can write what I want and then have it review the codebase and fix it according to my guidelines.

While my guidelines are often project-specific, the following is a good baseline to follow and gives me maintainable code.

Basic Code Guidelines

Naming

KindConventionExample
Functionssnake_case, noun-firstuser_create(), mail_send()
DataclassesPascalCaseUser, VerificationCode
Modulessnake_caseemail_service.py
Constants / enumsUPPER_SNAKE_CASEMAX_RETRY_COUNT

Exception Taxonomy

KindMeaningHandling
FaultUnrecoverable (connection loss, HTTP 500)Expose via banner/terminal in the UI. Never retried silently.
ErrorExpected in normal business operation (FileNotFound, InvalidCoupon, PasswordTooShort)Handle explicitly, and report to the user in the normal execution flow.
AssertionAPI/Function contract breachedExpose via banner/terminal in the UI. Application crashes hard. Never swallowed.

Error vs Assertion is a judgment call. A 403/404 can mean a genuine dev mistake (stale URL) or hostile interference (tampered payload/route). This must be resolved depending on the application environment: dev vs production.

Exceptions must never be swallowed silently in any of the three cases.

I wrap the above guidelines in a simple prompt:

Do a comprehensive code review of `@src/` and write it to `@docs/<YYYYMMDD[A-Z]>_CODE_REVIEW.md`.

Extract the architecture of the application from the code and write it to `@docs/<YYYYMMDD[A-Z]>_ARCHITECTURE.md`. The elements I am interested in include:

- An intro: what the application does
- Application layout
- The expected shape of the input data, and the output
- Etc

This is more than enough to guide most LLMs to do the right thing.