|
1 |
| -# Zig Design Patterns |
| 1 | +# Zig Patterns |
2 | 2 |
|
3 |
| -- [Zig Design Patterns](#zig-design-patterns) |
| 3 | +- [Zig Patterns](#zig-patterns) |
4 | 4 | - [About](#about)
|
5 |
| - - [Examples](#examples) |
| 5 | + - [The Patterns](#the-patterns) |
6 | 6 | - [License](#license)
|
7 | 7 |
|
8 | 8 | ## About
|
9 | 9 |
|
10 |
| -This repository contains examples of common design patterns found in Zig's standard library and many community projects. |
| 10 | +This repository contains examples of common patterns found in Zig's standard library and many community projects. |
11 | 11 |
|
12 | 12 | Note that copying (one of) these patterns verbatim into your project may not be useful; it's important to weigh the pros and cons of different patterns. If you come from another language, especially a non-systems one, you'll often find that the more unfamiliar ideas featured here may be more useful.
|
13 | 13 |
|
14 |
| -For example, I've seldom used interface-like patterns when designing systems in Zig, despite using such patterns dozens of times a day at work writing TypeScript or Go. |
| 14 | +For example, I've seldom used interface-like patterns when designing systems in Zig, despite using such patterns dozens of times a day at my old job writing TypeScript or Go. |
15 | 15 |
|
16 |
| -## Examples |
| 16 | +## The Patterns |
17 | 17 |
|
18 | 18 | All examples are annotated with comments including recommendations regarding when to use the patterns shown.
|
19 | 19 |
|
20 |
| -| Example | How to run | |
21 |
| -| ----- | --- | |
22 |
| -| [`@fieldParentPtr`](src/field_parent_ptr.zig) | `zig build field_parent_ptr` | |
23 |
| -| [Inline Switch](src/inline_switch.zig) | `zig build inline_switch` | |
24 |
| -| [MultiArrayList](src/multi_array_list.zig) | `zig build multi_array_list` | |
25 |
| -| [Type Function](src/type_function.zig) | `zig build type_function` | |
26 |
| -| [Virtual Table](src/vtable.zig) | `zig build vtable` | |
| 20 | +Example tests can be run with `zig build [name_of_pattern]`. For example, to run the tests in `typing/type_function.zig`, run `zig build type_function`. |
| 21 | + |
| 22 | +Patterns are grouped into the following categories: |
| 23 | +- `data` - data layout and organization techniques |
| 24 | +- `typing` - `comptime`, runtime, or mixed `type` or type safety techniques |
| 25 | + |
| 26 | +Some patterns may belong in multiple categories; I've selected the most fitting one in my opinion. |
27 | 27 |
|
28 | 28 | ## License
|
29 | 29 |
|
|
0 commit comments