Skip to content

Commit 49f06da

Browse files
committed
fix: remove lower_case_with_underscores and Capitalized_Words_With_Underscores from code examples
1 parent daad9a4 commit 49f06da

File tree

6 files changed

+58
-60
lines changed

6 files changed

+58
-60
lines changed

docs/050-breaking-changes.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ For most of the topics the compiler will provide suggestions.
8989

9090
* Explicit data location for all variables of struct, array or mapping types is
9191
now mandatory. This is also applied to function parameters and return
92-
variables. For example, change ``uint[] x = m_x`` to ``uint[] storage x =
93-
m_x``, and ``function f(uint[][] x)`` to ``function f(uint[][] memory x)``
92+
variables. For example, change ``uint[] x = z`` to ``uint[] storage x =
93+
z``, and ``function f(uint[][] x)`` to ``function f(uint[][] memory x)``
9494
where ``memory`` is the data location and might be replaced by ``storage`` or
9595
``calldata`` accordingly. Note that ``external`` functions require
9696
parameters with a data location of ``calldata``.
@@ -483,7 +483,7 @@ New version:
483483
return data;
484484
}
485485
486-
using address_make_payable for address;
486+
using AddressMakePayable for address;
487487
// Data location for 'arr' must be specified
488488
function g(uint[] memory /* arr */, bytes8 x, OtherContract otherContract, address unknownContract) public payable {
489489
// 'otherContract.transfer' is not provided.
@@ -500,7 +500,7 @@ New version:
500500
// 'address payable' should be used whenever possible.
501501
// To increase clarity, we suggest the use of a library for
502502
// the conversion (provided after the contract in this example).
503-
address payable addr = unknownContract.make_payable();
503+
address payable addr = unknownContract.makePayable();
504504
require(addr.send(1 ether));
505505
506506
// Since uint32 (4 bytes) is smaller than bytes8 (8 bytes),
@@ -516,8 +516,8 @@ New version:
516516
517517
// We can define a library for explicitly converting ``address``
518518
// to ``address payable`` as a workaround.
519-
library address_make_payable {
520-
function make_payable(address x) internal pure returns (address payable) {
519+
library AddressMakePayable {
520+
function makePayable(address x) internal pure returns (address payable) {
521521
return address(uint160(x));
522522
}
523523
}

docs/assembly.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,19 @@ 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 o_code) {
48+
function at(address _addr) public view returns (bytes memory code) {
4949
assembly {
5050
// retrieve the size of the code, this needs assembly
5151
let size := extcodesize(_addr)
5252
// allocate output byte array - this could also be done without assembly
53-
// by using o_code = new bytes(size)
54-
o_code := mload(0x40)
53+
// by using code = new bytes(size)
54+
code := mload(0x40)
5555
// new "memory end" including padding
56-
mstore(0x40, add(o_code, and(add(add(size, 0x20), 0x1f), not(0x1f))))
56+
mstore(0x40, add(code, and(add(add(size, 0x20), 0x1f), not(0x1f))))
5757
// store length in memory
58-
mstore(o_code, size)
58+
mstore(code, size)
5959
// actually retrieve the code, this needs assembly
60-
extcodecopy(_addr, add(o_code, 0x20), 0, size)
60+
extcodecopy(_addr, add(code, 0x20), 0, size)
6161
}
6262
}
6363
}

docs/contracts/functions.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ two integers passed as function parameters, then you use something like:
102102
function arithmetic(uint _a, uint _b)
103103
public
104104
pure
105-
returns (uint o_sum, uint o_product)
105+
returns (uint sum, uint product)
106106
{
107-
o_sum = _a + _b;
108-
o_product = _a * _b;
107+
sum = _a + _b;
108+
product = _a * _b;
109109
}
110110
}
111111
@@ -129,7 +129,7 @@ statement:
129129
function arithmetic(uint _a, uint _b)
130130
public
131131
pure
132-
returns (uint o_sum, uint o_product)
132+
returns (uint sum, uint product)
133133
{
134134
return (_a + _b, _a * _b);
135135
}

docs/style-guide.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ Yes:
204204

205205
.. code-block:: solidity
206206
207-
thisIsALongNestedMapping[being][set][to_some_value] = someFunction(
207+
thisIsALongNestedMapping[being][set][toSomeValue] = someFunction(
208208
argument1,
209209
argument2,
210210
argument3,
@@ -215,7 +215,7 @@ No:
215215

216216
.. code-block:: solidity
217217
218-
thisIsALongNestedMapping[being][set][to_some_value] = someFunction(argument1,
218+
thisIsALongNestedMapping[being][set][toSomeValue] = someFunction(argument1,
219219
argument2,
220220
argument3,
221221
argument4);
@@ -439,15 +439,15 @@ Yes:
439439
440440
x = 1;
441441
y = 2;
442-
long_variable = 3;
442+
longVariable = 3;
443443
444444
No:
445445

446446
.. code-block:: solidity
447447
448-
x = 1;
449-
y = 2;
450-
long_variable = 3;
448+
x = 1;
449+
y = 2;
450+
longVariable = 3;
451451
452452
Don't include a whitespace in the receive and fallback functions:
453453

@@ -1092,12 +1092,10 @@ naming styles.
10921092
* ``b`` (single lowercase letter)
10931093
* ``B`` (single uppercase letter)
10941094
* ``lowercase``
1095-
* ``lower_case_with_underscores``
10961095
* ``UPPERCASE``
10971096
* ``UPPER_CASE_WITH_UNDERSCORES``
10981097
* ``CapitalizedWords`` (or CapWords)
10991098
* ``mixedCase`` (differs from CapitalizedWords by initial lowercase character!)
1100-
* ``Capitalized_Words_With_Underscores``
11011099

11021100
.. note:: When using initialisms in CapWords, capitalize all the letters of the initialisms. Thus HTTPServerError is better than HttpServerError. When using initialisms in mixedCase, capitalize all the letters of the initialisms, except keep the first one lower case if it is the beginning of the name. Thus xmlHTTPRequest is better than XMLHTTPRequest.
11031101

@@ -1256,7 +1254,7 @@ Enums, in the style of simple type declarations, should be named using the CapWo
12561254
Avoiding Naming Collisions
12571255
==========================
12581256

1259-
* ``single_trailing_underscore_``
1257+
* ``singleTrailingUnderscore_``
12601258

12611259
This convention is suggested when the desired name collides with that of a
12621260
built-in or otherwise reserved name.

docs/types/mapping-types.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,22 +166,22 @@ the ``sum`` function iterates over to sum all the values.
166166
return self.data[key].keyIndex > 0;
167167
}
168168
169-
function iterate_start(itmap storage self) internal view returns (uint keyIndex) {
170-
return iterate_next(self, type(uint).max);
169+
function iterateStart(itmap storage self) internal view returns (uint keyIndex) {
170+
return iterateNext(self, type(uint).max);
171171
}
172172
173-
function iterate_valid(itmap storage self, uint keyIndex) internal view returns (bool) {
173+
function iterateValid(itmap storage self, uint keyIndex) internal view returns (bool) {
174174
return keyIndex < self.keys.length;
175175
}
176176
177-
function iterate_next(itmap storage self, uint keyIndex) internal view returns (uint r_keyIndex) {
177+
function iterateNext(itmap storage self, uint keyIndex) internal view returns (uint r_keyIndex) {
178178
keyIndex++;
179179
while (keyIndex < self.keys.length && self.keys[keyIndex].deleted)
180180
keyIndex++;
181181
return keyIndex;
182182
}
183183
184-
function iterate_get(itmap storage self, uint keyIndex) internal view returns (uint key, uint value) {
184+
function iterateGet(itmap storage self, uint keyIndex) internal view returns (uint key, uint value) {
185185
key = self.keys[keyIndex].key;
186186
value = self.data[key].value;
187187
}
@@ -206,11 +206,11 @@ the ``sum`` function iterates over to sum all the values.
206206
// Computes the sum of all stored data.
207207
function sum() public view returns (uint s) {
208208
for (
209-
uint i = data.iterate_start();
210-
data.iterate_valid(i);
211-
i = data.iterate_next(i)
209+
uint i = data.iterateStart();
210+
data.iterateValid(i);
211+
i = data.iterateNext(i)
212212
) {
213-
(, uint value) = data.iterate_get(i);
213+
(, uint value) = data.iterateGet(i);
214214
s += value;
215215
}
216216
}

docs/types/reference-types.rst

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ If you want to use string parameters or other types that are not implicitly conv
190190
contract C {
191191
string s = "Storage";
192192
function f(bytes calldata bc, string memory sm, bytes16 b) public view {
193-
string memory concat_string = string.concat(s, string(bc), "Literal", sm);
194-
assert((bytes(s).length + bc.length + 7 + bytes(sm).length) == bytes(concat_string).length);
193+
string memory concatString = string.concat(s, string(bc), "Literal", sm);
194+
assert((bytes(s).length + bc.length + 7 + bytes(sm).length) == bytes(concatString).length);
195195
196-
bytes memory concat_bytes = bytes.concat(bytes(s), bc, bc[:2], "Literal", bytes(sm), b);
197-
assert((bytes(s).length + bc.length + 2 + 7 + bytes(sm).length + b.length) == concat_bytes.length);
196+
bytes memory concatBytes = bytes.concat(bytes(s), bc, bc[:2], "Literal", bytes(sm), b);
197+
assert((bytes(s).length + bc.length + 2 + 7 + bytes(sm).length + b.length) == concatBytes.length);
198198
}
199199
}
200200
@@ -376,20 +376,20 @@ Array Members
376376
pragma solidity >=0.6.0 <0.9.0;
377377
378378
contract ArrayContract {
379-
uint[2**20] m_aLotOfIntegers;
379+
uint[2**20] aLotOfIntegers;
380380
// Note that the following is not a pair of dynamic arrays but a
381381
// dynamic array of pairs (i.e. of fixed size arrays of length two).
382382
// Because of that, T[] is always a dynamic array of T, even if T
383383
// itself is an array.
384384
// Data location for all state variables is storage.
385-
bool[2][] m_pairsOfFlags;
385+
bool[2][] pairsOfFlags;
386386
387387
// newPairs is stored in memory - the only possibility
388388
// for public contract function arguments
389389
function setAllFlagPairs(bool[2][] memory newPairs) public {
390390
// assignment to a storage array performs a copy of ``newPairs`` and
391-
// replaces the complete array ``m_pairsOfFlags``.
392-
m_pairsOfFlags = newPairs;
391+
// replaces the complete array ``pairsOfFlags``.
392+
pairsOfFlags = newPairs;
393393
}
394394
395395
struct StructType {
@@ -411,45 +411,45 @@ Array Members
411411
412412
function setFlagPair(uint index, bool flagA, bool flagB) public {
413413
// access to a non-existing index will throw an exception
414-
m_pairsOfFlags[index][0] = flagA;
415-
m_pairsOfFlags[index][1] = flagB;
414+
pairsOfFlags[index][0] = flagA;
415+
pairsOfFlags[index][1] = flagB;
416416
}
417417
418418
function changeFlagArraySize(uint newSize) public {
419419
// using push and pop is the only way to change the
420420
// length of an array
421-
if (newSize < m_pairsOfFlags.length) {
422-
while (m_pairsOfFlags.length > newSize)
423-
m_pairsOfFlags.pop();
424-
} else if (newSize > m_pairsOfFlags.length) {
425-
while (m_pairsOfFlags.length < newSize)
426-
m_pairsOfFlags.push();
421+
if (newSize < pairsOfFlags.length) {
422+
while (pairsOfFlags.length > newSize)
423+
pairsOfFlags.pop();
424+
} else if (newSize > pairsOfFlags.length) {
425+
while (pairsOfFlags.length < newSize)
426+
pairsOfFlags.push();
427427
}
428428
}
429429
430430
function clear() public {
431431
// these clear the arrays completely
432-
delete m_pairsOfFlags;
433-
delete m_aLotOfIntegers;
432+
delete pairsOfFlags;
433+
delete aLotOfIntegers;
434434
// identical effect here
435-
m_pairsOfFlags = new bool[2][](0);
435+
pairsOfFlags = new bool[2][](0);
436436
}
437437
438-
bytes m_byteData;
438+
bytes byteData;
439439
440440
function byteArrays(bytes memory data) public {
441441
// byte arrays ("bytes") are different as they are stored without padding,
442442
// but can be treated identical to "uint8[]"
443-
m_byteData = data;
443+
byteData = data;
444444
for (uint i = 0; i < 7; i++)
445-
m_byteData.push();
446-
m_byteData[3] = 0x08;
447-
delete m_byteData[2];
445+
byteData.push();
446+
byteData[3] = 0x08;
447+
delete byteData[2];
448448
}
449449
450450
function addFlag(bool[2] memory flag) public returns (uint) {
451-
m_pairsOfFlags.push(flag);
452-
return m_pairsOfFlags.length;
451+
pairsOfFlags.push(flag);
452+
return pairsOfFlags.length;
453453
}
454454
455455
function createMemoryArray(uint size) public pure returns (bytes memory) {

0 commit comments

Comments
 (0)