This question already has an answer here:

For instance, both ERC-721 and ERC-725 have underscores(_) before any function parameter.

I understand that normally their goal is to avoid variable overloading. However, what is the rationale for the ERC interfaces? Is is that in this way we make sure that whatever variable names the implementor will choose, there are no collisions?

marked as duplicate by eth Nov 10 '18 at 23:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Using underscores in front of variable names is simply due to convention. Some languages encourage using underscore for private variables so it's easy to distinguish between private and public variables. Solidity does the same - using underscores before private (inside a function) variables makes them easy to spot.

I'm not sure what you mean with avoiding variable overloading in this context.

  • Oh I meant exactly that: to distinguish between local variables in a function and global ones. Thanks! – Paul Berg Nov 10 '18 at 10:32

It's a convention in Solidity to declare local variables names with the first letter "_". I personally prefer to do the same for internal functions.

For instance:

function _decrementBalance(uint _index, uint _value) internal {
    uint oldBalance = accountBalances[_index];
    uint newBalance = oldBalance.sub(_value);
    accountBalances[_index] = newBalance;

This makes reading a contract code much easier.

Not the answer you're looking for? Browse other questions tagged or ask your own question.