The source content for blog.juliobiason.me
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.8 KiB

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Enable responsiveness on mobile devices-->
<!-- viewport-fit=cover is to support iPhone X rounded corners and notch in landscape-->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, viewport-fit=cover">
<title>Julio Biason .Me 4.3</title>
<!-- CSS -->
<link rel="stylesheet" href="https://blog.juliobiason.me/print.css" media="print">
<link rel="stylesheet" href="https://blog.juliobiason.me/poole.css">
<link rel="stylesheet" href="https://blog.juliobiason.me/hyde.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400italic,700|Abril+Fatface">
</head>
<body class=" ">
<div class="sidebar">
<div class="container sidebar-sticky">
<div class="sidebar-about">
<a href="https:&#x2F;&#x2F;blog.juliobiason.me"><h1>Julio Biason .Me 4.3</h1></a>
<p class="lead">Old school dev living in a 2.0 dev world</p>
</div>
<ul class="sidebar-nav">
<li class="sidebar-nav-item"><a href="&#x2F;">English</a></li>
<li class="sidebar-nav-item"><a href="&#x2F;pt">Português</a></li>
<li class="sidebar-nav-item"><a href="&#x2F;tags">Tags (EN)</a></li>
<li class="sidebar-nav-item"><a href="&#x2F;pt&#x2F;tags">Tags (PT)</a></li>
</ul>
</div>
</div>
<div class="content container">
<div class="post">
<h1 class="post-title">Things I Learnt The Hard Way - Units Makes Things Clear</h1>
<span class="post-date">
2019-07-17
<a href="https://blog.juliobiason.me/tags/books/">#books</a>
<a href="https://blog.juliobiason.me/tags/things-i-learnt/">#things i learnt</a>
<a href="https://blog.juliobiason.me/tags/units/">#units</a>
<a href="https://blog.juliobiason.me/tags/explicit/">#explicit</a>
</span>
<p>You know what's one of the worst function names ever? <code>sleep()</code>.</p>
<p>Sleep for how long? It is seconds or milliseconds?</p>
<span id="continue-reading"></span>
<p>Now let me ask you this: Would it clearer if the function was called
<code>sleepForMs()</code>? Would you understand that the function would make the
application sleep for a number of milliseconds?</p>
<p>What about <code>sleepForSecs()</code>? Do you understand that this will force your
application to sleep for a number of seconds?</p>
<p>What if, instead of using the function name, you could use <code>sleep(&quot;10s&quot;)</code>? Does
it make clear that you want it to sleep for 10 seconds?</p>
<p>That's why adding units to the function or parameters make sense. It removes
the ambiguity of what it means and doesn't rely on some specialized IDE/Editor
that display the parameter names.</p>
<div>
<div style="float:left">
&lt;&lt; <a href="&#x2F;books&#x2F;things-i-learnt&#x2F;optimization">Optimization Is For Compilers</a>
</div>
&nbsp;
<div style="float:right">
<a href="&#x2F;books&#x2F;things-i-learnt&#x2F;run-locally">If It Doesn&#x27;t Run On Your Computer, You Have A Problem</a> &gt;&gt;
</div>
</div>
</div>
</div>
</body>
</html>