ββ// Avoid
ββfunction ttt() {
ββ a = 1;
ββ b = 2;
ββ .... // do something
ββ c = 3;
ββ d = 4
ββ}
ββ
ββ// better
ββfunction ttt() {
ββ a = 1;
ββ b = 2;
ββ c = 3;
ββ d = 4;
ββ ... do something
ββ}
ββ// LOOP
ββuint cnt;
ββ
ββ// avoid
ββfunction ttt() {
ββ for(...) {
ββ cnt++;
ββ }
ββ}
ββ
ββ// better
ββfunction ttt() {
ββ uint tmp = cnt;
ββ for(...) {
ββ tmp++;
ββ }
ββ cnt = tmp;
ββ}
ββ// Avoid
ββuint64 a; --> x1
ββuint b --> x2
ββbyte c; -|
ββuint64 d; --> x3
ββ
ββ// better
ββuint64 a; -|
ββuint64 d; |
ββbyte c; --> x1
ββuint b; --> x2
ββ// avoid
ββfunction ttt(address user);
ββ
ββ// better
ββfunction ttt(address[] users);
ββ``
ββfunction a() --> cost 5k
ββfunction b() --> cost 20k
ββ
ββ// should
ββif (a() || b()) {
ββ ...
ββ}
external
for functions only accessed externally. (not public
)ββfunction b() public --> cost n
ββfunction a() public --> cost n+22
note
solidity