# 区块链100讲：风格指南说明-solidity 语言中文文档

1

2

contract A { ...

}

contract B { ...

}

contract C { ...

}

contract A { ...

}

contract B { ...

}

contract C { ...

}

contract A {

function spam() public;

function ham() public;}contract B is A {

function spam() public {

...

}

function ham() public {

...

}

}

contract A {

function spam() public {

...

}

function ham() public {

...

}

}

Imports规范

import "owned";contract A {

...

}

contract B is owned {

...

}

contract A {

...

}

import "owned";

contract B is owned {

...

}

contract A {

function A() public {

...

}

function() public {

...

}

// External functions

// ...

// External functions that are constant

// ...

// Public functions

// ...

// Internal functions

// ...

// Private functions

// ...

}

contract A {

// External functions

// ...

// Private functions

// ...

// Public functions

// ...

function A() public {

...

}

function() public {

...

}

// Internal functions

// ...

}

spam(ham[1], Coin());

spam( ham[ 1 ], Coin( { name: "ham" } ) );

function singleLine() public { spam(); }

function spam(uint i, Coin coin) public;

function spam(uint i , Coin coin) public ;

x = 1;

y = 2;

long_variable = 3;

x = 1;

y = 2;

long_variable = 3;

function() public {

...

}

function () public {

...

}

contract Coin {

struct Bank {

uint balance;

}

}

contract Coin{

struct Bank {

uint balance;

}

}

if (...) {

...

}

for (...) {

...

}

if (...){

...

}

while(...){}

for (...) {

...;

}

if (x

x += 1;

if (x

someArray.push(Coin({

name: 'spam',

value: 42

}));

if (x

x += 1;

} else if (x > 7) {

x -= 1;

} else {

x = 5;

}

if (x

x += 1;

else

x -= 1;

if (x

x += 1;

}else {

x -= 1;

}

function increment(uint x) public pure returns (uint) {

return x + 1;

}

function increment(uint x) public pure onlyowner returns (uint) {

return x + 1;

}

function increment(uint x) public pure returns (uint){

return x + 1;

}

function increment(uint x) public pure returns (uint){

return x + 1;

}

function increment(uint x) public pure returns (uint) {

return x + 1;

}

function increment(uint x) public pure returns (uint) {

return x + 1;

}

function kill() public onlyowner {

selfdestruct(owner);

}

function kill() onlyowner public {

selfdestruct(owner);

}

function thisFunctionHasLotsOfArguments(

public{

doSomething();}

doSomething();

}

doSomething();

}

function thisFunctionHasLotsOfArguments(

doSomething();

}

onlyowner

priced

doSomething();

}

function thisFunctionNameIsReallyLong(

public

onlyowner

priced

doSomething();

}

public

onlyowner

priced

doSomething();

}

}

public onlyowner priced returns (address) {

doSomething();

}

function thisFunctionNameIsReallyLong(

public

returns (

uint256 LongArgument,

uint256 Argument

){

doSomething()

return (

veryLongReturnArg1,

veryLongReturnArg2,

veryLongReturnArg3

);

}

function thisFunctionNameIsReallyLong(

public

uint256 LongArgument,

uint256 Argument){

doSomething()

return (veryLongReturnArg1,

veryLongReturnArg1,

veryLongReturnArg1);

}

contract A is B, C, D {

function A(uint param1, uint param2, uint param3, uint param4, uint param5)

B(param1)

C(param2, param3)

D(param4)

public {

// do something with param5 }

}

contract A is B, C, D {

function A(uint param1, uint param2, uint param3, uint param4, uint param5)

B(param1)

C(param2, param3)

D(param4)

public

{

// do something with param5

}

}

contract A is B, C, D {

function A(uint param1, uint param2, uint param3, uint param4, uint param5)

B(param1)

C(param2, param3)

D(param4)

public {

// do something with param5

}

}

function shortFunction() public { doSomething(); }

uint[] x;

uint [] x;

str = "foo";

str = "Hamlet says, 'To be or not to be...'";

str = 'bar';

str = '"Be yourself; everyone else is already taken." -Oscar Wilde';

x = 3;

x = 100 / 10;

x += 3 + 4;

x |= y && z;

x=3;

x = 100/10;

x += 3+4;

x |= y&&z;

x = 2**3 + 5;

x = 2*y + 3*z;

x = (a+b) * (a-b);

x = 2** 3 + 5;

x = y+z;

x +=1;

3

b (单个小写字母)

B (单个大写字母)

lowercase （小写）

lower_case_with_underscores （小写和下划线）

UPPERCASE （大写）

UPPER_CASE_WITH_UNDERSCORES （大写和下划线）

CapitalizedWords (驼峰式，首字母大写）

mixedCase (混合命名法，区别于首字母大写的初始字母小写!)

Capitalized_Words_With_Underscores (首字母大写和下划线)

l - el的小写方式

O - oh的大写方式

I - eye的大写方式

single_trailing_underscore_

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20180613B0QX5W00?refer=cp_1026
• 腾讯「云+社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 yunjia_community@tencent.com 删除。

2021-07-30

2021-07-30

2021-07-30

2021-07-30

2018-06-13

2018-05-03

2018-08-24

2018-06-27

2018-06-13

2021-07-30

2021-07-30

2021-07-30