Just A Summary : Baby's first screencast http://bofh.org.uk/articles/2008/03/14/babys-first-screencast.rss en-us 40 Piers Cawley Practices Punditry Comment on Baby's first screencast by James Abley <p>That&#8217;s quite cool. I&#8217;m almost inspired to pick up Ruby in more depth, since that uses some language features that I&#8217;ve not gone deep enough to encounter yet. I look forward to seeing a more in-depth version.</p> <p>And don&#8217;t worry about the typos, I&#8217;ve got far worse fat fingers than that!</p> Fri, 14 Mar 2008 17:08:39 -0500 urn:uuid:db46a849-7450-4442-b2a8-29c996de344a http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comment-1345 Comment on Baby's first screencast by Piers Cawley <p>What I&#8217;d really like to do is to write:</p> <pre><code>class Whatever use :laissez_faire_nils ... end</code></pre> <p>and have all the methods I define in that class definition use an Objective C style nil. For bonus points, if someone reopens the class, they shouldn&#8217;t get that style of nils unless they explicitly ask for them again. However, I think the only way to do something like that would be to use an explicit block:</p> <pre><code>class Whatever with(:laissez_faire_nils) { def some_method ... end } end</code></pre> <p>Mutter&#8230; <code>{}</code> isn&#8217;t right there. But then wrapping <code>do ... end</code> around a block of purely declarative code just feels ugly too. If only there were some way of implementing new block methods, so we could write:</p> <pre><code>with(:whatever) ... end</code></pre> <p>Lisp style macros rock&#8230;</p> Sat, 15 Mar 2008 06:21:40 -0500 urn:uuid:d1a0603e-c15a-4232-b934-a324dbb198df http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comment-1346 Comment on Baby's first screencast by Kevin Ballard <p>I&#8217;m a fan of <code>try(:method)</code>, as in</p> <pre><code>foo.try(:bar).try(:baz)</code></pre> <p>It&#8217;s also really simple to implement</p> <pre><code>class Object def try(name, *args) method(name).call *args end end class NilClass def try(name, *args) nil end end</code></pre> Sat, 15 Mar 2008 10:13:47 -0500 urn:uuid:3a6906c4-5e5c-4136-87e5-3e3b7af31173 http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comment-1347 Comment on Baby's first screencast by Aristotle Pagaltzis <p>Piers, I don’t think that code is right. Your modification of @nil@’s behaviour is temporally scoped, whereas it should be lexically scoped.</p> Sat, 15 Mar 2008 11:58:27 -0500 urn:uuid:b715926a-ad54-4cc4-801b-d3d1d90c21bc http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comment-1348 Comment on Baby's first screencast by Tom Moertel <p>You might want to reconsider the requirement that &#8220;<em>maybe</em>(3) {<em>nil</em>} should be <em>nil</em>,&#8221; especially if you&#8217;re using the Maybe monad as inspiration. Without that requirement, the semantics of <em>maybe</em>(<em>z_) {_e</em>} are straightforward: <em>nil</em> represents failure.</p> <p>If you add that requirement, however, failure is represented by attempting to call a non-existent method on a <em>nil</em> value. Such failure semantics result in unintuitive inconsistencies. Consider, for example, the following chain:</p> <pre><code>maybe(3) { e1.e2.e3.e4 }</code></pre> <p>If <em>e1</em>, <em>e2</em>, or <em>e3</em> fails (i.e., returns <em>nil</em>), the entire computation <em>e1.e2.e3.e4</em> fails and thus the result of the <em>maybe</em> computation is 3. If, however, only <em>e4</em> fails, the entire computation <em>e1.e2.e3.e4</em> somehow &#8220;succeeds&#8221; (with the result of <em>nil</em>), which seems inconsistent. Why should <em>nil</em> denote failure for all but the last element of the chain?</p> <p>It seems, then, that the requirement ought to be &#8220;<em>maybe</em>(3) {<em>nil</em>} should be 3&#8221;.</p> <p>Cheers,<br />Tom</p> Sat, 15 Mar 2008 16:12:56 -0500 urn:uuid:3ce03146-41cb-4bdb-994d-3669d8d455a2 http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comment-1349 Comment on Baby's first screencast by Piers Cawley <p>@Aristotle: Ugh! You&#8217;re right. I have the awful feeling that the only successful fix would involve changing the interface so that the first value is passed as the value to the block:</p> <pre><code>maybe(initial_value, default) {|it| it.should.return.the.default.if.nil.crops.up end</pre></code> <p>That way we can wrap the initial value in a proxy object before the block gets at it and wrap each intermediate value as well. I don&#8217;t like the interface so much though (even though it would end up working even more like a Haskell Maybe).</p> <p>@Tom: Ah yes, point taken.</p> Sun, 16 Mar 2008 16:48:19 -0500 urn:uuid:80258bfc-4cfb-41e7-983d-c814190b6212 http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comment-1350 Comment on Baby's first screencast by Daniel Berger <p>foo.bar.baz rescue nil</p> <p>Have a nice day.</p> Mon, 17 Mar 2008 13:32:57 -0500 urn:uuid:2468cfcb-c010-4ebd-a642-d34b97fd44f2 http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comment-1353 Comment on Baby's first screencast by Piers Cawley <p>@Daniel: If you want to shoot yourself in the foot, go ahead and do that. If, however, you&#8217;ve been there, done that and got the holes to prove it, you start wanting something a little more robust.</p> Tue, 18 Mar 2008 02:20:28 -0500 urn:uuid:59bf911c-47a7-4dbf-83f3-3e845e0c1e15 http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comment-1354 Comment on Baby's first screencast by loki <p>May be you could use:</p> <pre>if defined? foo.bar puts 'May be' end Sat, 12 Apr 2008 11:38:32 -0500 urn:uuid:0e645478-0df8-44d7-beec-13cf8131abff http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comment-1385 Comment on Baby's first screencast by Nando Vieira <p>An alternative to the maybe approach is something like this: <a href="http://pastie.caboo.se/206983" rel="nofollow">http://pastie.caboo.se/206983</a></p> Sun, 01 Jun 2008 20:40:46 -0500 urn:uuid:1cf4ef11-bf76-4e12-966b-0b562f517dca http://www.bofh.org.uk/articles/2008/03/14/babys-first-screencast#comment-1410