Gleam Code Review
Review Gleam code against these guidelines and suggest improvements.
Function Design
- •Prefer small, composable functions over large blocks of code
- •Functions should do one thing well
- •Extract complex logic into named helper functions
Control Flow
- •Avoid deep nesting; use
result.tryandbool.guardfor early returns - •Prefer composable pipelines (
|>) over excessiveusesyntax - •Use
usefor callbacks, but don't overuse it—pipelines are often clearer
gleam
// Prefer pipeline items |> list.filter(is_valid) |> list.map(transform) // Over nested use use item <- list.filter_map(items) // ...
Error Handling
- •Never return
Option(t)from a function; useResult(t, Nil)instead - •
let assertis acceptable in tests andmain; in library code it's acceptable if provably safe, but prefer explicit error handling when a reasonable alternative exists - •Handle errors explicitly with
result.try,result.map, or pattern matching
Test Style
- •Use newer assert style:
assert foo == "bar"overfoo |> should.equal("bar") - •Use
qcheck.runfor property-based tests
Comments
- •Avoid extraneous comments that duplicate what the code does—they get outdated quickly
- •If code needs a comment to explain what it does, rewrite the code to be clearer instead
- •Comments are helpful only when something is especially tricky or noteworthy for a special reason
- •Good:
// PKCS#7 padding requires block alignment(explains why, not what) - •Bad:
// Loop through the list and filter valid items(just describes the code)
Review Output
For each issue found:
- •Quote the problematic code
- •Explain the issue briefly
- •Show the suggested fix