-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
434 lines (278 loc) · 20.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Practical Elegance</title>
<meta name="author" content="Jason Lewis">
<meta name="description" content="Machine Beauty In his essay Machine Beauty, David Gelernter defines “machine beauty” as an inspired mating of simplicity and power. In …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://canweriotnow.github.com">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="/javascripts/ender.js"></script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<link href="/atom.xml" rel="alternate" title="Practical Elegance" type="application/atom+xml">
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22978638-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body >
<header role="banner"><hgroup>
<h1><a href="/">Practical Elegance</a></h1>
<h2>"Elegance is not a dispensable luxury." - Edsgar Dijkstra</h2>
</hgroup>
</header>
<nav role="navigation"><ul class="subscription" data-subscription="rss">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:canweriotnow.github.com" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
</ul>
</nav>
<div id="main">
<div id="content">
<div class="blog-index">
<article>
<header>
<h1 class="entry-title"><a href="/blog/2012/05/08/simplicity/">Simplicity</a></h1>
<p class="meta">
<time datetime="2012-05-08T10:15:00-04:00" pubdate data-updated="true">2012-05-08</time>
</p>
</header>
<div class="entry-content"><h3>Machine Beauty</h3>
<p>In his essay <a href="http://www.goodreads.com/book/show/107615.Machine_Beauty">Machine Beauty</a>, David Gelernter defines “machine beauty” as an inspired mating of simplicity and power. In software, I think this is also what we mean when we talk about “elegance.”</p>
<p><img src="http://photo.goodreads.com/books/1171573120l/107615.jpg" width="250"></p>
<p>The Dijkstra quote that serves as a tagline for this blog is actually truncated; the full quote reads:</p>
<blockquote><p>Elegance is not a dispensable luxury but a quality that decides between success and failure.</p></blockquote>
<p>This is not (necessarily) an economic truth; few people would describe any product from Microsoft as elegant, but they have been economically successful. However, the painful experience of using Microsoft software, the unreliability of both systems and applications, the general clunkiness of Windows applications, indicates that the software here is indeed a failure.</p>
<p>Software is a failure when it becomes an obstacle to productivity rather than an aid to it; when you must serve the compiler (or interpreter) rather than the compiler serving you (think Java boilerplate). From an end-user standpoint, the failure comes when the interface imposes unnatural workflows and ceremony that interrupts the natural flow of completing a task.</p>
<h3>Simplicity Matters</h3>
<p>One of the most interesting (inspiring?) talks at <a href="http://railsconf2012.com/">RailsConf</a> this year was Rich Hickey’s keynote entitled “Simplicity Matters”. Here’s the video, you should watch it:</p>
<iframe width="560" height="315" src="http://www.youtube-nocookie.com/embed/rI8tNMsozo0" frameborder="0" allowfullscreen></iframe>
<p>One of the most important points he makes, early on in the talk, is that we often tend to conflate “simple” with “easy,” and this is far from accurate. It’s all too easy to complect the design of languages, systems, and applications, rather than maintain simplicity and elegance. He’s kind of (allusively) hard on Rails, but not without reason. One of the ongoing efforts in the refactoring and continued development of Rails is to simplify the codebase as well as the APIs.</p>
<h3>Practical Elegance</h3>
<p>There are two modern programming languages that I think exemplify the marriage of power and simplicity that constitutes elegance. The first, which I use every day, is Ruby.</p>
<p>For instance, consider the following accumulator generator in C++:</p>
<figure class='code'><figcaption><span>Accumulator Generator </span><a href='http://www.paulgraham.com/accgen.html'>link</a></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class='c++'><span class='line'><span class="k">template</span><span class="o"><</span><span class="k">typename</span> <span class="n">T</span><span class="o">></span>
</span><span class='line'><span class="k">struct</span> <span class="n">Acc</span> <span class="p">{</span>
</span><span class='line'> <span class="n">Acc</span><span class="p">(</span><span class="n">T</span> <span class="n">n</span><span class="p">)</span>
</span><span class='line'> <span class="o">:</span> <span class="n">n</span><span class="p">(</span><span class="n">n</span><span class="p">)</span> <span class="p">{}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">template</span><span class="o"><</span><span class="k">typename</span> <span class="n">U</span><span class="o">></span>
</span><span class='line'> <span class="n">Acc</span><span class="p">(</span><span class="k">const</span> <span class="n">Acc</span><span class="o"><</span><span class="n">U</span><span class="o">>&</span> <span class="n">u</span><span class="p">)</span>
</span><span class='line'> <span class="o">:</span> <span class="n">n</span><span class="p">(</span><span class="n">u</span><span class="p">.</span><span class="n">n</span><span class="p">)</span> <span class="p">{}</span>
</span><span class='line'>
</span><span class='line'> <span class="k">template</span><span class="o"><</span><span class="k">typename</span> <span class="n">U</span><span class="o">></span>
</span><span class='line'> <span class="n">T</span> <span class="k">operator</span><span class="p">()(</span><span class="n">U</span> <span class="n">i</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'> <span class="k">return</span> <span class="n">n</span> <span class="o">+=</span> <span class="n">i</span><span class="p">;</span>
</span><span class='line'> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'> <span class="n">T</span> <span class="n">n</span><span class="p">;</span>
</span><span class='line'><span class="p">};</span>
</span></code></pre></td></tr></table></div></figure>
<p>Super clear, right? Readable? Oh, yeah.</p>
<p>Hardly. But maybe it’s not fair to pick on C++, simplicity was (sadly) never a design goal.
Python is a more modern programming language, it’s designed to be easy for new programmers to learn.</p>
<figure class='code'><figcaption><span>Accumulator Generator </span><a href='http://www.paulgraham.com/accgen.html'>link</a></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="k">class</span> <span class="nc">foo</span><span class="p">:</span>
</span><span class='line'> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">n</span><span class="p">):</span>
</span><span class='line'> <span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">=</span> <span class="n">n</span>
</span><span class='line'> <span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">i</span><span class="p">):</span>
</span><span class='line'> <span class="bp">self</span><span class="o">.</span><span class="n">n</span> <span class="o">+=</span> <span class="n">i</span>
</span><span class='line'> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">n</span>
</span></code></pre></td></tr></table></div></figure>
<p>Simpler than C++, sure. But you still have all these explicit calls to self, and a class definition that should be unnecessary in a functional construct like an accumulator generator. It’s an improvement, but still ugly as hell.</p>
<p>Now let’s look at Ruby:</p>
<figure class='code'><figcaption><span>Accumulator Generator </span><a href='http://www.paulgraham.com/accgen.html'>link</a></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">def</span> <span class="nf">foo</span> <span class="p">(</span><span class="n">n</span><span class="p">)</span>
</span><span class='line'> <span class="nb">lambda</span> <span class="p">{</span><span class="o">|</span><span class="n">i</span><span class="o">|</span> <span class="n">n</span> <span class="o">+=</span> <span class="n">i</span> <span class="p">}</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<p>Wow. Three lines of code (although it could be written in one). If you understand lambdas, it’s obvious what’s going on here at a glance. You initalize <code>foo</code> with a value, and it returns a lambda that will accumulate any values passed to it.</p>
<p>Ruby makes the solution completely obvious.</p>
<p><em>Note: all examples above from <a href="http://www.paulgraham.com/accgen.html">Paul Graham’s website</a></em></p>
<h3>Clojure</h3>
<p>The other language that has me in awe of its marriage of power and simplicity is <a href="http://clojure.org">Clojure</a>. Clojure is a Lisp dialect targeting the JVM, and I encourage anyone out there to explore it. I’m just getting my feet wet with Clojure, so I haven’t attempted an example like above just yet (the emphasis on mutable state being the exception rather than the rule makes it a little less straightforward).</p>
<p>But here’s my answer to <a href="https://4clojure.com/problem/26">Problem 26</a> on <a href="https://4clojure.com">4clojure</a>, which involves creating a Fibonacci sequence generator using only lambdas.</p>
<figure class='code'><figcaption><span>Fibonacci Generator</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='clojure'><span class='line'><span class="p">(</span><span class="k">fn </span><span class="p">[</span><span class="nv">n</span><span class="p">]</span>
</span><span class='line'> <span class="p">(</span><span class="nb">take </span><span class="nv">n</span>
</span><span class='line'> <span class="p">(</span><span class="nb">map </span><span class="nv">first</span>
</span><span class='line'> <span class="p">(</span><span class="nb">iterate </span>
</span><span class='line'> <span class="p">(</span><span class="k">fn </span><span class="p">[[</span><span class="nv">a</span> <span class="nv">b</span><span class="p">]]</span>
</span><span class='line'> <span class="p">(</span><span class="nb">vector </span><span class="nv">b</span> <span class="p">(</span><span class="nb">+ </span><span class="nv">a</span> <span class="nv">b</span><span class="p">)))</span> <span class="p">[</span><span class="mi">1</span> <span class="mi">1</span><span class="p">])))))</span>
</span></code></pre></td></tr></table></div></figure>
<p>Okay, maybe not as “pretty” as Ruby, but Clojure has its own amazing properties I can’t even begin to go into… but I will be posting more on Clojure in the future.</p>
<p>Anyhow, I just mentioned that implementing an accumulator generator in Clojure is “less straightforward” than in a language like Python or Ruby (or, for that matter, Lisps like Scheme or Common Lisp). Why is this? As I mentioned previously, Clojure, while technically an “impure” functional language (as in, side-effects are allowed), tries to keep side-effects to the side as a special case; so, for instance, most data structures in Clojure are immutable.</p>
<p>“Wait,” you might exclaim, “that seems harder to work with! Aren’t immutable data structures introducing complexity!?!?”</p>
<p>Clearly, if you share this opinion, you’ve never tried to deal with concurrency. Clojure’s preference for immutable data structures isn’t <em>easier</em> than the usual acceptance of side-effects; but it is <em>simpler.</em> Making me think before I do an operation for side-effects in effect makes me think hard about many cases where I have an opportunity to complect my code.</p>
<p>I’ve heard the argument that Python’s bondage-and-discipline approach to programmer freedom is comparable, but I call shenanigans. It’s too much to go into here, but I think another day I’ll go into everything that’s wrong with “The Zen of Python.”</p>
<p>Anyhow… I thought these preliminary thoughts on what simplicity really means would be a good start for a blog entitled <em>Practical Elegance.</em></p>
</div>
</article>
<article>
<header>
<h1 class="entry-title"><a href="/blog/2012/05/08/starting-over/">Starting Over</a></h1>
<p class="meta">
<time datetime="2012-05-08T09:46:00-04:00" pubdate data-updated="true">2012-05-08</time>
</p>
</header>
<div class="entry-content"><p>I decided to retire my old blog, which had devolved into a platform for rants rather than anything truly worthwhile… to me, anyhow. Sure, my rants were amusing at times, and people seemed to enjoy them, but that’s not the point of blogging for me.</p>
<p>I want to talk about things that really matter, which (for me) includes simple, powerful code that works the way it is intended to.</p>
<p>So, trying this blogging thing again.</p>
</div>
</article>
<div class="pagination">
<a href="/blog/archives">Blog Archives</a>
</div>
</div>
<aside class="sidebar">
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/blog/2012/05/08/simplicity/">Simplicity</a>
</li>
<li class="post">
<a href="/blog/2012/05/08/starting-over/">Starting Over</a>
</li>
</ul>
</section>
<section>
<h1>GitHub Repos</h1>
<ul id="gh_repos">
<li class="loading">Status updating…</li>
</ul>
<a href="https://github.com/canweriotnow">@canweriotnow</a> on GitHub
<script type="text/javascript">
$.domReady(function(){
if (!window.jXHR){
var jxhr = document.createElement('script');
jxhr.type = 'text/javascript';
jxhr.src = '/javascripts/libs/jXHR.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(jxhr, s);
}
github.showRepos({
user: 'canweriotnow',
count: 0,
skip_forks: true,
target: '#gh_repos'
});
});
</script>
<script src="/javascripts/github.js" type="text/javascript"> </script>
</section>
<section>
<h1>Latest Tweets</h1>
<ul id="tweets">
<li class="loading">Status updating…</li>
</ul>
<script type="text/javascript">
$.domReady(function(){
getTwitterFeed("canweriotnow", 4, false);
});
</script>
<script src="/javascripts/twitter.js" type="text/javascript"> </script>
<a href="http://twitter.com/canweriotnow" class="twitter-follow-button" data-show-count="false">Follow @canweriotnow</a>
</section>
<section>
<h1>On Delicious</h1>
<div id="delicious"></div>
<script type="text/javascript" src="http://feeds.delicious.com/v2/json/canweriotnow?count=3&sort=date&callback=renderDeliciousLinks"></script>
<p><a href="http://delicious.com/canweriotnow">My Delicious Bookmarks »</a></p>
</section>
<section class="googleplus">
<h1>
<a href="https://plus.google.com/110736810583208350607?rel=author">
<img src="http://www.google.com/images/icons/ui/gprofile_button-32.png" width="32" height="32">
Google+
</a>
</h1>
</section>
</aside>
</div>
</div>
<footer role="contentinfo"><p>
Copyright © 2012 - Jason Lewis -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
</p>
</footer>
<script type="text/javascript">
var disqus_shortname = 'canweriotnow';
var disqus_script = 'count.js';
(function () {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script;
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
}());
</script>
<script type="text/javascript">
(function() {
var script = document.createElement('script'); script.type = 'text/javascript'; script.async = true;
script.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(script, s);
})();
</script>
<script type="text/javascript">
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>
</body>
</html>