Updated NEP 1 : Style Guide for Nim Code (markdown)
This commit is contained in:
parent
93d4fa0158
commit
54b8faabe9
|
@ -13,7 +13,6 @@ sense in certain contexts. Furthermore, just as
|
||||||
[Python's style guide](http://legacy.python.org/dev/peps/pep-0008/) changes
|
[Python's style guide](http://legacy.python.org/dev/peps/pep-0008/) changes
|
||||||
over time, this style guide will too.
|
over time, this style guide will too.
|
||||||
|
|
||||||
<br></br>
|
|
||||||
Style Guidelines
|
Style Guidelines
|
||||||
================
|
================
|
||||||
### Spacing and Whitespace Conventions ###
|
### Spacing and Whitespace Conventions ###
|
||||||
|
@ -43,7 +42,6 @@ Style Guidelines
|
||||||
LongLongPtr* = ptr LongLong
|
LongLongPtr* = ptr LongLong
|
||||||
```
|
```
|
||||||
|
|
||||||
<br></br>
|
|
||||||
### Naming Conventions ###
|
### Naming Conventions ###
|
||||||
|
|
||||||
Note: While the rules outlined below are the *current* naming conventions,
|
Note: While the rules outlined below are the *current* naming conventions,
|
||||||
|
@ -55,12 +53,12 @@ changed, there are many places in the standard library which still use this
|
||||||
convention. Such style remains in place purely for legacy reasons, and will
|
convention. Such style remains in place purely for legacy reasons, and will
|
||||||
be changed in the future.
|
be changed in the future.
|
||||||
|
|
||||||
- Type identifiers should be in CamelCase. All other identifiers should be in
|
- Type identifiers should be in camelCase. All other identifiers should be in
|
||||||
pascalCase with the exception of constants which **may** use CamelCase but
|
CamelCase with the exception of constants which **may** use PascalCase but
|
||||||
are not required to.
|
are not required to.
|
||||||
```nimrod
|
```nimrod
|
||||||
const aConstant = 42
|
const aConstant = 42
|
||||||
const FOO_BAR = 4.2
|
const FooBar = 4.2
|
||||||
|
|
||||||
var aVariable = "Meep"
|
var aVariable = "Meep"
|
||||||
|
|
||||||
|
@ -92,9 +90,15 @@ be changed in the future.
|
||||||
pcFile
|
pcFile
|
||||||
pcLinkToFile
|
pcLinkToFile
|
||||||
```
|
```
|
||||||
Non-pure enum values should use pascalCase whereas pure enum values should use CamelCase.
|
Non-pure enum values should use camelCase whereas pure enum values should use PascalCase.
|
||||||
|
```nimrod
|
||||||
|
type PathComponent {.pure.} = enum
|
||||||
|
Dir
|
||||||
|
LinkToDir
|
||||||
|
File
|
||||||
|
LinkToFile
|
||||||
|
```
|
||||||
|
|
||||||
<br></br>
|
|
||||||
### Coding Conventions ###
|
### Coding Conventions ###
|
||||||
- The 'return' statement should only be used when it's control-flow properties
|
- The 'return' statement should only be used when it's control-flow properties
|
||||||
are required. Use a procedures implicit 'result' variable instead. This improves
|
are required. Use a procedures implicit 'result' variable instead. This improves
|
||||||
|
@ -111,7 +115,7 @@ be changed in the future.
|
||||||
variables remain immutable, and gives those who read the code a better idea
|
variables remain immutable, and gives those who read the code a better idea
|
||||||
of the code's purpose.
|
of the code's purpose.
|
||||||
|
|
||||||
<br></br>
|
|
||||||
### Conventions for multi-line statements and expressions ###
|
### Conventions for multi-line statements and expressions ###
|
||||||
- Any tuple type declarations that are longer than one line should use the
|
- Any tuple type declarations that are longer than one line should use the
|
||||||
regular object type layout instead. This enhances the readability of the
|
regular object type layout instead. This enhances the readability of the
|
||||||
|
@ -132,7 +136,7 @@ be changed in the future.
|
||||||
```nimrod
|
```nimrod
|
||||||
type
|
type
|
||||||
EventCallback = proc (
|
EventCallback = proc (
|
||||||
timeRecieved: TTime
|
timeRecieved: Time
|
||||||
errorCode: int
|
errorCode: int
|
||||||
event: Event
|
event: Event
|
||||||
)
|
)
|
||||||
|
@ -146,7 +150,7 @@ be changed in the future.
|
||||||
consider renaming your procedure).
|
consider renaming your procedure).
|
||||||
```nimrod
|
```nimrod
|
||||||
proc lotsOfArguments(argOne: string, argTwo: int, argThree:float
|
proc lotsOfArguments(argOne: string, argTwo: int, argThree:float
|
||||||
argFour: proc(), argFive:bool): int
|
argFour: proc(), argFive: bool): int
|
||||||
```
|
```
|
||||||
|
|
||||||
- Multi-line procedure calls should either have one argument per line
|
- Multi-line procedure calls should either have one argument per line
|
||||||
|
@ -165,8 +169,8 @@ be changed in the future.
|
||||||
watchSubdir.WinBool,
|
watchSubdir.WinBool,
|
||||||
filterFlags,
|
filterFlags,
|
||||||
cast[ptr dword](nil),
|
cast[ptr dword](nil),
|
||||||
cast[POverlapped](ol),
|
cast[Overlapped](ol),
|
||||||
cast[LPOverlappedCompletionRoutine](nil)
|
cast[OverlappedCompletionRoutine](nil)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,4 +178,4 @@ be changed in the future.
|
||||||
# Best suited for 'simple' procedure calls
|
# Best suited for 'simple' procedure calls
|
||||||
startProcess(nimExecutable, currentDirectory, compilerArguments
|
startProcess(nimExecutable, currentDirectory, compilerArguments
|
||||||
environment, processOptions)
|
environment, processOptions)
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue