CR

Crystal Defaults

Core Crystal coding conventions covering naming, type annotations, and idiomatic patterns

Details

Language / Topic
crystalCrystal
Category
Style Guide

Rules

balanced
- Use `snake_case` for methods, variables, and file names; `PascalCase` for classes, modules, and structs; `SCREAMING_SNAKE_CASE` for constants.
- Prefer `struct` over `class` for small, immutable value types — structs are stack-allocated and copied on assignment, which eliminates GC pressure.
- Use explicit return type annotations on public methods: `def fetch(url : String) : HTTP::Client::Response` — they serve as documentation and catch return type regressions.
- Use `?` suffix for boolean-returning methods (`valid?`, `empty?`) and `!` suffix for in-place or raising variants (`save!`, `parse!`) — follow the Crystal convention uniformly.