|
| 1 | +# LLM Code Style Preferences |
| 2 | + |
| 3 | +## Clojure Style Guidelines |
| 4 | + |
| 5 | +### Conditionals |
| 6 | +- Use `if` for single condition checks, not `cond` |
| 7 | +- Only use `cond` for multiple condition branches |
| 8 | +- Prefer `if-let` and `when-let` for binding and testing a value in one step |
| 9 | +- Consider `when` for conditionals with single result and no else branch |
| 10 | +- consider `cond->`, and `cond->>` |
| 11 | + |
| 12 | +### Variable Binding |
| 13 | +- Minimize code points by avoiding unnecessary `let` bindings |
| 14 | +- Only use `let` when a value is used multiple times or when clarity demands it |
| 15 | +- Inline values used only once rather than binding them to variables |
| 16 | +- Use threading macros (`->`, `->>`) to eliminate intermediate bindings |
| 17 | + |
| 18 | +### Parameters & Destructuring |
| 19 | +- Use destructuring in function parameters when accessing multiple keys |
| 20 | +- Example: `[{:keys [::zloc ::match-form] :as ctx}]` for namespaced keys instead of separate `let` bindings |
| 21 | +- Example: `[{:keys [zloc match-form] :as ctx}]` for regular keywords |
| 22 | + |
| 23 | +### Control Flow |
| 24 | +- Track actual values instead of boolean flags where possible |
| 25 | +- Use early returns with `when` rather than deeply nested conditionals |
| 26 | +- Return `nil` for "not found" conditions rather than objects with boolean flags |
| 27 | + |
| 28 | +### Comments |
| 29 | +- Do not include comments in generated code, unless specifically asked to. |
| 30 | + |
| 31 | +### Nesting |
| 32 | +- Minimize nesting levels by using proper control flow constructs |
| 33 | +- Use threading macros (`->`, `->>`) for sequential operations |
| 34 | + |
| 35 | +### Function Design |
| 36 | +- Functions should generally do one thing |
| 37 | +- Pure functions preferred over functions with side effects |
| 38 | +- Return useful values that can be used by callers |
| 39 | +- smaller functions make edits faster and reduce the number of tokens |
| 40 | +- reducing tokens makes me happy |
| 41 | + |
| 42 | +### Library Preferences |
| 43 | +- Prefer `clojure.string` functions over Java interop for string operations |
| 44 | + - Use `str/ends-with?` instead of `.endsWith` |
| 45 | + - Use `str/starts-with?` instead of `.startsWith` |
| 46 | + - Use `str/includes?` instead of `.contains` |
| 47 | + - Use `str/blank?` instead of checking `.isEmpty` or `.trim` |
| 48 | +- Follow Clojure naming conventions (predicates end with `?`) |
| 49 | +- Favor built-in Clojure functions that are more expressive and idiomatic |
| 50 | + |
| 51 | +### REPL best pratices |
| 52 | +- Always reload namespaces with `:reload` flag: `(require '[namespace] :reload)` |
| 53 | +- Always change into namespaces that you are working on |
| 54 | + |
| 55 | +### Testing Best Practices |
| 56 | +- Always reload namespaces before running tests with `:reload` flag: `(require '[namespace] :reload)` |
| 57 | +- Test both normal execution paths and error conditions |
| 58 | + |
| 59 | +### Using Shell Commands |
| 60 | +- Prefer the idiomatic `clojure.java.shell/sh` for executing shell commands |
| 61 | +- Always handle potential errors from shell command execution |
| 62 | +- Use explicit working directory for relative paths: `(shell/sh "cmd" :dir "/path")` |
| 63 | +- For testing builds and tasks, run `clojure -X:test` instead of running tests piecemeal |
| 64 | +- When capturing shell output, remember it may be truncated for very large outputs |
| 65 | +- Consider using shell commands for tasks that have mature CLI tools like diffing or git operations |
| 66 | + |
| 67 | +- **Context Maintenance**: |
| 68 | + - Use `clojure_eval` with `:reload` to ensure you're working with the latest code |
| 69 | + - always switch into `(in-ns ...)` the namespace that you are working on |
| 70 | + - Keep function and namespace references fully qualified when crossing namespace boundaries |
0 commit comments