AtlatestRepositorysigil-web-styles
sigil-web-styles / tree / build / dev / lib / _pkg / sigil-stdlib / stylenaming.md
2
# Naming Conventions4
> Standard naming patterns for Sigil code.6
## General Rules8
- Use **lowercase with hyphens**: `calculate-total`, not `calculateTotal` or `calculate_total`9
- Be descriptive but concise: `user-name` not `u-n` or `the-name-of-the-user`10
- Avoid abbreviations unless universally understood: `config` ok, `cfg` discouraged12
## Predicates14
Functions that return a boolean end with `?`.16
```scheme17
(null? '()) ; => #t18
(string? "hello") ; => #t19
(file-exists? path) ; => #t or #f21
;; Define your own22
(define (valid-email? str)23
(string-contains str "@"))24
```26
## Mutators28
Procedures that modify state end with `!`.30
```scheme31
(set! x 10)32
(vector-set! v 0 value)33
(set-point-x! p 100)35
;; Define your own36
(define (increment-counter! counter)37
(set-counter-value! counter38
(+ (counter-value counter) 1)))39
```41
## Conversions43
Procedures that convert between types use `->`.45
```scheme46
(string->number "42") ; => 4247
(number->string 42) ; => "42"48
(list->vector '(1 2 3)) ; => #(1 2 3)49
(symbol->string 'hello) ; => "hello"51
;; Define your own52
(define (point->list p)53
(list (point-x p) (point-y p)))54
```56
## Constructors58
Use `make-` prefix for explicit constructors with arguments.60
```scheme61
(make-vector 10 0) ; Create vector of 10 zeros62
(make-hash-table) ; Create empty hash table63
(make-channel 5) ; Create buffered channel64
```66
For simple structs, the type name itself is the constructor:68
```scheme69
(point x: 10 y: 20) ; Not make-point70
(config host: "localhost")71
```73
## Private Helpers75
Internal procedures not meant for export can use `%` prefix.77
```scheme78
(define (%validate-input x)79
...)81
(define (public-api x)82
(when (%validate-input x)83
...))84
```86
Alternatively, simply don't export them—unexported bindings are module-private.88
## Constants90
Use descriptive names, optionally UPPER-CASE for emphasis.92
```scheme93
(define DEFAULT-PORT 8080)94
(define MAX-RETRIES 3)95
(define pi 3.14159) ; Lowercase also acceptable96
```98
## Type Names100
Record type names often use angle brackets (R7RS convention):102
```scheme103
(define-record-type <point> ...)104
(define-record-type <http-response> ...)105
```107
With `define-struct`, plain names are typical:109
```scheme110
(define-struct point ...)111
(define-struct http-response ...)112
```114
## Module Names116
- Use lowercase with hyphens117
- Organize hierarchically118
- Match directory structure120
```scheme121
(sigil core) ; Core module122
(sigil http client) ; HTTP client submodule123
(myapp users api) ; App-specific module124
```126
## Parameter Names128
Use meaningful parameter names that describe purpose:130
```scheme131
;; Good132
(define (send-email recipient subject body) ...)133
(define (connect host port) ...)135
;; Avoid136
(define (send-email a b c) ...)137
(define (connect x y) ...)138
```140
For well-known single-letter conventions:141
- `n` - count or number142
- `x`, `y`, `z` - coordinates or generic values143
- `i`, `j`, `k` - loop indices144
- `f`, `g` - functions145
- `p` - predicate146
- `s` - string147
- `lst` - list