Skip to content

Instantly share code, notes, and snippets.

@unlight
Last active May 17, 2025 17:16
Show Gist options
  • Save unlight/568ba63e9678748eb68a to your computer and use it in GitHub Desktop.
Save unlight/568ba63e9678748eb68a to your computer and use it in GitHub Desktop.
Naming

Propose a variable/function/method/class name.

Context/Purpose: [What does the code do? Why is it needed?]
Domain: TypeScript, Node.js, NestJS, [industry] (Calendar scheduling app)
Scope: [Used across the app for consistency]
Key Priorities: Readability, maintainability, brevity, follows [NestJS] conventions, humor Constraints/Conventions:

  • Try to stick the limit to 1-3 words, use 4 if necessary for specificity
  • A name must be short, intuitive and descriptive:
    • Short. A name must not take long to type and, therefore, remember;
    • Intuitive. A name must read naturally, as close to the common speech as possible;
    • Descriptive. A name must reflect what it does/possesses in the most efficient way.
  • Avoid
    • Contractions
    • Context duplication
  • For function follow A/HC/LC Pattern: [Prefix?] + [Action] + [High Context] + [Low Context?]
    • Actions: get, set, reset, remove, delete, compose, handle
    • Prefixes: is, has, should, min/max, prev/next If necessary to add type to name, you can use words "Pool Cache Dict Map Collection List Array Object Structure" as suffix If necessary to add size to name, you can use words "Tiny Small Normal Big Huge Enormous" as suffix or prefix Example of Bad Names: ?

Правила

Префиксы:

  • New
  • Target
  • Better
  • Smart
  • Nice
  • Internal
  • Fuzzy
  • Next
  • Old
  • Custom
  • Test (e.g. TestItem)

Суффиксы (окончания):

  • Info
  • Data
  • Helper
  • Internal
  • Ling
  • Zoo
  • Ify
  • Us (Latin)
  • Fields
  • Structure
  • Effect

Тип:

  • Pool
  • Cache
  • Dict
  • Map
  • Collection
  • List
  • Array
  • Object
  • Structure

Названия:

  • Behavior
  • Formatter
  • Internal

Поведение/Состояние:

  • Normal
  • Full
  • Internal

Поведение/Состояние:

  • DataObject
  • Dto
  • ApiModel
  • Contracts (folder instead of dto)

Размер:

  • Tiny
  • Small
  • Normal
  • Big
  • Huge
  • Enormous

Утилиты:

  • Utils
  • Utility
  • Helper
  • Tools
  • Assistant
  • HelpingHand
  • HelpingTool
  • Hand
  • Unit
  • Booster
  • Backpack
  • Donkey
  • Really

Для файлов (окончания):

  • service
  • module
  • function
  • component
  • view
  • container
  • page
  • route
  • controller
  • structure
  • effect

Other

  • core (instead of domain)

Суффиксы для файлов для группировки по ролям

  • entity (работа с БД) import { User } from '@prisma/client';
  • usecase (folder usecases)
  • dto
  • input (for Graphql)
  • output (for Graphql)
  • processor (queue)

Service differentiations

  • projector (projection) user.projection.ts
  • output
  • view (viewRepository)

Infra

  • repository (src/modules/users/infra/repositories/user.repository.ts)
  • src/modules/users/infra/protocols/user-repository.protocol.ts (interface)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment