Skip to content

Commit

Permalink
Precise event naming convention (#14)
Browse files Browse the repository at this point in the history
* precise event naming convention

* make event format clearer

* split events section

* fix syntax
  • Loading branch information
xenoliss authored Apr 24, 2024
1 parent 1b4af1a commit 4c35c62
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,40 @@ Custom errors are in some cases more gas efficient and allow passing useful info

For example, `InsufficientBalance`.

#### 3. Event names should be past tense.
#### 3. Events

For example, `UpdatedOwner` not `UpdateOwner`.
##### A. Events names should be past tense.

Events should track things that _happened_ and so should be past tense. Using past tense also helps avoid naming collisions with structs or functions.

We are aware this does not follow precedent from early ERCs, like [ERC-20](https://eips.ethereum.org/EIPS/eip-20). However it does align with some more recent high profile Solidity, e.g. [1](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/976a3d53624849ecaef1231019d2052a16a39ce4/contracts/access/Ownable.sol#L33), [2](https://github.com/aave/aave-v3-core/blob/724a9ef43adf139437ba87dcbab63462394d4601/contracts/interfaces/IAaveOracle.sol#L25-L31), [3](https://github.com/ProjectOpenSea/seaport/blob/1d12e33b71b6988cbbe955373ddbc40a87bd5b16/contracts/zones/interfaces/PausableZoneEventsAndErrors.sol#L25-L41).

NO:

```solidity
event OwnerUpdate(address newOwner);
```

YES:

```solidity
event OwnerUpdated(address newOwner);
```

##### B. Prefer `SubjectVerb` naming format.

NO:

```solidity
event UpdatedOwner(address newOwner);
```

YES:

```solidity
event OwnerUpdated(address newOwner);
```

#### 4. Avoid using assembly.

Assembly code is hard to read and audit. We should avoid it unless the gas savings are very consequential, e.g. > 25%.
Expand Down

0 comments on commit 4c35c62

Please sign in to comment.