-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatom.xml
More file actions
594 lines (530 loc) · 35.7 KB
/
atom.xml
File metadata and controls
594 lines (530 loc) · 35.7 KB
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[Coding in an absurd reality]]></title>
<link href="http://Confusion.github.com/atom.xml" rel="self"/>
<link href="http://Confusion.github.com/"/>
<updated>2013-01-31T21:39:53+01:00</updated>
<id>http://Confusion.github.com/</id>
<author>
<name><![CDATA[Ivo Wever]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[We still have a long way to go]]></title>
<link href="http://Confusion.github.com/blog/2011/02/17/we-still-have-a-long-way-to-go/"/>
<updated>2011-02-17T00:00:00+01:00</updated>
<id>http://Confusion.github.com/blog/2011/02/17/we-still-have-a-long-way-to-go</id>
<content type="html"><![CDATA[<blockquote><p>Enlightenment, science, democracy and equal opportunity are still the
true rebels, reigning for just a few generations (and still
imperfectly) in one or two corners of the Earth, after elite chiefs,
romantic bards and magicians dominated our ancestors for maybe half a
million years.</p></blockquote>
<p>— David Brin, in <a href="http://dir.salon.com/story/ent/feature/2002/12/17/tolkien_brin/print.html">J.R.R. Tolkien — enemy of progress</a></p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Identifying your Ruby implementation at runtime]]></title>
<link href="http://Confusion.github.com/blog/2010/08/05/identifying-your-ruby-implementation-at-runtime/"/>
<updated>2010-08-05T00:00:00+02:00</updated>
<id>http://Confusion.github.com/blog/2010/08/05/identifying-your-ruby-implementation-at-runtime</id>
<content type="html"><![CDATA[<p>There are a number of global variables available to determine, at runtime,
which Ruby implementation you are using. You can find most of these in
<code>Object.constants</code> and the most interesting ones are:</p>
<ul>
<li>RUBY_ENGINE,</li>
<li>RUBY_PLATFORM,</li>
<li>RUBY_VERSION and</li>
<li>PLATFORM</li>
</ul>
<p>Why would you want to know this? For instance to be able to load a Java library
when our code is running in JRuby, but fallback to some other library when we
are running in MRI or Rubinius. In my current use case: to run most specs in
MRI, which starts way faster than JRuby. Loading of Java-specific code is
surrounded by:</p>
<figure class='code'><figcaption><span></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='ruby'><span class='line'> <span class="k">if</span> <span class="no">RUBY_ENGINE</span> <span class="o">==</span> <span class="n">jruby</span>
</span><span class='line'> <span class="c1"># Load jars and stuff</span>
</span><span class='line'> <span class="k">else</span>
</span><span class='line'> <span class="n">logger</span><span class="o">.</span><span class="n">warn</span> <span class="s2">"Running in stubbed mode: only useful for specs that</span>
</span><span class='line'><span class="s2"> dont exercise the actual database connection."</span>
</span><span class='line'> <span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Ruby has only one kind of method and one kind of method container]]></title>
<link href="http://Confusion.github.com/blog/2010/08/01/ruby-has-only-one-kind-of-method-and-one-kind-of-method-container/"/>
<updated>2010-08-01T00:00:00+02:00</updated>
<id>http://Confusion.github.com/blog/2010/08/01/ruby-has-only-one-kind-of-method-and-one-kind-of-method-container</id>
<content type="html"><![CDATA[<p>While learning Ruby, I found the talk of classes, modules, eigenclasses (also
known as singleton classes or metaclasses), instance methods, class methods and
singleton methods (also known as eigenmethods) pretty confusing. Fortunately,
when you put everything together<sup>[1]</sup>, it turns out to be very simple: Ruby has
only one kind of methods, which are instance methods of modules. The methods
that are accessible to an object, are the instance methods of its eigenclass
and the superclasses of the eigenclass.</p>
<p>If you’re thinking “no, Ruby also has class methods or singleton methods”: as
Ola Bini shows in <a href="http://ola-bini.blogspot.com/2006/09/ruby-singleton-class.html">his article on singleton classes</a>:
defining a class method or singleton method is identical to defining an instance
method on its eigenclass. Now if you define the method using either syntax, then
where does this method actually live? Both:</p>
<figure class='code'><figcaption><span></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>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="no">C1</span><span class="o">.</span><span class="n">singleton_methods</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># and</span>
</span><span class='line'>
</span><span class='line'><span class="p">(</span><span class="k">class</span> <span class="o"><<</span> <span class="no">C1</span><span class="p">;</span> <span class="nb">self</span><span class="p">;</span> <span class="k">end</span><span class="p">)</span><span class="o">.</span><span class="n">instance_methods</span>
</span></code></pre></td></tr></table></div></figure>
<p>will report the method, but of course only one instance of this method exists.
The <a href="http://rubini.us/">Rubinius</a> implementation of Ruby reflects this:</p>
<figure class='code'><figcaption><span></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='ruby'><span class='line'><span class="k">def</span> <span class="nf">singleton_methods</span><span class="p">(</span><span class="n">all</span><span class="o">=</span><span class="kp">true</span><span class="p">)</span>
</span><span class='line'> <span class="n">mt</span> <span class="o">=</span> <span class="no">Rubinius</span><span class="o">.</span><span class="n">object_metaclass</span><span class="p">(</span><span class="nb">self</span><span class="p">)</span><span class="o">.</span><span class="n">method_table</span>
</span><span class='line'> <span class="nb">methods</span> <span class="o">=</span> <span class="p">(</span><span class="n">all</span> <span class="p">?</span> <span class="n">mt</span><span class="o">.</span><span class="n">names</span> <span class="p">:</span> <span class="n">mt</span><span class="o">.</span><span class="n">public_names</span> <span class="o">+</span> <span class="n">mt</span><span class="o">.</span><span class="n">protected_names</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'> <span class="no">Rubinius</span><span class="o">.</span><span class="n">convert_to_names</span> <span class="nb">methods</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>
<p>When you ask for the singleton methods of a class, you get the methods (the
method_table) of its metaclass.</p>
<p>The consequence of this is that it gets much easier to reason about the
behavior of <a href="http://ruby-doc.org/core/classes/Object.html#M000335">extend</a> and
<a href="http://ruby-doc.org/core/classes/Module.html#M001638">include</a>: extending a
module is equivalent to adding its instance methods to the instance methods of
the eigenclass of the extending module. That you can access them via
<code>ExtendingModule.module_instance_method</code> is merely syntactical sugar.</p>
<p>Including a module is equivalent to adding the module’s instance methods to the
instance methods of the class. The instance methods of a class are accessible
to instances of the class, which is how an instance can have access to the
included module’s instance methods.</p>
<p>Examples:</p>
<figure class='code'><figcaption><span></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>
<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>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">module</span> <span class="nn">M1</span>
</span><span class='line'> <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">module_singleton_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.module_singleton_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'> <span class="k">def</span> <span class="nf">module_instance_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.module_instance_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'> <span class="k">class</span> <span class="o"><<</span> <span class="nb">self</span>
</span><span class='line'> <span class="k">def</span> <span class="nf">module_eigenclass_instance_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.module_eigenclass_instance_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'> <span class="k">if</span> <span class="o">!</span><span class="nb">instance_methods</span><span class="o">.</span><span class="n">include?</span> <span class="n">module_singleton_method</span>
</span><span class='line'> <span class="k">raise</span> <span class="no">StandardError</span><span class="p">,</span> <span class="s2">"This wont happen."</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">module</span> <span class="nn">M2</span><span class="p">;</span> <span class="kp">extend</span> <span class="no">M1</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">module</span> <span class="nn">M3</span><span class="p">;</span> <span class="kp">include</span> <span class="no">M1</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">module</span> <span class="nn">M4</span><span class="p">;</span> <span class="kp">extend</span> <span class="no">M3</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># Everything that raises an Error is commented</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># You cant subclass a module:</span>
</span><span class='line'><span class="c1"># module M5 < M1; end</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># You cant instantiate modules: Module doesnt have a new method.</span>
</span><span class='line'><span class="c1"># M1.new</span>
</span><span class='line'>
</span><span class='line'><span class="nb">puts</span> <span class="s2">"Accessing methods through an instance of Module"</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">M1</span><span class="o">.</span><span class="n">module_singleton_method</span>
</span><span class='line'><span class="c1"># puts M1.module_instance_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">M1</span><span class="o">.</span><span class="n">module_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts M2.module_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">M2</span><span class="o">.</span><span class="n">module_instance_method</span>
</span><span class='line'><span class="c1"># puts M2.module_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts M3.module_singleton_method</span>
</span><span class='line'><span class="c1"># puts M3.module_instance_method</span>
</span><span class='line'><span class="c1"># puts M3.module_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts M4.module_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">M4</span><span class="o">.</span><span class="n">module_instance_method</span>
</span><span class='line'><span class="c1"># puts M4.module_eigenclass_instance_method</span>
</span></code></pre></td></tr></table></div></figure>
<p>What can we conclude from this?</p>
<ul>
<li>You cannot access a module’s instance methods, except by extending the
module. When you extend a module, its instance methods are added as
instance methods to the eigenclass of the extending module. In the
example, M1’s instance methods become instance methods of M2’s
eigenclass.</li>
<li>Including a module into another module makes the instance methods of the
included module available as instance methods in the including module.
This may seem pointless, because you still can’t access them, but
subsequently extending the including module also makes the included
module’s methods available to the extending module. In the example, M1’s
instance methods were added to M3’s and through the extend they became to
M4.</li>
<li>Defining a singleton method on a module has exactly the same result as
defining an instance method on a module’s eigenclass. Neither extending
nor including the module will make the instance methods of its eigenclass
available to the extending or including module.</li>
<li>You can only inherit from a class, not from a module.</li>
</ul>
<p>For classes, it’s pretty much the same:</p>
<figure class='code'><figcaption><span></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>
<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>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
<span class='line-number'>49</span>
<span class='line-number'>50</span>
<span class='line-number'>51</span>
<span class='line-number'>52</span>
<span class='line-number'>53</span>
<span class='line-number'>54</span>
<span class='line-number'>55</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">class</span> <span class="nc">C1</span>
</span><span class='line'> <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">class_singleton_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.class_singleton_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'> <span class="k">def</span> <span class="nf">class_instance_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.class_instance_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'> <span class="k">class</span> <span class="o"><<</span> <span class="nb">self</span>
</span><span class='line'> <span class="k">def</span> <span class="nf">class_eigenclass_instance_method</span>
</span><span class='line'> <span class="s2">"</span><span class="si">#{</span><span class="nb">self</span><span class="si">}</span><span class="s2">.module_eigenclass_instance_method"</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'> <span class="k">if</span> <span class="o">!</span><span class="nb">instance_methods</span><span class="o">.</span><span class="n">include?</span> <span class="n">class_singleton_method</span>
</span><span class='line'> <span class="k">raise</span> <span class="no">StandardError</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'> <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">C2</span> <span class="o"><</span> <span class="no">C1</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">C3</span><span class="p">;</span> <span class="kp">extend</span> <span class="no">M1</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nc">C4</span><span class="p">;</span> <span class="kp">include</span> <span class="no">M1</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># class C5; extend C1; end</span>
</span><span class='line'><span class="c1"># class C6; include C1; end</span>
</span><span class='line'>
</span><span class='line'><span class="nb">puts</span> <span class="s2">"Accessing methods through an instance of Class"</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C1</span><span class="o">.</span><span class="n">class_singleton_method</span>
</span><span class='line'><span class="c1"># puts C1.class_instance_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C1</span><span class="o">.</span><span class="n">class_eigenclass_instance_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C2</span><span class="o">.</span><span class="n">class_singleton_method</span>
</span><span class='line'><span class="c1"># puts C2.class_instance_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C2</span><span class="o">.</span><span class="n">class_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts C3.module_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C3</span><span class="o">.</span><span class="n">module_instance_method</span>
</span><span class='line'><span class="c1"># puts C3.module_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts C4.module_singleton_method</span>
</span><span class='line'><span class="c1"># puts C4.module_instance_method</span>
</span><span class='line'><span class="c1"># puts C4.module_eigenclass_instance_method</span>
</span><span class='line'>
</span><span class='line'><span class="nb">puts</span> <span class="s2">"Accessing methods through a class instance"</span>
</span><span class='line'><span class="c1"># puts C1.new.class_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C1</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">class_instance_method</span>
</span><span class='line'><span class="c1"># puts C1.new.class_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts C2.new.class_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C2</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">class_instance_method</span>
</span><span class='line'><span class="c1"># puts C2.new.class_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts C3.new.module_singleton_method</span>
</span><span class='line'><span class="c1"># puts C3.new.module_instance_method</span>
</span><span class='line'><span class="c1"># puts C3.new.module_eigenclass_instance_method</span>
</span><span class='line'><span class="c1"># puts C4.new.module_singleton_method</span>
</span><span class='line'><span class="nb">puts</span> <span class="no">C4</span><span class="o">.</span><span class="n">new</span><span class="o">.</span><span class="n">module_instance_method</span>
</span><span class='line'><span class="c1"># puts C4.new.module_eigenclass_instance_method</span>
</span></code></pre></td></tr></table></div></figure>
<p>From this we can conclude:</p>
<ul>
<li>Instance methods of a class are accessible to each instance of the class.
Each instance has it’s own unique eigenclass, but when a method isn’t
found there, the next stop is the superclass of the eigenclass, which is
the object representing the same class we usually consider the class of
the instance.</li>
<li>You can only extend or include modules, not classes.</li>
<li>When a class extends a module, the module’s instance methods are added to
the instance methods of the class’s eigenclass. Since classes are
modules, this is exactly as expected.</li>
<li>Including a module into a class makes the module’s instance methods
available to all instances of the class.</li>
</ul>
<hr />
<p><sup>[1]</sup> With a little help from the excellent:
<a href="http://pragprog.com/titles/ppmetr/metaprogramming-ruby">Metaprogramming Ruby</a> by Paolo Perrotta</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Drowning Doesn't Look Like Drowning]]></title>
<link href="http://Confusion.github.com/blog/2010/07/08/drowning-doesnt-look-like-drowning/"/>
<updated>2010-07-08T00:00:00+02:00</updated>
<id>http://Confusion.github.com/blog/2010/07/08/drowning-doesnt-look-like-drowning</id>
<content type="html"><![CDATA[<p><a href="http://mariovittone.com/2010/05/154/">Something everyone should know</a> when
someone is drowning, it doesn’t look
the way it is portrayed in movies. Especially children are known
to drown within reach of others, because everyone, even their parents, are
unaware something is wrong.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[TipsAndTricks/TextBasedLinuxInstall - Dropbox Wiki]]></title>
<link href="http://Confusion.github.com/blog/2010/02/26/tipsandtrickstextbasedlinuxinstall---dropbox-wiki/"/>
<updated>2010-02-26T00:00:00+01:00</updated>
<id>http://Confusion.github.com/blog/2010/02/26/tipsandtrickstextbasedlinuxinstall—dropbox-wiki</id>
<content type="html"><![CDATA[<p>Wow, there’s actually <a href="http://wiki.dropbox.com/TipsAndTricks/TextBasedLinuxInstall">a Linux CLI version of DropBox</a>.
Amazing!</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[A Few Billion Lines of Code Later: Using Static Analysis to Find Bugs in the Real World]]></title>
<link href="http://Confusion.github.com/blog/2010/02/13/a-few-billion-lines-of-code-later/"/>
<updated>2010-02-13T00:00:00+01:00</updated>
<id>http://Confusion.github.com/blog/2010/02/13/a-few-billion-lines-of-code-later</id>
<content type="html"><![CDATA[<p><a href="http://cacm.acm.org/magazines/2010/2/69354-a-few-billion-lines-of-code-later/fulltext">A very interesting story</a>
about the practical problems the guys that developed <a href="http://www.coverity.com/">Coverity’s</a>
static analysis tool encountered. Shows the difference between
academic theory and practice, but applies just as much to any theory developers
usually have about a software application, before actual customers start using
it.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Schneier on Security: Man-in-the-Middle Attack Against Chip and PIN]]></title>
<link href="http://Confusion.github.com/blog/2010/02/12/schneier-on-security-man-in-the-middle-attack-against-chip-and-pin/"/>
<updated>2010-02-12T00:00:00+01:00</updated>
<id>http://Confusion.github.com/blog/2010/02/12/schneier-on-security-man-in-the-middle-attack-against-chip-and-pin</id>
<content type="html"><![CDATA[<p><a href="http://www.schneier.com/blog/archives/2010/02/man-in-the-midd_1.html">As Bruce says</a>:</p>
<blockquote><p>This is big.</p></blockquote>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[The Twitter Engineering Blog: Hello World]]></title>
<link href="http://Confusion.github.com/blog/2010/02/10/the-twitter-engineering-blog-hello-world/"/>
<updated>2010-02-10T00:00:00+01:00</updated>
<id>http://Confusion.github.com/blog/2010/02/10/the-twitter-engineering-blog-hello-world</id>
<content type="html"><![CDATA[<p><a href="http://engineering.twitter.com/2010/02/hello-world.html">Funky animation</a> that
shows how the code in the Twitter repository grew the past few years.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Lisp evangelists that miss the point about syntax]]></title>
<link href="http://Confusion.github.com/blog/2010/02/03/lisp-evangelists-that-miss-the-point-about-syntax/"/>
<updated>2010-02-03T00:00:00+01:00</updated>
<id>http://Confusion.github.com/blog/2010/02/03/lisp-evangelists-that-miss-the-point-about-syntax</id>
<content type="html"><![CDATA[<p>People that promote Lisp usually tout the fact that you can construct new
syntax as one of its powerful features. However, when it comes to any other
programming language, a number of these people will say that the language is
wrong, because it has too much syntax. As any syntax seems to be too much, the
complaint about the syntax is actually a red herring. The real complaint is:
this language isn’t Lisp and I can’t ‘drop down’ to a lower level to adjust the
syntax to my needs.</p>
<p>As many people in <a href="http://news.ycombinator.com/item?id=1097911">this thread</a>,
which inspired this post, point out: the
ability to create syntax is powerful, exactly because syntax increases the
usability of the language for your specific purpose. So why not create syntax
that catches 99% of the cases for which you intend the language to be used and
abolish the ability to create further syntax? The ability to create syntax
comes at a cost and the existence of so many other programming languages shows
one thing very clearly: not everyone is willing to pay that cost. Why can’t we
live with that fact, use Lisp when we need it or want to and
stop criticizing other languages for not being Lisp?</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Writers and editors: don't make me feel stupid!]]></title>
<link href="http://Confusion.github.com/blog/2010/01/20/writers-and-editors-dont-make-me-feel-stupid/"/>
<updated>2010-01-20T00:00:00+01:00</updated>
<id>http://Confusion.github.com/blog/2010/01/20/writers-and-editors-dont-make-me-feel-stupid</id>
<content type="html"><![CDATA[<p>Imagine you don’t know what a <a href="http://en.wikipedia.org/wiki/Web_service">web_service</a> is, but you’ve heard someone talking
about them and you are interested in knowing more about them. You click the
link in the previous sentence and are told</p>
<pre><code> Web services today are frequently just Application Programming
Interfaces (API) or web APIs that can be accessed over a network,
such as the Internet, and executed on a remote system hosting the
requested services.
</code></pre>
<p>That didn’t make any sense to you, but you continued reading and made it to</p>
<pre><code> The W3C defines a “web service” as “a software system designed to
support interoperable machine-to-machine interaction over a network.
</code></pre>
<p>which started to make a bit of sense. However, as you weren’t particularly
enlightened yet, you enter ‘What_is_a_webservice’ into Google and read other
<a href="http://www.google.com/search?ie=UTF-8&q=what+is+a+web+service">‘explanations’</a> like the one from <a href="http://www.webopedia.com/TERM/W/Web_Services.html">Webopedia</a>:</p>
<pre><code> The term Web services describes a standardized way of integrating
Web-based applications using the XML, SOAP, WSDL and UDDI open
standards over an Internet protocol backbone. XML is used to tag the
data, SOAP is used to transfer the data, WSDL is used for describing
the services available and UDDI is used for listing what services are
available. Used primarily as a means for businesses to communicate
with each other and with clients, Web services allow organizations to
communicate data without intimate knowledge of each other’s IT
systems behind the firewall.
</code></pre>
<p>There’s not a doubt on my mind that most people are now left feeling stupid and
confused. This is a very bad thing, because it discourages people from
learning: if it is impossible to find a decent introduction to a subject,
surely it’s either too hard or too obscure?
There are several possible explanations for why these introductions are so bad:</p>
<ul>
<li>Perhaps it is simply too hard to introduce a subject using common English
terms?</li>
<li>Perhaps the authors have an advanced understanding of the subject, but
not of writing for a general audience?</li>
<li>Perhaps they suffer from the disease of overuse of jargon to which people
in every profession fall prey?</li>
<li>Perhaps they feel the quality of an article suffers when a web service
would be introduced in terms a layman could follow, like
<pre><code>A web service is a service offered by a piece of software that allows
one computer to receive and answer requests for information from
other computers over a network
</code></pre></li>
</ul>
<p>I’m not sure which of these reasons is dominant, but even if all of them hold
for the authors: surely there is at least one editor that realizes it should be
thumbed down and can explain how and why?</p>
<p>What motivated me to write this article was the fact that, for the first time,
I had to use WS-Addressing and WS-Security in a web service client and the
first question that came to mind was: “why do we need these”? After figuring
that out, I concluded that the explanations on Wikipedia and other high-ranking
search results really didn’t give me the answers I was looking for.</p>
<p>Firstly they suffered from the problems described in the beginning of this post, but
secondly: the explanations never went into the ‘why’ of these things. They all
just explained the ‘what’ and the ‘how’. This is what the Wikipedia
introduction on WS-Addressing currently says:</p>
<pre><code> WS-Addressing or Web Services Addressing is a specification of
transport-neutral mechanisms that allow web services to communicate
addressing information. It essentially consists of two parts: a
structure for communicating a reference to a Web service endpoint,
and a set of Message Addressing Properties which associate addressing
information with a particular message.
</code></pre>
<p>Now I don’t like feeling stupid and I don’t like having to think longer than is
strictly necessary to understand something and this causes both. Why wouldn’t
something like the following do?</p>
<pre><code> The motivation for WS-Addressing is that you want to allow clients to
invoke a web service using address A, while the web service itself
lives at address B. This allows you to, for instance, use address A
as a front door to web services at addresses B, C, D and E, while
having the software at address A perform routing, validation,
authentication, etc. for all these other web services. It also allows
you more freedom in your web service addresses, because they don’t
need to be URL’s that are reachable over the network: only address A
needs to be ‘real’.
</code></pre>
<p>Secondly, a FAQ or the like should answer the obvious question: can’t you solve
this in some other way?</p>
<pre><code> Of course you can come up with your own scheme to obtain the same
goal, but one downside to that is that the software at address A
would have to be able to deal with different homegrown
implementations of the same general principle, if it were to allow
access to web services of different origins. Another downside is that
you may initially overlook functionality, that proves harder to ‘tack
on’ later. That’s why Microsoft, IBM, Sun, BEA and SAP, under the
auspices of the W3C, came up with a single standard, which contains
specifications for all scenarios they could think of.
</code></pre>
]]></content>
</entry>
</feed>