Add more details to objconstr

This commit is contained in:
Tanguy 2022-05-19 11:47:28 +02:00
parent 0636df2805
commit 29c1bc399f
No known key found for this signature in database
GPG Key ID: 7DD8EC6B6CE6C45E
5 changed files with 6 additions and 4 deletions

View File

@ -27,6 +27,6 @@ func f*(): Result[void, cstring]
func parse(): Type {.raises: [Defect, ParseError]}
```
See also [Result](libraries.result.md) for more recommendations about `Result`.
See also [Result](libraries.results.md) for more recommendations about `Result`.
See also [Error handling helpers](https://github.com/status-im/nim-stew/pull/26) in stew that may change some of these guidelines.

View File

@ -17,5 +17,5 @@ Avoid `string` for binary data. If stdlib returns strings, [convert](https://git
### Practical notes
* [stew](https://github.com/status-im/nim-stew) contains helpers for dealing with bytes and strings
* [stew](libraries.stew.md) contains helpers for dealing with bytes and strings

View File

@ -15,6 +15,6 @@ Don't cast pointers to `int`.
* When comparing lengths to unsigned integers, convert the length to unsigned
* Pointers may overflow `int` when used for arithmetic
* An alternative to `int` for non-negative integers such as lengths is `Natural`
* `Natural` is a `range` type and therefore [unreliable](#range) - it generally avoids the worst problems owing to its simplicity but may require additional casts to work around bugs
* `Natural` is a `range` type and therefore [unreliable](language.range.md) - it generally avoids the worst problems owing to its simplicity but may require additional casts to work around bugs
* Better models length, but is not used by `len`

View File

@ -30,8 +30,10 @@ func init(T: type (ref Xxx), a, b: int ): T = ...
### Cons
* Sometimes inefficient compared to updating an existing `var` instance, since all fields must be re-initialized
* Compared to `func newXxx()`, `func new(T: type Xxx)` will be a generic procedure, which can cause issues. See [Import, export](language.import.md)
### Practical notes
* The default, 0-initialized state of the object often gets constructed in the language - avoiding a requirement that a magic `init` function be called makes the type more ergonomic to use
* Avoid using `result` or `var instance: Type` which disable several compiler diagnostics
* When using inheritance, `func new(T: type Xxx)` will also bind to any type inheriting from Xxx

View File

@ -38,5 +38,5 @@ Of the three:
Multiple security issues, `nil` reference crashes and wrong-init-order issues have been linked to the use of `result` and lack of assignment in branches.
In general, the use of accumulation-style initialization is discouraged unless made necessary by the data type - see [Variable initialization](#variable-initialization)
In general, the use of accumulation-style initialization is discouraged unless made necessary by the data type - see [Variable initialization](language.varinit.md)