mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
commit
6b711d0527
@ -124,6 +124,8 @@ This means that cyclic creation dependencies are impossible.
|
|||||||
|
|
||||||
.. index:: ! visibility, external, public, private, internal
|
.. index:: ! visibility, external, public, private, internal
|
||||||
|
|
||||||
|
.. _visibility-and-accessors:
|
||||||
|
|
||||||
************************
|
************************
|
||||||
Visibility and Accessors
|
Visibility and Accessors
|
||||||
************************
|
************************
|
||||||
@ -232,6 +234,8 @@ is no good way to provide the key for the mapping.
|
|||||||
|
|
||||||
.. index:: ! function;modifier
|
.. index:: ! function;modifier
|
||||||
|
|
||||||
|
.. _modifiers:
|
||||||
|
|
||||||
******************
|
******************
|
||||||
Function Modifiers
|
Function Modifiers
|
||||||
******************
|
******************
|
||||||
|
@ -117,10 +117,10 @@ Tips and Tricks
|
|||||||
|
|
||||||
* Use `delete` on arrays to delete all its elements.
|
* Use `delete` on arrays to delete all its elements.
|
||||||
* Use shorter types for struct elements and sort them such that short types are grouped together. This can lower the gas costs as multiple SSTORE operations might be combined into a single (SSTORE costs 5000 or 20000 gas, so this is what you want to optimise). Use the gas price estimator (with optimiser enabled) to check!
|
* Use shorter types for struct elements and sort them such that short types are grouped together. This can lower the gas costs as multiple SSTORE operations might be combined into a single (SSTORE costs 5000 or 20000 gas, so this is what you want to optimise). Use the gas price estimator (with optimiser enabled) to check!
|
||||||
* Make your state variables public - the compiler will create [getters](#accessor-functions) for you for free.
|
* Make your state variables public - the compiler will create :ref:`getters <visibility-and-accessors>` for you for free.
|
||||||
* If you end up checking conditions on input or state a lot at the beginning of your functions, try using [modifiers](#function-modifiers)
|
* If you end up checking conditions on input or state a lot at the beginning of your functions, try using :ref:`modifiers`.
|
||||||
* If your contract has a function called `send` but you want to use the built-in send-function, use `address(contractVariable).send(amount)`.
|
* If your contract has a function called `send` but you want to use the built-in send-function, use `address(contractVariable).send(amount)`.
|
||||||
* If you want your contracts to receive ether when called via `send`, you have to implement the [fallback function](#fallback-functions).
|
* If you do **not** want your contracts to receive ether when called via `send`, you can add a throwing fallback function `function() { throw; }`.
|
||||||
* Initialise storage structs with a single assignment: `x = MyStruct({a: 1, b: 2});`
|
* Initialise storage structs with a single assignment: `x = MyStruct({a: 1, b: 2});`
|
||||||
|
|
||||||
********
|
********
|
||||||
|
Loading…
Reference in New Issue
Block a user