https://github.com/ringabout/nimstyleguide
The style guide for Nim(only applying to our team's projects).
https://github.com/ringabout/nimstyleguide
Last synced: 7 months ago
JSON representation
The style guide for Nim(only applying to our team's projects).
- Host: GitHub
- URL: https://github.com/ringabout/nimstyleguide
- Owner: ringabout
- License: apache-2.0
- Created: 2020-07-26T11:29:58.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-28T09:01:50.000Z (almost 6 years ago)
- Last Synced: 2025-09-21T16:35:38.818Z (8 months ago)
- Language: Nim
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# NimStyleGuide
The style guide for Nim only applies to our team's projects.
## Philosophy
### Explicit is better than implicit
## Preference
### Prefer `a == nil` to `a.isNil`
### Prefer `a.len = 0` to `a == ""`
## Style
### Long parameters
```nim
proc createIoCompletionPort*(
FileHandle: Handle,
ExistingCompletionPort: Handle,
CompletionKey: ULONG_PTR,
NumberOfConcurrentThreads: DWORD
): Handle {.libKernel32, importc: "CreateIoCompletionPort"}
```
## C wrapper reuqirements
C wrapper must be both standard and correct.
| ctypes | nim types |
|--------------------|------------|
| char | cchar |
| unsigned char | cuchar |
| signed char | cschar |
| short | cshort |
| unsigned short | cushort |
| int | cint |
| unsigned int | cuint |
| long | clong |
| unsigned long | culong |
| long long | clonglong |
| unsigned long long | culonglong |
| [const] char* | cstring |
| [const] void * | pointer |
For example,
```nim
type
POINTER_64_INT* = uint
INT8* = cchar
PINT8* = ptr INT8
INT16* = cshort
PINT16* = ptr INT16
INT32* = cint
PINT32* = ptr INT32
INT64* = int64
PINT64* = ptr INT64
UINT8* = cuchar
PUINT8* = ptr UINT8
UINT16* = cushort
PUINT16* = ptr UINT16
```
## Docs requirements
```nim
proc foo(a: int, b: string): int
## Calculate something.
## Params:
## - ``a``: An int.
## - ``b``: An string.
## Returns:
## - Return results.
```
### Whether examples are runnable
If examples are runnable
```nim
proc foo(a: int, b: string): int
## Calculate something.
runnableExamples:
assert foo(12, "ok") == 3
```
Otherwise
```nim
proc foo(a: int, b: string): int
## Calculate something.
## .. code-block:: Nim
## assert foo(12, "ok") == 3
```
## Notes
### Your variable's name can't be as same as modules' name.
## Tests
Use `testament` instead of `unittest`.