⚡ Curated dev resources & dealsSponsored
DevToolBayFree Developer Tools

命名约定:camelCase、snake_case 与 kebab-case

跨栈边界的命名翻译规则与自动化收益。

发布于·约 2 分钟阅读

Naming conventions look like taste until they cross a boundary: a Python service talking to a JavaScript front end, a JSON field meeting a URL, a database column meeting a TypeScript type. Each ecosystem has a default — knowing the map prevents most of the friction.

Where each style lives

  • camelCase — JavaScript, TypeScript, Java and Swift variables; JSON API fields.
  • snake_case — Python, Ruby, Rust and SQL columns; the usual database-to-API style.
  • kebab-case — URLs, HTML attributes, CSS classes and file names, because the hyphen is safe everywhere.
  • PascalCase — types, classes and component names.
  • CONSTANT_CASE — environment variables and compile-time constants.

The acronyms minefield

HTTPServer, HttpServer and httpServer are all legal camelCase readings. Pick one rule — consecutive capitals count as one word — and apply it mechanically. The Case Converter implements that rule across eleven styles, so batch renames stay consistent instead of drifting file by file.

Serializing across the boundary

Databases emit snake_case; JavaScript clients want camelCase. Modern serializers convert automatically. When yours does not, convert field lists in bulk with the converter before wiring types, and generate the matching interfaces from a sample payload with the JSON to TypeScript tool.

URLs deserve their own rules

Lowercase kebab URLs avoid case-sensitivity bugs across servers and CDNs. After restructuring paths, check routing rules against real address structure with the URL Parser — path case bugs hide until a cached link meets a case-sensitive route.

The rule underneath all of it: consistency within a layer, explicit conversion between layers. Convention is a contract, and the tools above keep that contract auditable.

相关指南

文中提到的工具