From 29c1bc399f72fadf917a816b8683aee0ce91f57d Mon Sep 17 00:00:00 2001 From: Tanguy Date: Thu, 19 May 2022 11:47:28 +0200 Subject: [PATCH] Add more details to objconstr --- src/errors.result.md | 2 +- src/language.binary.md | 2 +- src/language.integers.md | 2 +- src/language.objconstr.md | 2 ++ src/language.result.md | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/errors.result.md b/src/errors.result.md index 1dec442..20438fd 100644 --- a/src/errors.result.md +++ b/src/errors.result.md @@ -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. diff --git a/src/language.binary.md b/src/language.binary.md index a1aed15..613b6c8 100644 --- a/src/language.binary.md +++ b/src/language.binary.md @@ -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 diff --git a/src/language.integers.md b/src/language.integers.md index f6b536c..61c07f4 100644 --- a/src/language.integers.md +++ b/src/language.integers.md @@ -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` diff --git a/src/language.objconstr.md b/src/language.objconstr.md index adbee0a..d8030c7 100644 --- a/src/language.objconstr.md +++ b/src/language.objconstr.md @@ -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 diff --git a/src/language.result.md b/src/language.result.md index 0af3acd..f61727a 100644 --- a/src/language.result.md +++ b/src/language.result.md @@ -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)