refactor: apply project style guidelines
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
# Compile through recoverable source errors
|
||||
# compile through recoverable source errors
|
||||
|
||||
Honey produces an executable whenever source errors can be represented safely: structurally valid syntax trees may contain typed invalid nodes carrying source spans and diagnostic identities, and semantic checking or lowering turns demanded invalid code into diagnostic runtime traps. Clean compilation returns status `0`, compilation that emits an executable with source diagnostics returns `1`, and unrecoverable infrastructure or backend failure returns `2`. This deliberately favors testing unaffected program paths over conventional fail-fast compilation; parser recovery must preserve valid surrounding syntax, while compact syntax-tree storage remains private behind typed views.
|
||||
Honey produces an executable whenever source errors can be represented safely: structurally valid syntax trees may contain typed invalid nodes carrying source spans and diagnostic identities, and semantic checking or lowering turns demanded invalid code into diagnostic runtime traps. clean compilation returns status `0`, compilation that emits an executable with source diagnostics returns `1`, and unrecoverable infrastructure or backend failure returns `2`. this deliberately favors testing unaffected program paths over conventional fail-fast compilation; parser recovery must preserve valid surrounding syntax, while compact syntax-tree storage remains private behind typed views.
|
||||
|
||||
+21
-21
@@ -1,27 +1,27 @@
|
||||
# Honey style
|
||||
|
||||
These guidelines apply to Honey programs, the compiler, and the standard library. The compiler is currently written in Bro; apply the same conventions using syntax supported by the bootstrap compiler.
|
||||
these guidelines apply to Honey programs, the compiler, and the standard library. the compiler is currently written in Bro; apply the same conventions using syntax supported by the bootstrap compiler. generated C bindings retain the generator's declarations and formatting.
|
||||
|
||||
## Names
|
||||
## names
|
||||
|
||||
- Use `snake_case` for procedures, variables, fields, and enum members; `PascalCase` for types; `SCREAMING_SNAKE_CASE` for named sentinel constants.
|
||||
- Choose names that describe the value or operation. Short loop indices are appropriate when their meaning is local.
|
||||
- Qualify imported operations with their module, such as `mem.alloc` and `ast.node_count`. Mark file-local implementation details with `@hide:file`.
|
||||
- use `snake_case` for procedures, variables, fields, and enum members; `PascalCase` for types; `SCREAMING_SNAKE_CASE` for named sentinel constants.
|
||||
- choose names that describe the value or operation. short loop indices are appropriate when their meaning is local. preserve external ABI names.
|
||||
- qualify imported operations with their module, such as `mem.alloc` and `ast.node_count`. mark file-local implementation details with `@hide:file`.
|
||||
|
||||
## Bindings and types
|
||||
## bindings and types
|
||||
|
||||
- Prefer `::` for bindings that stay fixed; use `:=` for bindings that change.
|
||||
- Infer types when the initializer makes the intended type clear. Write an explicit type when it determines representation, mutability, or a public contract.
|
||||
- Request mutable pointers and slices only when the operation needs to modify their contents.
|
||||
- Give aggregates meaningful defaults. Use `undefined` only when every value that can be read is assigned first.
|
||||
- prefer `::` for bindings that stay fixed; use `:=` for bindings that change, including values mutated through pointers.
|
||||
- infer types when the initializer makes the intended type clear. write an explicit type when it determines representation, mutability, or a public contract.
|
||||
- request mutable pointers and slices only when the operation needs to modify their contents.
|
||||
- give aggregates meaningful defaults. use `undefined` only when every value that can be read is assigned first.
|
||||
|
||||
## Layout and control flow
|
||||
## layout and control flow
|
||||
|
||||
- Use four-space indentation and put opening braces on the declaration or control-flow line.
|
||||
- Use single-line bodies for simple operations. Use braces for multiple statements or nested control flow.
|
||||
- Break long parameter lists and aggregate initializers across lines, with a trailing comma on the last item.
|
||||
- Use early returns for terminal cases so the main path stays shallow.
|
||||
- Register `defer` cleanup immediately after acquiring a resource. Use `errdefer` for cleanup needed only until ownership is transferred successfully.
|
||||
- use four-space indentation and put opening braces on the declaration or control-flow line.
|
||||
- use single-line bodies for simple operations. use braces for multiple statements or nested control flow.
|
||||
- break long parameter lists and aggregate initializers across lines, with a trailing comma on the last item.
|
||||
- use early returns for terminal cases so the main path stays shallow.
|
||||
- register `defer` cleanup immediately after acquiring a resource. use `errdefer` for cleanup needed only until ownership is transferred successfully.
|
||||
|
||||
## allocation and ownership
|
||||
|
||||
@@ -36,10 +36,10 @@ These guidelines apply to Honey programs, the compiler, and the standard library
|
||||
- prefer lowercase prose in documentation, including headings and sentence starts. preserve the case of code identifiers, proper names, and acronyms.
|
||||
- write comments for invariants, ownership, or reasons that the code alone does not explain. use `#!` for API documentation.
|
||||
|
||||
## Library operations
|
||||
## library operations
|
||||
|
||||
- Reuse an existing standard-library operation when it expresses the work directly.
|
||||
- Use `mem.set(destination, value)` when assigning the same complete typed value to every element of a mutable slice. This preserves the value's fields; it is not a byte-wise zeroing operation.
|
||||
- Keep a loop when only one field is initialized, values differ by element, or initialization shares a pass with other work. A helper should not introduce unnecessary writes or another traversal.
|
||||
- reuse an existing standard-library operation when it expresses the work directly.
|
||||
- use `mem.set(destination, value)` when assigning the same complete typed value to every element of a mutable slice. this preserves the value's fields; it is not a byte-wise zeroing operation.
|
||||
- keep a loop when only one field is initialized, values differ by element, or initialization shares a pass with other work. a helper should not introduce unnecessary writes or another traversal.
|
||||
|
||||
When editing or reviewing code, apply every relevant guideline to the changed code. Keep unrelated formatting changes separate.
|
||||
when editing or reviewing code, apply every relevant guideline to the changed code. keep unrelated formatting changes separate.
|
||||
|
||||
Reference in New Issue
Block a user