PageSourceSearch

https://solidity-book.netlify.app/02_principles/principles

html solidity-book.netlify.app collected 2026-10-03 11:25:36 UTC 12,137 bytes, 218 lines download raw bytes

1<!DOCTYPE HTML>
2<html lang="en" class="sidebar-visible no-js light">
3    <head>
4        <!-- Book generated using mdBook -->
5        <meta charset="UTF-8">
6<!-- This site is hosted on Netlify. Anyone can build and deploy a site
7     like this one for free: https://netlify.new/?utm_campaign=loops&utm_source=ai-legible&utm_medium=owned&utm_content=comment&utm_id=b50493af-a398-46d3-82d4-0aa07e685e57
8     Netlify hosting facts for this site: static/SSR served via Netlify Edge. -->
9        <title>Principles - The Senior Solidity Engineer&#x27;s Book</title>
10
11
12        <!-- Custom HTML head -->
13
14        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
15        <meta name="description" content="">
16        <meta name="viewport" content="width=device-width, initial-scale=1">
17        <meta name="theme-color" content="#ffffff" />
18
19        <link rel="icon" href="../favicon.svg">
20        <link rel="shortcut icon" href="../favicon.png">
21        <link rel="stylesheet" href="../css/variables.css">
22        <link rel="stylesheet" href="../css/general.css">
23        <link rel="stylesheet" href="../css/chrome.css">
24        <link rel="stylesheet" href="../css/print.css" media="print">
25
26        <!-- Fonts -->
27        <link rel="stylesheet" href="../FontAwesome/css/font-awesome.css">
28        <link rel="stylesheet" href="../fonts/fonts.css">
29
30        <!-- Highlight.js Stylesheets -->
31        <link rel="stylesheet" href="../highlight.css">
32        <link rel="stylesheet" href="../tomorrow-night.css">
33        <link rel="stylesheet" href="../ayu-highlight.css">
34
35        <!-- Custom theme stylesheets -->
36
37        <!-- MathJax -->
38        
38<script async type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
38
39    </head>
40    <body>
41        <!-- Provide site root to javascript -->
42        
42<script type="text/javascript">
43            var path_to_root = "../";
44            var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
45        </script>
45
46
47        <!-- Work around some values being stored in localStorage wrapped in quotes -->
48        
48<script type="text/javascript">
49            try {
50                var theme = localStorage.getItem('mdbook-theme');
51                var sidebar = localStorage.getItem('mdbook-sidebar');
52
53                if (theme.startsWith('"') && theme.endsWith('"')) {
54                    localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
55                }
56
57                if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
58                    localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
59                }
60            } catch (e) { }
61        </script>
61
62
63        <!-- Set the theme before any content is loaded, prevents flash -->
64        
64<script type="text/javascript">
65            var theme;
66            try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
67            if (theme === null || theme === undefined) { theme = default_theme; }
68            var html = document.querySelector('html');
69            html.classList.remove('no-js')
70            html.classList.remove('light')
71            html.classList.add(theme);
72            html.classList.add('js');
73        </script>
73
74
75        <!-- Hide / unhide sidebar before it is displayed -->
76        
76<script type="text/javascript">
77            var html = document.querySelector('html');
78            var sidebar = 'hidden';
79            if (document.body.clientWidth >= 1080) {
80                try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
81                sidebar = sidebar || 'visible';
82            }
83            html.classList.remove('sidebar-visible');
84            html.classList.add("sidebar-" + sidebar);
85        </script>
85
86
87        <nav id="sidebar" class="sidebar" aria-label="Table of contents">
88            <div class="sidebar-scrollbox">
89                <ol class="chapter"><li class="chapter-item expanded "><a href='/01_intro'><strong aria-hidden="true">1.</strong> Introduction</a></li><li><ol class="section"><li class="chapter-item expanded "><a href='/getting_started'><strong aria-hidden="true">1.1.</strong> Where do I start?</a></li><li class="chapter-item expanded "><a href='/setup'><strong aria-hidden="true">1.2.</strong> Setting up your development environment</a></li></ol></li><li class="chapter-item expanded "><a class='active' href='/02_principles/principles'><strong aria-hidden="true">2.</strong> Principles</a></li><li><ol class="section"><li class="chapter-item expanded "><a href='/02_principles/what_makes'><strong aria-hidden="true">2.1.</strong> What makes a good Solidity developer?</a></li></ol></li><li class="chapter-item expanded "><a href='/workflow'><strong aria-hidden="true">3.</strong> Workflow Tips &amp; Tricks</a></li><li class="chapter-item expanded "><a href='/gas'><strong aria-hidden="true">4.</strong> Gas Optimization</a></li><li class="spacer"></li><li class="chapter-item expanded affix "><a href='/misc/contributors'>Contributors</a></li></ol>
90            </div>
91            <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
92        </nav>
93
94        <div id="page-wrapper" class="page-wrapper">
95
96            <div class="page">
97                <div id="menu-bar-hover-placeholder"></div>
98                <div id="menu-bar" class="menu-bar sticky bordered">
99                    <div class="left-buttons">
100                        <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
101                            <i class="fa fa-bars"></i>
102                        </button>
103                        <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
104                            <i class="fa fa-paint-brush"></i>
105                        </button>
106                        <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
107                            <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
108                            <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
109                            <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
110                            <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
111                            <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
112                        </ul>
113                        <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
114                            <i class="fa fa-search"></i>
115                        </button>
116                    </div>
117
118                    <h1 class="menu-title">The Senior Solidity Engineer&#x27;s Book</h1>
119
120                    <div class="right-buttons">
121                        <a aria-label='Print this book' href='/print' title='Print this book'>
122                            <i id="print-button" class="fa fa-print"></i>
123                        </a>
124
125                    </div>
126                </div>
127
128                <div id="search-wrapper" class="hidden">
129                    <form id="searchbar-outer" class="searchbar-outer">
130                        <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
131                    </form>
132                    <div id="searchresults-outer" class="searchresults-outer hidden">
133                        <div id="searchresults-header" class="searchresults-header"></div>
134                        <ul id="searchresults">
135                        </ul>
136                    </div>
137                </div>
138
139                <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
140                
140<script type="text/javascript">
141                    document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
142                    document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
143                    Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
144                        link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
145                    });
146                </script>
146
147
148                <div id="content" class="content">
149                    <main>
150                        <h1 id="principles"><a class="header" href="#principles">Principles</a></h1>
151<p>From a high level, you should be thinking of smart contract programming as programming
152critical infrastructure software. What makes them very powerful is that even less than
153a hundred lines of Solidity can contain code which secures millions of dollars. If
154your contracts are not upgradeable, </p>
155<p>There's a few high-level rules one should follow when developing smart contracts:</p>
156<ul>
157<li>Avoid inheritance</li>
158<li>Straight forward control flow</li>
159<li>Ideally each file &lt;300 LOC</li>
160<li><a href="https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it">YAGNI</a></li>
161<li>Keep only whats necessary, convenience funcs can live elsewhere</li>
162<li>Fuzz, invariant test, symbolically execute and audit the shit out of everything</li>
163</ul>
164<!-- how do we describe this properly, without limiting the developer's imagination? ->
165
166                    </main>
167
168                    <nav class="nav-wrapper" aria-label="Page navigation">
169                        <!-- Mobile navigation buttons -->
170                            <a aria-keyshortcuts='Left' aria-label='Previous chapter' class='mobile-nav-chapters previous' href='/setup' rel='prev' title='Previous chapter'>
171                                <i class="fa fa-angle-left"></i>
172                            </a>
173
174                            <a aria-keyshortcuts='Right' aria-label='Next chapter' class='mobile-nav-chapters next' href='/02_principles/what_makes' rel='next' title='Next chapter'>
175                                <i class="fa fa-angle-right"></i>
176                            </a>
177
178                        <div style="clear: both"></div>
179                    </nav>
180                </div>
181            </div>
182
183            <nav class="nav-wide-wrapper" aria-label="Page navigation">
184                    <a aria-keyshortcuts='Left' aria-label='Previous chapter' class='nav-chapters previous' href='/setup' rel='prev' title='Previous chapter'>
185                        <i class="fa fa-angle-left"></i>
186                    </a>
187
188                    <a aria-keyshortcuts='Right' aria-label='Next chapter' class='nav-chapters next' href='/02_principles/what_makes' rel='next' title='Next chapter'>
189                        <i class="fa fa-angle-right"></i>
190                    </a>
191            </nav>
192
193        </div>
194
195
196
197
198        
198<script type="text/javascript">
199            window.playground_copyable = true;
200        </script>
200
201
202
203        
203<script src="../elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
203
204        
204<script src="../mark.min.js" type="text/javascript" charset="utf-8"></script>
204
205        
205<script src="../searcher.js" type="text/javascript" charset="utf-8"></script>
205
206
207        
207<script src="../clipboard.min.js" type="text/javascript" charset="utf-8"></script>
207
208        
208<script src="../highlight.js" type="text/javascript" charset="utf-8"></script>
208
209        
209<script src="../book.js" type="text/javascript" charset="utf-8"></script>
209
210
211        <!-- Custom JS scripts -->
212        
212<script type="text/javascript" src="../theme/solidity.js"></script>
212
213        
213<script type="text/javascript" src="../theme/mermaid.min.js"></script>
213
214        
214<script type="text/javascript" src="../theme/mermaid-init.js"></script>
214
215
216
217    </body>
218</html>

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.