mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Docs style guide
This commit is contained in:
parent
df076e072d
commit
3198f55d24
@ -115,7 +115,7 @@ Details are given in the following example.
|
|||||||
// Here, we only specify `override` and not `virtual`.
|
// Here, we only specify `override` and not `virtual`.
|
||||||
// This means that contracts deriving from `PriceFeed`
|
// This means that contracts deriving from `PriceFeed`
|
||||||
// cannot change the behaviour of `kill` anymore.
|
// cannot change the behaviour of `kill` anymore.
|
||||||
function kill() public override (Mortal, Named) { Named.kill(); }
|
function kill() public override(Mortal, Named) { Named.kill(); }
|
||||||
function get() public view returns(uint r) { return info; }
|
function get() public view returns(uint r) { return info; }
|
||||||
|
|
||||||
uint info;
|
uint info;
|
||||||
@ -297,7 +297,7 @@ of the variable:
|
|||||||
|
|
||||||
contract A
|
contract A
|
||||||
{
|
{
|
||||||
function f() external virtual pure returns(uint) { return 5; }
|
function f() external pure virtual returns(uint) { return 5; }
|
||||||
}
|
}
|
||||||
|
|
||||||
contract B is A
|
contract B is A
|
||||||
|
@ -98,11 +98,11 @@ Yes::
|
|||||||
|
|
||||||
|
|
||||||
contract B is A {
|
contract B is A {
|
||||||
function spam() public override pure {
|
function spam() public pure override {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
function ham() public override pure {
|
function ham() public pure override {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,11 +111,17 @@ No::
|
|||||||
|
|
||||||
pragma solidity >=0.4.0 <0.7.0;
|
pragma solidity >=0.4.0 <0.7.0;
|
||||||
|
|
||||||
contract A {
|
abstract contract A {
|
||||||
function spam() public pure {
|
function spam() virtual pure public;
|
||||||
|
function ham() public virtual pure;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
contract B is A {
|
||||||
|
function spam() public pure override {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
function ham() public pure {
|
function ham() public pure override {
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -564,31 +570,30 @@ No::
|
|||||||
function increment(uint x) public pure returns (uint) {
|
function increment(uint x) public pure returns (uint) {
|
||||||
return x + 1;}
|
return x + 1;}
|
||||||
|
|
||||||
You should explicitly label the visibility of all functions, including constructors.
|
The modifier order for a function should be:
|
||||||
|
|
||||||
|
1. Visibility
|
||||||
|
2. Mutability
|
||||||
|
3. Virtual
|
||||||
|
4. Override
|
||||||
|
5. Custom modifiers
|
||||||
|
|
||||||
Yes::
|
Yes::
|
||||||
|
|
||||||
function explicitlyPublic(uint val) public {
|
function balance(uint from) public view override returns (uint) {
|
||||||
doSomething();
|
return balanceOf[from];
|
||||||
}
|
}
|
||||||
|
|
||||||
No::
|
|
||||||
|
|
||||||
function implicitlyPublic(uint val) {
|
|
||||||
doSomething();
|
|
||||||
}
|
|
||||||
|
|
||||||
The visibility modifier for a function should come before any custom
|
|
||||||
modifiers.
|
|
||||||
|
|
||||||
Yes::
|
|
||||||
|
|
||||||
function kill() public onlyowner {
|
function kill() public onlyowner {
|
||||||
selfdestruct(owner);
|
selfdestruct(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
No::
|
No::
|
||||||
|
|
||||||
|
function balance(uint from) public override view returns (uint) {
|
||||||
|
return balanceOf[from];
|
||||||
|
}
|
||||||
|
|
||||||
function kill() onlyowner public {
|
function kill() onlyowner public {
|
||||||
selfdestruct(owner);
|
selfdestruct(owner);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user