rule stringclasses 4
values | rule_title stringclasses 4
values | rationale stringclasses 4
values | before stringclasses 4
values | after stringclasses 4
values | language stringclasses 1
value | source_file stringclasses 4
values | canonical_repo stringclasses 1
value |
|---|---|---|---|---|---|---|---|
rule-1 | Branch on type with an explicit `if … is_a?`, not a clever `case` | `case … in` demands exhaustive matching and, under the Grant ORM's `Grant::Base+` inference, fails to compile (`Error: case is not exhaustive. Missing types: Grant::Base`). The dot-receiver sugar `case … when .is_a?(T)` compiles, but the leading dot is a riddle the reader must decode before reaching the branch bodies. ... | case user
in Users::Regular
session[:user_type] = "regular"
session[:session_version] = user.session_version
in Users::Admin
session[:user_type] = "admin"
end
# or, the dot-receiver sugar form:
case user
when .is_a?(Users::Regular)
session[:user_type] = "regular"
session[:session_version] = user.session_vers... | def record_session(user : Users::Regular | Users::Admin, session : Hash(Symbol, String | Int32)) : Nil
if user.is_a?(Users::Regular)
session[:user_type] = "regular"
session[:session_version] = user.session_version
else
session[:user_type] = "admin"
end
end | crystal | examples/01_branch_on_type.cr | https://github.com/AgentC-Consulting/aed-conventions |
rule-2 | Name the thing; don't make the reader decode a chain | The terse form is compact, but the reader has to hold three operations in their head at once: a nilable session lookup, a block binding, and a comparison — all inside a negated guard. Naming the intermediate turns the same logic into two plain statements: this is the state we expected; refuse unless it exists and match... | return unless session["oauth_state"]?.try { |s| constant_time_equal?(s, state) } | expected_state = session["oauth_state"]?
return unless expected_state && constant_time_equal?(expected_state, state) | crystal | examples/02_name_the_thing.cr | https://github.com/AgentC-Consulting/aed-conventions |
rule-3 | Prefer explicit guard clauses to nested ternaries / one-liners | One line, two nested ternaries, three outcomes. The author saved four lines; every future reader re-parses the precedence to find out what happens when. The guard-clause form doubles as the security argument: each line is one condition under which entry is refused, and everything after the guards assumes both checks pa... | def verify_password(password : String) : self?
password_digest.empty? ? nil : (Crypto::Bcrypt::Password.new(password_digest).verify(password) ? self : nil)
end | def verify_password(password : String) : self?
return nil if password_digest.empty?
return nil unless Crypto::Bcrypt::Password.new(password_digest).verify(password)
self
end | crystal | examples/03_guard_clauses.cr | https://github.com/AgentC-Consulting/aed-conventions |
rule-4,rule-5 | Use full, intention-revealing names; say WHY in a comment, let the code say WHAT | Cryptic names force a comment per line, and every comment just restates the code next to it. The AFTER version has FEWER comments — good names removed the need for most of them, and the one comment that remains carries information the code cannot: the specific attack (session fixation) the reset prevents. | # process the user
def do_it(u)
# reset the session
session.reset
# set the id
session[:uid] = u.id
# set the version
tmp = u.session_version
session[:sv] = tmp
end | def establish_session(user : Users::Regular) : Nil
# Rotate the session id BEFORE writing identity: prevents session fixation
# (an attacker pre-planting a known session id that survives login).
session.reset
session[:user_id] = user.id
session[:session_version] = user.session_version
end | crystal | examples/04_reader_first_names_and_comments.cr | https://github.com/AgentC-Consulting/aed-conventions |
AED Conventions — before/after examples (seed dataset, v0)
This is a seed dataset — four labeled before/after pairs, not a benchmark. It exists because the pairs are real and worth sharing now, not because four examples constitute a mature corpus. Honest framing over inflated claims: this is v0, and it is expected to grow as the AED conventions add more rules (a control-flow rule set is planned for a public v1.1).
What this is
Four {rule, rationale, before, after, language} records drawn directly from
AgentC-Consulting/aed-conventions,
the canonical, public repository of Agent-Enhanced Development (AED) — code
conventions for codebases written, reviewed, and maintained by humans and
coding agents together. Each record pairs a terser/clever form of a piece of
Crystal code (before) with the AED-conforming form (after), plus the
rationale a human or agent would use to justify preferring one over the
other.
This is style-transfer / code-readability pair data: same behavior, two surface forms, labeled by which rule motivates the preferred form and why.
Why this shape
The conventions themselves
(CONVENTIONS.md)
are the source of truth — six rules, each with a stable anchor
(#rule-1 … #rule-6) and worked examples. This dataset is a machine-readable
extraction of the same before/after pairs that already live in the repo's
examples/
directory as standalone, compiling Crystal files. If you want the rules in
prose, read the repo. If you want the pairs as structured records, this is
that.
Fields
| Field | Type | Description |
|---|---|---|
rule |
string | Anchor id(s) in CONVENTIONS.md, e.g. "rule-1" or "rule-4,rule-5" when one example illustrates two rules together. |
rule_title |
string | Human-readable title of the rule(s). |
rationale |
string | Why the after form is preferred — the argument, not just the assertion. |
before |
string | The terser / clever / harder-to-parse form. |
after |
string | The AED-conforming form: reads like a plain statement of intent. |
language |
string | Always "crystal" in this seed; the rules generalize to other languages, the examples do not (yet). |
source_file |
string | Path in the canonical repo the pair was drawn from. |
canonical_repo |
string | Always https://github.com/AgentC-Consulting/aed-conventions — cite this when using the data. |
License
Dual-licensed, matching the canonical repository:
- Prose fields (
rule_title,rationale, this card) — CC BY 4.0, credit to AgentC Consulting. - Code fields (
before,after) — MIT, take freely, with or without credit.
Full license text: LICENSE
(CC BY 4.0) and LICENSE-EXAMPLES
(MIT) in the canonical repo.
Citation
Please cite the canonical repository:
AgentC-Consulting/aed-conventions
(CITATION.cff).
Who maintains this
AgentC Consulting — agent-enhanced development is the day job: building and modernizing production applications with coding agents doing the majority of the writing, under conventions that keep every line reviewable.
- Downloads last month
- 11