diff options
Diffstat (limited to 'public/post/programming-as-art')
| -rw-r--r-- | public/post/programming-as-art/code.png | bin | 530926 -> 0 bytes | |||
| -rw-r--r-- | public/post/programming-as-art/index.html | 179 | ||||
| -rw-r--r-- | public/post/programming-as-art/math.png | bin | 398307 -> 0 bytes | |||
| -rw-r--r-- | public/post/programming-as-art/teaching.png | bin | 410632 -> 0 bytes | |||
| -rw-r--r-- | public/post/programming-as-art/wand.png | bin | 356173 -> 0 bytes |
5 files changed, 0 insertions, 179 deletions
diff --git a/public/post/programming-as-art/code.png b/public/post/programming-as-art/code.png Binary files differdeleted file mode 100644 index 30c3522..0000000 --- a/public/post/programming-as-art/code.png +++ /dev/null diff --git a/public/post/programming-as-art/index.html b/public/post/programming-as-art/index.html deleted file mode 100644 index 32ff96c..0000000 --- a/public/post/programming-as-art/index.html +++ /dev/null @@ -1,179 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> - - <head><title>Romanticism in Programming – Kumar Damani - Home</title> -<meta name="description" content="Git, email, and resume"> - -<meta name="viewport" content="width=device-width, initial-scale=1"> -<meta charset="UTF-8"/> - -<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.css" integrity="sha384-vKruj+a13U8yHIkAyGgK1J3ArTLzrFGBbBc0tDp4ad/EyewESeXE/Iv67Aj8gKZ0" crossorigin="anonymous"> -<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/katex.min.js" integrity="sha384-PwRUT/YqbnEjkZO0zZxNqcxACrXe+j766U2amXcgMg5457rve2Y7I6ZJSm2A0mS4" crossorigin="anonymous"></script> -<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.4/dist/contrib/auto-render.min.js" integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous" - onload="renderMathInElement(document.body);"></script> -<script> - document.addEventListener("DOMContentLoaded", function() { - renderMathInElement(document.body, { - delimiters: [ - {left: "$$", right: "$$", display: true}, - {left: "$", right: "$", display: false} - ] - }); - }); -</script> - - - -<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css" integrity="sha512-1sCRPdkRXhBV2PBLUdRb4tMg1w2YPf37qatUFeS7zlBy7jJI8Lf4VHwWfZZfpXtYSLy85pkm9GaYVYMfw5BC1A==" crossorigin="anonymous" /> - - -<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/academicons/1.9.1/css/academicons.min.css" integrity="sha512-b1ASx0WHgVFL5ZQhTgiPWX+68KjS38Jk87jg7pe+qC7q9YkEtFq0z7xCglv7qGIs/68d3mAp+StfC8WKC5SSAg==" crossorigin="anonymous" /> - - -<link rel="stylesheet" href="https://kumardamani.net/css/palettes/tokyo-night-dark.css"> -<link rel="stylesheet" href="https://kumardamani.net/css/risotto.css"> -<link rel="stylesheet" href="https://kumardamani.net/css/custom.css"> -</head> - - <body> - <div class="page"> - - <header class="page__header"><nav class="page__nav main-nav"> - <ul> - <h1 class="page__logo"><a href="https://kumardamani.net/" class="page__logo-inner">Kumar Damani - Home</a></h1> - - - <li class="main-nav__item"><a class="nav-main-item active" href="https://kumardamani.net/post/" title="Posts">Posts</a></li> - - </ul> -</nav> - -</header> - - <section class="page__body"> - <header class="content__header"> - <h1>Romanticism in Programming</h1> - </header> - - <div class="content__body"> - <p>Why there is art in programming.</p> -<p>During my early days as a CS student, one of the first mind-blowing moments was -watching <code>Hello World!</code> getting printed out to the console thousands of times -in just two functional lines of code.</p> -<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#66d9ef">for</span> _ <span style="color:#f92672">in</span> range(<span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">1001</span>): -</span></span><span style="display:flex;"><span> print(<span style="color:#e6db74">"Hello World!"</span>) -</span></span></code></pre></div><p>At the time it felt like having the <a href="https://harry-potter-compendium.fandom.com/wiki/Elder_Wand">Elder Wand</a>. -<img src="wand.png" alt="Dumbledore with Elder Wand pic"></p> -<p>But there was more to our lesson. -The TA then asks us to put our newly found power to use by computing the -sum of 1 to 100. Of course, it was a natural application of what we had just done earlier:</p> -<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>sum <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span> -</span></span><span style="display:flex;"><span><span style="color:#66d9ef">for</span> i <span style="color:#f92672">in</span> range(<span style="color:#ae81ff">1</span>, <span style="color:#ae81ff">100</span><span style="color:#f92672">+</span><span style="color:#ae81ff">1</span>): -</span></span><span style="display:flex;"><span> sum <span style="color:#f92672">=</span> sum <span style="color:#f92672">+</span> i -</span></span></code></pre></div><p>Sure enough we saw the answer <code>5050</code> in the console. -But then the TA reminds us that we are making our computers <strong>work too hard</strong>. -In other words, the computer needs to do one-hundred ADD instructions in order to make this computation happen.</p> -<p>What if the number was a million? How well would our method scale?</p> -<p>Well then it would take a million ADD instructions. -We call this scaling <em>linearly</em> with the input size. -Later we would formalize this to $\mathcal{O}(n)$ (pronounced: <em>Big Oh of N</em>).</p> -<p>The TA hinted that there is a better way, and that we already know of the better way in math.</p> -<p><img src="teaching.png" alt="Teaching meme"></p> -<p>$\displaystyle S_n = \sum\limits_{i=1}^n i = 1 + 2 + … + n = \frac{n (n + 1)}{2}$</p> -<p>With this we are no longer using loops, but a known mathematical fact about sequences. -If you don’t belive me, see the <a href="https://letstalkscience.ca/educational-resources/backgrounders/gauss-summation">proof</a>.</p> -<p>Written as code:</p> -<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span>sum <span style="color:#f92672">=</span> n (n <span style="color:#f92672">+</span> <span style="color:#ae81ff">1</span>) <span style="color:#f92672">/</span> <span style="color:#ae81ff">2</span> -</span></span></code></pre></div><p>This one-liner solves our problem with just 3 (ADD, MULTIPLY, DIVIDE) instructions. -Crucially, it does not depend on the size of the input like our previous solution, thus -<strong>no matter the input, it always takes 3 instructions to compute!</strong> -This is a HUGE win!</p> -<p><img src="math.png" alt="Math meme"></p> -<p>Later we would formalize this to $\mathcal{O}(1)$, or <em>constant</em> scaling.</p> -<blockquote> -<p>Yes, yes I know IRL the complier would optimize the loop solution -such that it does not take N instructions but for the purposes of -learning we were not allowed to depend on that.</p> -</blockquote> -<p>Looking back at it now, -both solutions are equally correct, and modern compilers would optimize the first solution -in the final instructions sent to the cpu, such that any performance differences would be negligible. -In other words, the computer wouldn’t acutally be <em>working so hard</em>.</p> -<p>Objectively, the first solution is more readable, and friendly to a new observer than the second.</p> -<p><em>Why then am I still so drawn to the second solution?</em></p> -<p>The first solution reminds me of the saying “to a hammer, eveything looks like a nail”. -Its a brute force approach. -In comparison, the second solution is using the exact tool for our particular problem. -It somehow feels personalized and dare I say <em>romantic</em>.</p> -<p>When I reflect on moments like this, it reminds me that there is emergent elegance and beauty -even in the seemingly arbitrary sequence of symbols that is <code>code</code>. -<img src="code.png" alt="The Matrix code going by image"></p> -<p>Programming is not quite as <em>objective</em> as people would have you believe. -There are trade-offs to each solution, and which solution you prefer relect on the trade-offs -you are willing to accept, which varies by the observer: much like <em>art</em>.</p> - </div> - <footer class="content__footer"></footer> - - </section> - - <section class="page__aside"> - <div class="aside__about"> -<div class="aside__about"> - <img class="about__logo" src="https://kumardamani.net/images/rice.svg" alt="Logo"> -<h1 class="about__title">Links</h1> -<p class="about__description">Git, email, and resume</p> -</div> - - -<ul class="aside__social-links"> - - <li> - <a href="https://gitlab.com/kdam0/" rel="me" aria-label="GitLab" title="GitLab"><i class="fa-brands fa-gitlab" aria-hidden="true"></i></a> - </li> - - <li> - <a href="mailto:me@kumardamani.net" rel="me" aria-label="Email" title="Email"><i class="fa-solid fa-envelope" aria-hidden="true"></i></a> - </li> - - <li> - <a href="/KumarDamaniCV.pdf" rel="me" aria-label="Resume" title="Resume"><i class="fa-solid fa-file" aria-hidden="true"></i></a> - </li> - -</ul> -</div> - <hr> - <div class="aside__content"> - <p>How programming is romantic.</p> - - <p> - By Kumar Damani, - 2022-11-29 - </p> - - - - - </div> - </section> - - <footer class="page__footer"><p> - - - - - - - - - - -</p> -<br /><br /> -<p class="copyright"></p> -<p class="advertisement">Powered by <a href="https://gohugo.io/">hugo</a> and <a href="https://github.com/joeroe/risotto">risotto</a>.</p> -</footer> - - </div> - </body> - -</html> diff --git a/public/post/programming-as-art/math.png b/public/post/programming-as-art/math.png Binary files differdeleted file mode 100644 index bbdc372..0000000 --- a/public/post/programming-as-art/math.png +++ /dev/null diff --git a/public/post/programming-as-art/teaching.png b/public/post/programming-as-art/teaching.png Binary files differdeleted file mode 100644 index 9bf5dce..0000000 --- a/public/post/programming-as-art/teaching.png +++ /dev/null diff --git a/public/post/programming-as-art/wand.png b/public/post/programming-as-art/wand.png Binary files differdeleted file mode 100644 index 5eefc9c..0000000 --- a/public/post/programming-as-art/wand.png +++ /dev/null |
