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
|
||||
over time, this style guide will too.
|
||||
|
||||
<br></br>
|
||||
Style Guidelines
|
||||
================
|
||||
### Spacing and Whitespace Conventions ###
|
||||
|
@ -43,7 +42,6 @@ Style Guidelines
|
|||
LongLongPtr* = ptr LongLong
|
||||
```
|
||||
|
||||
<br></br>
|
||||
### 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
|
||||
be changed in the future.
|
||||
|
||||
- Type identifiers should be in CamelCase. All other identifiers should be in
|
||||
pascalCase with the exception of constants which **may** use CamelCase but
|
||||
- Type identifiers should be in camelCase. All other identifiers should be in
|
||||
CamelCase with the exception of constants which **may** use PascalCase but
|
||||
are not required to.
|
||||
```nimrod
|
||||
const aConstant = 42
|
||||
const FOO_BAR = 4.2
|
||||
const FooBar = 4.2
|
||||
|
||||
var aVariable = "Meep"
|
||||
|
||||
|
@ -92,9 +90,15 @@ be changed in the future.
|
|||
pcFile
|
||||
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 ###
|
||||
- The 'return' statement should only be used when it's control-flow properties
|
||||
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
|
||||
of the code's purpose.
|
||||
|
||||
<br></br>
|
||||
|
||||
### Conventions for multi-line statements and expressions ###
|
||||
- Any tuple type declarations that are longer than one line should use the
|
||||
regular object type layout instead. This enhances the readability of the
|
||||
|
@ -132,7 +136,7 @@ be changed in the future.
|
|||
```nimrod
|
||||
type
|
||||
EventCallback = proc (
|
||||
timeRecieved: TTime
|
||||
timeRecieved: Time
|
||||
errorCode: int
|
||||
event: Event
|
||||
)
|
||||
|
@ -146,7 +150,7 @@ be changed in the future.
|
|||
consider renaming your procedure).
|
||||
```nimrod
|
||||
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
|
||||
|
@ -165,8 +169,8 @@ be changed in the future.
|
|||
watchSubdir.WinBool,
|
||||
filterFlags,
|
||||
cast[ptr dword](nil),
|
||||
cast[POverlapped](ol),
|
||||
cast[LPOverlappedCompletionRoutine](nil)
|
||||
cast[Overlapped](ol),
|
||||
cast[OverlappedCompletionRoutine](nil)
|
||||
)
|
||||
|
||||
|
||||
|
@ -174,4 +178,4 @@ be changed in the future.
|
|||
# Best suited for 'simple' procedure calls
|
||||
startProcess(nimExecutable, currentDirectory, compilerArguments
|
||||
environment, processOptions)
|
||||
```
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue