A question about conventions

qqwyqqwy Posts: 15Member
There are two 'rules' I see in a lot of Solidity snippets:

1) Function parameters receive an underscore as first character in their name.
2) When accessing contract state variables, we do not use `this.` in front of the name, although we could.

I am wondering why these conventions exist, and how strict they are enforced (Are there tools that require you to use this format?)

Personally, because of the influence of other languages and because of referential transparency, I would:

- Only start a parameter with an underscore if it is a parameter that is actually unused in the function. This is an influence from functional programming languages but it it widely used in many languages nowadays, either enforced by the language itself or by linters; giving you a warning if you try to access a variable that starts with a `_`.

- Always use `this.` when referencing internal state, because it makes it more clear that the thing you are using lives outside the current function scope. In other words, using `this.` makes it more explicit that you are mutating the contract's state and thus makes your code more readable, as well as making it harder to make mistakes with name shadowing.

Why do these two conventions exist? Is there any problem with not following them?
Sign In or Register to comment.