Crystal keeps its own language identity while following Pureline principles.
Idiomatic Postfix Guards Are Allowed
Crystal postfix conditions are Pureline-compliant when they express a short, obvious guard.
return unless valid
return if closed They fit Pureline well because they can keep guard logic compact and preserve a linear happy path.
Use an explicit block when either the condition or the guarded action becomes more complex:
if session.closed? || session.expired?
logger.info("Session is no longer usable")
return
end The rule is not "avoid postfix conditions." The rule is: use the form that keeps the intent immediately obvious.
Avoid else
if valid
execute
else
reject
end if !valid
reject
return
end
execute Idiomatic Naming
Variables and methods use snake_case:
session_service
packet_registry
load_user
create_session SessionService
PacketRegistry
UserStorage Prefer Type Inference
session = create_session(user) session : Session = create_session(user) when Crystal can infer the type clearly.
Explicit Nil Guards
user = users.find(id)
if user.nil?
return
end
session = create_session(user) Avoid burying expected nil handling inside deeply nested chains.
Exceptions Are for Exceptional States
Expected outcomes should preferably use normal domain modeling such as nil, union types, result-like structures, or enums.
Exceptions should represent exceptional failure, not ordinary branching.
Avoid Macro Cleverness Without Need
Crystal macros are powerful, but Pureline avoids hiding ordinary behavior behind metaprogramming unless the abstraction produces a clear architectural benefit.
Generated behavior should remain predictable and discoverable.