Skip to content

Commit beb5106

Browse files
committed
fix: corrects _ prefixes
1 parent 7f360e6 commit beb5106

16 files changed

+185
-185
lines changed

docs/assembly.rst

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ Solidity language without a compiler change.
4545
pragma solidity >=0.4.16 <0.9.0;
4646
4747
library GetCode {
48-
function at(address _addr) public view returns (bytes memory code) {
48+
function at(address addr) public view returns (bytes memory code) {
4949
assembly {
5050
// retrieve the size of the code, this needs assembly
51-
let size := extcodesize(_addr)
51+
let size := extcodesize(addr)
5252
// allocate output byte array - this could also be done without assembly
5353
// by using code = new bytes(size)
5454
code := mload(0x40)
@@ -57,7 +57,7 @@ Solidity language without a compiler change.
5757
// store length in memory
5858
mstore(code, size)
5959
// actually retrieve the code, this needs assembly
60-
extcodecopy(_addr, add(code, 0x20), 0, size)
60+
extcodecopy(addr, add(code, 0x20), 0, size)
6161
}
6262
}
6363
}
@@ -74,43 +74,43 @@ efficient code, for example:
7474
library VectorSum {
7575
// This function is less efficient because the optimizer currently fails to
7676
// remove the bounds checks in array access.
77-
function sumSolidity(uint[] memory _data) public pure returns (uint sum) {
78-
for (uint i = 0; i < _data.length; ++i)
79-
sum += _data[i];
77+
function sumSolidity(uint[] memory data) public pure returns (uint sum) {
78+
for (uint i = 0; i < data.length; ++i)
79+
sum += data[i];
8080
}
8181
8282
// We know that we only access the array in bounds, so we can avoid the check.
8383
// 0x20 needs to be added to an array because the first slot contains the
8484
// array length.
85-
function sumAsm(uint[] memory _data) public pure returns (uint sum) {
86-
for (uint i = 0; i < _data.length; ++i) {
85+
function sumAsm(uint[] memory data) public pure returns (uint sum) {
86+
for (uint i = 0; i < data.length; ++i) {
8787
assembly {
88-
sum := add(sum, mload(add(add(_data, 0x20), mul(i, 0x20))))
88+
sum := add(sum, mload(add(add(data, 0x20), mul(i, 0x20))))
8989
}
9090
}
9191
}
9292
9393
// Same as above, but accomplish the entire code within inline assembly.
94-
function sumPureAsm(uint[] memory _data) public pure returns (uint sum) {
94+
function sumPureAsm(uint[] memory data) public pure returns (uint sum) {
9595
assembly {
9696
// Load the length (first 32 bytes)
97-
let len := mload(_data)
97+
let len := mload(data)
9898
9999
// Skip over the length field.
100100
//
101101
// Keep temporary variable so it can be incremented in place.
102102
//
103-
// NOTE: incrementing _data would result in an unusable
104-
// _data variable after this assembly block
105-
let data := add(_data, 0x20)
103+
// NOTE: incrementing data would result in an unusable
104+
// data variable after this assembly block
105+
let dataElementLocation := add(data, 0x20)
106106
107107
// Iterate until the bound is not met.
108108
for
109-
{ let end := add(data, mul(len, 0x20)) }
110-
lt(data, end)
111-
{ data := add(data, 0x20) }
109+
{ let end := add(dataElementLocation, mul(len, 0x20)) }
110+
lt(dataElementLocation, end)
111+
{ data := add(dataElementLocation, 0x20) }
112112
{
113-
sum := add(sum, mload(data))
113+
sum := add(sum, mload(dataElementLocation))
114114
}
115115
}
116116
}

docs/common-patterns.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,27 +163,27 @@ restrictions highly readable.
163163
// prepend a check that only passes
164164
// if the function is called from
165165
// a certain address.
166-
modifier onlyBy(address _account)
166+
modifier onlyBy(address account)
167167
{
168-
if (msg.sender != _account)
168+
if (msg.sender != account)
169169
revert Unauthorized();
170170
// Do not forget the "_;"! It will
171171
// be replaced by the actual function
172172
// body when the modifier is used.
173173
_;
174174
}
175175
176-
/// Make `_newOwner` the new owner of this
176+
/// Make `newOwner` the new owner of this
177177
/// contract.
178-
function changeOwner(address _newOwner)
178+
function changeOwner(address newOwner)
179179
public
180180
onlyBy(owner)
181181
{
182-
owner = _newOwner;
182+
owner = newOwner;
183183
}
184184
185-
modifier onlyAfter(uint _time) {
186-
if (block.timestamp < _time)
185+
modifier onlyAfter(uint time) {
186+
if (block.timestamp < time)
187187
revert TooEarly();
188188
_;
189189
}
@@ -205,21 +205,21 @@ restrictions highly readable.
205205
// refunded, but only after the function body.
206206
// This was dangerous before Solidity version 0.4.0,
207207
// where it was possible to skip the part after `_;`.
208-
modifier costs(uint _amount) {
209-
if (msg.value < _amount)
208+
modifier costs(uint amount) {
209+
if (msg.value < amount)
210210
revert NotEnoughEther();
211211
212212
_;
213-
if (msg.value > _amount)
214-
payable(msg.sender).transfer(msg.value - _amount);
213+
if (msg.value > amount)
214+
payable(msg.sender).transfer(msg.value - amount);
215215
}
216216
217-
function forceOwnerChange(address _newOwner)
217+
function forceOwnerChange(address newOwner)
218218
public
219219
payable
220220
costs(200 ether)
221221
{
222-
owner = _newOwner;
222+
owner = newOwner;
223223
// just some example condition
224224
if (uint160(owner) & 0 == 1)
225225
// This did not refund for Solidity
@@ -315,8 +315,8 @@ function finishes.
315315
316316
uint public creationTime = block.timestamp;
317317
318-
modifier atStage(Stages _stage) {
319-
if (stage != _stage)
318+
modifier atStage(Stages stage_) {
319+
if (stage != stage_)
320320
revert FunctionInvalidAtThisStage();
321321
_;
322322
}

docs/contracts/constant-state-variables.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ Not all types for constants and immutables are implemented at this time. The onl
4141
uint immutable maxBalance;
4242
address immutable owner = msg.sender;
4343
44-
constructor(uint _decimals, address _reference) {
45-
decimals = _decimals;
44+
constructor(uint decimals_, address ref) {
45+
decimals = decimals_;
4646
// Assignments to immutables can even access the environment.
47-
maxBalance = _reference.balance;
47+
maxBalance = ref.balance;
4848
}
4949
50-
function isBalanceTooHigh(address _other) public view returns (bool) {
51-
return _other.balance > maxBalance;
50+
function isBalanceTooHigh(address other) public view returns (bool) {
51+
return other.balance > maxBalance;
5252
}
5353
}
5454

docs/contracts/creating-contracts.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ This means that cyclic creation dependencies are impossible.
4848
4949
// This is the constructor which registers the
5050
// creator and the assigned name.
51-
constructor(bytes32 _name) {
51+
constructor(bytes32 name_) {
5252
// State variables are accessed via their name
5353
// and not via e.g. `this.owner`. Functions can
5454
// be accessed directly or through `this.f`,
@@ -65,7 +65,7 @@ This means that cyclic creation dependencies are impossible.
6565
// no real way to verify that.
6666
// This does not create a new contract.
6767
creator = TokenCreator(msg.sender);
68-
name = _name;
68+
name = name_;
6969
}
7070
7171
function changeName(bytes32 newName) public {

docs/contracts/events.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ four indexed arguments rather than three.
8080
8181
contract ClientReceipt {
8282
event Deposit(
83-
address indexed _from,
84-
bytes32 indexed _id,
85-
uint _value
83+
address indexed from,
84+
bytes32 indexed id,
85+
uint value
8686
);
8787
88-
function deposit(bytes32 _id) public payable {
88+
function deposit(bytes32 id) public payable {
8989
// Events are emitted using `emit`, followed by
9090
// the name of the event and the arguments
9191
// (if any) in parentheses. Any such invocation
9292
// (even deeply nested) can be detected from
9393
// the JavaScript API by filtering for `Deposit`.
94-
emit Deposit(msg.sender, _id, msg.value);
94+
emit Deposit(msg.sender, id, msg.value);
9595
}
9696
}
9797
@@ -126,9 +126,9 @@ The output of the above looks like the following (trimmed):
126126
127127
{
128128
"returnValues": {
129-
"_from": "0x1111…FFFFCCCC",
130-
"_id": "0x50…sd5adb20",
131-
"_value": "0x420042"
129+
"from": "0x1111…FFFFCCCC",
130+
"id": "0x50…sd5adb20",
131+
"value": "0x420042"
132132
},
133133
"raw": {
134134
"data": "0x7f…91385",

docs/contracts/function-modifiers.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ if they are marked ``virtual``. For details, please see
7272
registeredAddresses[msg.sender] = true;
7373
}
7474
75-
function changePrice(uint _price) public onlyOwner {
76-
price = _price;
75+
function changePrice(uint price_) public onlyOwner {
76+
price = price_;
7777
}
7878
}
7979

docs/contracts/functions.rst

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ that call them, similar to internal library functions.
1717
// SPDX-License-Identifier: GPL-3.0
1818
pragma solidity >=0.7.1 <0.9.0;
1919
20-
function sum(uint[] memory _arr) pure returns (uint s) {
21-
for (uint i = 0; i < _arr.length; i++)
22-
s += _arr[i];
20+
function sum(uint[] memory arr) pure returns (uint s) {
21+
for (uint i = 0; i < arr.length; i++)
22+
s += arr[i];
2323
}
2424
2525
contract ArrayExample {
2626
bool found;
27-
function f(uint[] memory _arr) public {
27+
function f(uint[] memory arr) public {
2828
// This calls the free function internally.
2929
// The compiler will add its code to the contract.
30-
uint s = sum(_arr);
30+
uint s = sum(arr);
3131
require(s >= 10);
3232
found = true;
3333
}
@@ -65,8 +65,8 @@ with two integers, you would use something like the following:
6565
6666
contract Simple {
6767
uint sum;
68-
function taker(uint _a, uint _b) public {
69-
sum = _a + _b;
68+
function taker(uint a, uint b) public {
69+
sum = a + b;
7070
}
7171
}
7272
@@ -99,13 +99,13 @@ two integers passed as function parameters, then you use something like:
9999
pragma solidity >=0.4.16 <0.9.0;
100100
101101
contract Simple {
102-
function arithmetic(uint _a, uint _b)
102+
function arithmetic(uint a, uint b)
103103
public
104104
pure
105105
returns (uint sum, uint product)
106106
{
107-
sum = _a + _b;
108-
product = _a * _b;
107+
sum = a + b;
108+
product = a * b;
109109
}
110110
}
111111
@@ -126,12 +126,12 @@ statement:
126126
pragma solidity >=0.4.16 <0.9.0;
127127
128128
contract Simple {
129-
function arithmetic(uint _a, uint _b)
129+
function arithmetic(uint a, uint b)
130130
public
131131
pure
132132
returns (uint sum, uint product)
133133
{
134-
return (_a + _b, _a * _b);
134+
return (a + b, a * b);
135135
}
136136
}
137137
@@ -362,7 +362,7 @@ Fallback Function
362362
-----------------
363363

364364
A contract can have at most one ``fallback`` function, declared using either ``fallback () external [payable]``
365-
or ``fallback (bytes calldata _input) external [payable] returns (bytes memory _output)``
365+
or ``fallback (bytes calldata input) external [payable] returns (bytes memory output)``
366366
(both without the ``function`` keyword).
367367
This function must have ``external`` visibility. A fallback function can be virtual, can override
368368
and can have modifiers.
@@ -373,8 +373,8 @@ all and there is no :ref:`receive Ether function <receive-ether-function>`.
373373
The fallback function always receives data, but in order to also receive Ether
374374
it must be marked ``payable``.
375375

376-
If the version with parameters is used, ``_input`` will contain the full data sent to the contract
377-
(equal to ``msg.data``) and can return data in ``_output``. The returned data will not be
376+
If the version with parameters is used, ``input`` will contain the full data sent to the contract
377+
(equal to ``msg.data``) and can return data in ``output``. The returned data will not be
378378
ABI-encoded. Instead it will be returned without modifications (not even padding).
379379

380380
In the worst case, if a payable fallback function is also used in
@@ -397,7 +397,7 @@ operations as long as there is enough gas passed on to it.
397397
for the function selector and then
398398
you can use ``abi.decode`` together with the array slice syntax to
399399
decode ABI-encoded data:
400-
``(c, d) = abi.decode(_input[4:], (uint256, uint256));``
400+
``(c, d) = abi.decode(input[4:], (uint256, uint256));``
401401
Note that this should only be used as a last resort and
402402
proper functions should be used instead.
403403

@@ -486,13 +486,13 @@ The following example shows overloading of the function
486486
pragma solidity >=0.4.16 <0.9.0;
487487
488488
contract A {
489-
function f(uint _in) public pure returns (uint out) {
490-
out = _in;
489+
function f(uint value) public pure returns (uint out) {
490+
out = value;
491491
}
492492
493-
function f(uint _in, bool _really) public pure returns (uint out) {
494-
if (_really)
495-
out = _in;
493+
function f(uint value, bool really) public pure returns (uint out) {
494+
if (really)
495+
out = value;
496496
}
497497
}
498498
@@ -506,12 +506,12 @@ externally visible functions differ by their Solidity types but not by their ext
506506
507507
// This will not compile
508508
contract A {
509-
function f(B _in) public pure returns (B out) {
510-
out = _in;
509+
function f(B value) public pure returns (B out) {
510+
out = value;
511511
}
512512
513-
function f(address _in) public pure returns (address out) {
514-
out = _in;
513+
function f(address value) public pure returns (address out) {
514+
out = value;
515515
}
516516
}
517517
@@ -539,12 +539,12 @@ candidate, resolution fails.
539539
pragma solidity >=0.4.16 <0.9.0;
540540
541541
contract A {
542-
function f(uint8 _in) public pure returns (uint8 out) {
543-
out = _in;
542+
function f(uint8 val) public pure returns (uint8 out) {
543+
out = val;
544544
}
545545
546-
function f(uint256 _in) public pure returns (uint256 out) {
547-
out = _in;
546+
function f(uint256 val) public pure returns (uint256 out) {
547+
out = val;
548548
}
549549
}
550550

0 commit comments

Comments
 (0)