Skip to content

Latest commit

 

History

History
71 lines (57 loc) · 3.21 KB

File metadata and controls

71 lines (57 loc) · 3.21 KB

LLM Code Style Preferences

Clojure Style Guidelines

Conditionals

  • Use if for single condition checks, not cond
  • Only use cond for multiple condition branches
  • Prefer if-let and when-let for binding and testing a value in one step
  • Consider when for conditionals with single result and no else branch
  • consider cond->, and cond->>

Variable Binding

  • Minimize code points by avoiding unnecessary let bindings
  • Only use let when a value is used multiple times or when clarity demands it
  • Inline values used only once rather than binding them to variables
  • Use threading macros (->, ->>) to eliminate intermediate bindings

Parameters & Destructuring

  • Use destructuring in function parameters when accessing multiple keys
  • Example: [{:keys [::zloc ::match-form] :as ctx}] for namespaced keys instead of separate let bindings
  • Example: [{:keys [zloc match-form] :as ctx}] for regular keywords

Control Flow

  • Track actual values instead of boolean flags where possible
  • Use early returns with when rather than deeply nested conditionals
  • Return nil for "not found" conditions rather than objects with boolean flags

Comments

  • Do not include comments in generated code, unless specifically asked to.

Nesting

  • Minimize nesting levels by using proper control flow constructs
  • Use threading macros (->, ->>) for sequential operations

Function Design

  • Functions should generally do one thing
  • Pure functions preferred over functions with side effects
  • Return useful values that can be used by callers
  • smaller functions make edits faster and reduce the number of tokens
  • reducing tokens makes me happy

Library Preferences

  • Prefer clojure.string functions over Java interop for string operations
    • Use str/ends-with? instead of .endsWith
    • Use str/starts-with? instead of .startsWith
    • Use str/includes? instead of .contains
    • Use str/blank? instead of checking .isEmpty or .trim
  • Follow Clojure naming conventions (predicates end with ?)
  • Favor built-in Clojure functions that are more expressive and idiomatic

REPL best pratices

  • Always reload namespaces with :reload flag: (require '[namespace] :reload)
  • Always change into namespaces that you are working on

Testing Best Practices

  • Always reload namespaces before running tests with :reload flag: (require '[namespace] :reload)
  • Test both normal execution paths and error conditions

Using Shell Commands

  • Prefer the idiomatic clojure.java.shell/sh for executing shell commands

  • Always handle potential errors from shell command execution

  • Use explicit working directory for relative paths: (shell/sh "cmd" :dir "/path")

  • For testing builds and tasks, run clojure -X:test instead of running tests piecemeal

  • When capturing shell output, remember it may be truncated for very large outputs

  • Consider using shell commands for tasks that have mature CLI tools like diffing or git operations

  • Context Maintenance:

    • Use clojure_eval with :reload to ensure you're working with the latest code
    • always switch into (in-ns ...) the namespace that you are working on
    • Keep function and namespace references fully qualified when crossing namespace boundaries