Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Function calls and events with named parametersΒ #4254

@pcaversaccio

Description

@pcaversaccio

🧐 Motivation

OpenZeppelin contracts generally optimise for readability, security, and auditability (at least from my perspective). Therefore, I think using Function Calls with Named Parameters provides a huge value-add to the codebase wrt readability and auditability.

πŸ“ Details

Example (ERC20Burnable):

function burnFrom(address account, uint256 amount) public virtual {
    _spendAllowance({owner: account, spender: _msgSender(), amount: amount});
    _burn({account: account, amount: amount});
}

There might be cases where currently the parameter names coincide (e.g. amount or account above), but I would still consider this a value-add wrt clear readability.

Edit: I also suggest using named parameters for events.

Example (ERC20):

event Transfer(address indexed from, address indexed to, uint256 value);

function _mint(address account, uint256 amount) internal virtual {
    require(account != address(0), "ERC20: mint to the zero address");

    _beforeTokenTransfer(address(0), account, amount);

    _totalSupply += amount;
    unchecked {
        // Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
        _balances[account] += amount;
    }
    emit Transfer({from: address(0), to: account, value: amount});

    _afterTokenTransfer(address(0), account, amount);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions