Functions can be specified as being external, public, internal or private, where the default is public. For state variables, external is not possible and the default is internal.
external: 只可以給外面的contract呼叫,不可內部呼叫
External functions are part of the contract interface, which means they can be called from other contracts and via transactions. An external function f cannot be called internally (i.e. f() does not work, but this.f() works). External functions are sometimes more efficient when they receive large arrays of data.
public: 都可呼叫
Public functions are part of the contract interface and can be either called internally or via messages. For public state variables, an automatic getter function (see below) is generated.
internal: 跟private類似,但如果是繼承該contract的contract也可以呼叫
Those functions and state variables can only be accessed internally (i.e. from within the current contract or contracts deriving from it), without using this.
private: 只有同contract才可呼叫
Private functions and state variables are only visible for the contract they are defined in and not in derived contracts.
View, Pure, Const
修改的意思代表會去更改合約中其他變數的值。
View: 可讀取,但不可修改
Pure: 不可讀取,不可修改
const: 可讀取,但不可修改,不可加在function上
return or throw
The former will cost less gas but it can be more headache as any changes you did to the contract so far will be kept. In the other hand, 'throw' will cancel all contract execution, revert any changes that transaction could have made and the sender will lose all ether he sent for gas. But since the Wallet can detect that a contract will throw, it always shows an alert, therefore preventing any ether to be spent at all.