mirror of
https://github.com/ziglang/zig.git
synced 2024-11-25 05:40:16 +00:00
better glossary definitions for container and namespace
parent
8e39f02941
commit
268ccd791f
34
Glossary.md
34
Glossary.md
@ -10,31 +10,27 @@ See `src/Air.zig`.
|
|||||||
|
|
||||||
Compile-time, as opposed to runtime. [Introduction to comptime in zig](https://ziglang.org/documentation/master/#comptime)
|
Compile-time, as opposed to runtime. [Introduction to comptime in zig](https://ziglang.org/documentation/master/#comptime)
|
||||||
|
|
||||||
### Container/Namespace
|
### Container
|
||||||
|
|
||||||
Structs, enums, unions, and opaques. Zig source files are themselves struct definitions.
|
An array list, hash map, or non-intrusive linked list.
|
||||||
|
|
||||||
Think of containers as where you _declare_ things, which is order-independent, whereas blocks are where you _execute_ things, which is order-dependent.
|
### Namespace
|
||||||
|
|
||||||
<details>
|
Structs, enums, unions, and opaques declare namespaces. Each Zig source file is a struct and
|
||||||
|
therefore also a namespace.
|
||||||
|
|
||||||
```zig
|
Namespaces contain order-independent declarations.
|
||||||
// this is a container
|
|
||||||
// declarations are simultaneous
|
|
||||||
opaque {
|
|
||||||
const b = a+1;
|
|
||||||
const a = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is NOT a container
|
When deciding upon a name for a namespace, keep in mind the **fully qualified namespace**.
|
||||||
// executions are sequential
|
|
||||||
do: {
|
|
||||||
const b = a+1; // error: use of undeclared identifier 'a'
|
|
||||||
const a = 1;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
For example:
|
||||||
|
|
||||||
|
* Bad namespaces:
|
||||||
|
- `hash.HashMap`
|
||||||
|
- `crypto.sha.Sha3`
|
||||||
|
* Good namespaces:
|
||||||
|
- `hash.Map`
|
||||||
|
- `crypto.Sha3`
|
||||||
|
|
||||||
### ELF
|
### ELF
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user