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.
134 lines
5.5 KiB
134 lines
5.5 KiB
11 months ago
|
<!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://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="/">English</a></li>
|
||
|
|
||
|
<li class="sidebar-nav-item"><a href="/pt">Português</a></li>
|
||
|
|
||
|
<li class="sidebar-nav-item"><a href="/tags">Tags (EN)</a></li>
|
||
|
|
||
|
<li class="sidebar-nav-item"><a href="/pt/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 - Cognitive Cost Is The Readability Killer</h1>
|
||
|
<span class="post-date">
|
||
|
2019-06-26
|
||
|
|
||
|
<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/cognitive-dissonance/">#cognitive dissonance</a>
|
||
|
|
||
|
<a href="https://blog.juliobiason.me/tags/cognitive-cost/">#cognitive cost</a>
|
||
|
|
||
|
</span>
|
||
|
<p>"<a href="https://en.wikipedia.org/wiki/Cognitive_dissonance">Cognitive dissonance</a>"
|
||
|
is a fancy way of saying "I need to remember two (or more) different and
|
||
|
contradicting things at the same time to understand this." Keeping those
|
||
|
different things in your head creates a cost and it keeps accumulating the
|
||
|
more indirect the things are ('cause you'll have to keep all those in your
|
||
|
head).</p>
|
||
|
<span id="continue-reading"></span>
|
||
|
<p>(Disclaimer: I like to use the expression "cognitive dissonance" to make me
|
||
|
sound smarter. I usually explain what it means, though.)</p>
|
||
|
<p>To give you an example of a (very mild) cognitive cost, I'll show you this:</p>
|
||
|
<ul>
|
||
|
<li>You have a function called <code>sum()</code>. It does the sum of the numbers of a
|
||
|
list.</li>
|
||
|
<li>You have another function, called <code>is_pred()</code>. It gets a value and, if it
|
||
|
fits the predicate -- a test, basically -- returns True; otherwise,
|
||
|
returns False.</li>
|
||
|
</ul>
|
||
|
<p>So, pretty simple, right? One function sums numbers and another returns a
|
||
|
boolean.</p>
|
||
|
<p>Now, what would you say if I shown you this, in Python:</p>
|
||
|
<pre data-lang="python" style="background-color:#2b303b;color:#c0c5ce;" class="language-python "><code class="language-python" data-lang="python"><span style="color:#96b5b4;">sum</span><span>(</span><span style="color:#bf616a;">is_pred</span><span>(x) </span><span style="color:#b48ead;">for </span><span>x </span><span style="color:#b48ead;">in </span><span>my_list)
|
||
|
</span></code></pre>
|
||
|
<p>Wait, didn't I say that <code>sum()</code> sums numbers? And that <code>is_pred()</code> returns a
|
||
|
boolean. How can I sum booleans? What's the expected result of True + True +
|
||
|
False?</p>
|
||
|
<p>Sadly, this works. Because someone, long time ago, didn't think booleans were
|
||
|
worth a thing and used an integer instead. And everyone else since then did
|
||
|
the same stupid mistake.</p>
|
||
|
<p>But, for you, you'll now read a line that says "summing a boolean list returns
|
||
|
a number". And that's two different, disparate things that you suddenly have
|
||
|
to keep in mind when reading that line.</p>
|
||
|
<p>That's why <a href="/books/things-i-learnt/data-types">types are important</a>. Also,
|
||
|
this may sound a bit like <a href="/books/things-i-learnt/magical-number-seven">the magical number
|
||
|
seven</a>, 'cause you have to keep
|
||
|
two things at your mind at the same thing but, although that's not near seven,
|
||
|
they are not the same, with opposite (for weird meanings of "opposite", in
|
||
|
this case) meanings.</p>
|
||
|
<div>
|
||
|
|
||
|
<div style="float:left">
|
||
|
<< <a href="/books/things-i-learnt/magical-number-seven">The Magic Number Seven, Plus Or Minus Two</a>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<div style="float:right">
|
||
|
<a href="/books/things-i-learnt/functional-programming">Learn The Basics of Functional Programming</a> >>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
|
||
|
</html>
|