Skip to content

Commit

Permalink
feat: documentation chapter (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
julio4 authored Nov 30, 2023
1 parent fec6527 commit bf697bf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Summary
- [Events](./ch00/basics/events.md)
- [Storing Custom Types](./ch00/basics/storing-custom-types.md)
- [Custom types in entrypoints](./ch00/basics/custom-types-in-entrypoints.md)
- [Documentation](./ch00/basics/documentation.md)
- [Deploy and interact with contracts](./ch00/interacting/interacting.md)
- [Contract interfaces and Traits generation](./ch00/interacting/interfaces-traits.md)
- [Calling other contracts](./ch00/interacting/calling_other_contracts.md)
Expand Down
33 changes: 33 additions & 0 deletions src/ch00/basics/documentation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Documentation

It's important to take the time to document your code. It will helps developers and users to understand the contract and its functionalities.

In Cairo, you can add comments with `//`.

### Contract Interface:

In smart contracts, you will often have a trait that defines the contract's interface (with `#[starknet::interface]`).
This is the perfect place to include detailed documentation explaining the purpose and functionality of the contract entry points. You can follow this template:

```rust
#[starknet::interface]
trait IContract<TContractState> {
/// High-level description of the function
///
/// # Arguments
/// * `arg_1` - Description of the argument
/// * `arg_n` - ...
///
/// # Returns
/// High-level description of the return value
fn do_something(ref self: TContractState, arg_1: T_arg_1) -> T_return;
}
```

Keep in mind that this should not describe the implementation details of the function, but rather the high-level purpose and functionality of the contract from the perspective of a user.

### Implementation Details:

When writing the logic of the contract, you can add comments to describe the technical implementation details of the functions.

> Avoid over-commenting: Comments should provide additional value and clarity.

0 comments on commit bf697bf

Please sign in to comment.