Skip to content

Commit

Permalink
Merge pull request #3545 from dfinity/candid-deprecated-fields
Browse files Browse the repository at this point in the history
add: candid deprecated fields best practices
  • Loading branch information
jessiemongeon1 authored Sep 27, 2024
2 parents acaf519 + 87fa753 commit 21f632a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/developer-docs/smart-contracts/candid/candid-concepts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ Regardless of the host language you use, it is important to know the mapping bet

## Best practices

### Use descriptive type names

It is recommended to use Candid records with descriptive names for types:

```candid
Expand All @@ -319,3 +321,24 @@ type Recycler =
nick: text;
};
```

### Deprecating fields

To deprecate a Candid field, you can update the field's type to `opt empty`, indicating the field is not used:

```
record {
first_name : text; middle_name : opt empty; second_name : text; score : nat; country : text
}
```

However, it is best practice to mark a field as `reserved` to prevent future developers from using the field in an unexpected manner:

```
record {
first_name : text; middle_name : reserved; second_name : text; score : nat; country : text
}
```

For more information, refer to the blog post on [Candid for engineers](https://mmapped.blog/posts/20-candid-for-engineers#faq).

0 comments on commit 21f632a

Please sign in to comment.