<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Segment7: David Black Explains Bang Methods</title>
    <link>http://blog.segment7.net/articles/2007/08/15/david-black-explains-bang-methods</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>The Blog</description>
    <item>
      <title>David Black Explains Bang Methods</title>
      <description>&lt;p&gt;I&amp;#8217;ve seen an explosion of silly bang methods that don&amp;#8217;t follow Ruby&amp;#8217;s usage, and I&amp;#8217;ve been meaning to write exactly this post:

&lt;blockquote cite="http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist"&gt;&lt;p&gt;In Ruby, you can write methods whose names end in ! (exclamation point or &amp;ldquo;bang&amp;rdquo;). There&amp;rsquo;s a lot of confusion surrounding the matter of when, and why, you would want to do so.

&lt;p&gt;The ! in method names that end with ! means, &amp;ldquo;This method is dangerous&amp;rdquo;&amp;mdash;or, more precisely, this method is the &amp;ldquo;dangerous&amp;rdquo; version of an otherwise equivalent method, with the same name minus the !. &amp;ldquo;Danger&amp;rdquo; is relative; the ! doesn&amp;rsquo;t mean anything at all unless the method name it&amp;rsquo;s in corresponds to a similar but bang-less method name.
&lt;/blockquote&gt;

&lt;p style="text-align: right"&gt;&amp;mdash;&lt;a href="http://dablog.rubypal.com/2007/8/15/bang-methods-or-danger-will-rubyist"&gt;Bang methods; or, Danger, Will Rubyist!&lt;/a&gt; via &lt;a href="http://dablog.rubypal.com/"&gt;DABlog&lt;/a&gt;
</description>
      <pubDate>Wed, 15 Aug 2007 11:23:07 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:c7a1978c-de7c-46cf-b826-f6d50caacdcc</guid>
      <author>drbrain@segment7.net (Eric Hodel)</author>
      <link>http://blog.segment7.net/articles/2007/08/15/david-black-explains-bang-methods</link>
      <category>Ruby</category>
    </item>
    <item>
      <title>"David Black Explains Bang Methods" by Nick Kallen</title>
      <description>&lt;p&gt;This might be the Ruby convention, and I&amp;#8217;m willing to follow it if so. I&amp;#8217;ve programmed in various dialects of LISP where ! means the procedure has a side-effect. I find that convention absolutely invaluable, and this vague notion of &amp;#8220;danger&amp;#8221; where ! disambiguates the &amp;#8220;safe&amp;#8221; from the &amp;#8220;dangerous&amp;#8221; method seems odd. I&amp;#8217;d rather the convention be more like in Scheme: Side-effect? bang!&lt;/p&gt;</description>
      <pubDate>Wed, 22 Aug 2007 21:47:17 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:0774c985-bbd1-4dd0-a38e-2602dc928d97</guid>
      <link>http://blog.segment7.net/articles/2007/08/15/david-black-explains-bang-methods#comment-757</link>
    </item>
    <item>
      <title>"David Black Explains Bang Methods" by David Black</title>
      <description>&lt;p&gt;James&amp;#8212;&lt;/p&gt;


	&lt;p&gt;Your impression is empirically correct - lots of destructive methods are !-methods - but that&amp;#8217;s not the fundamental meaning of the !. &amp;#8220;Dangerous&amp;#8221; can mean many things, and destructive methods may or may not have a !. The only ones that do are those that exist in a pair with a non-destructive counterpart.&lt;/p&gt;


	&lt;p&gt;There&amp;#8217;s also exit! which is an example of a non-destructive bang-method. It&amp;#8217;s the &amp;#8220;dangerous&amp;#8221; version of exit.&lt;/p&gt;


	&lt;p&gt;The ! convention is also something you can use in your own code. That&amp;#8217;s another good reason not to conflate it with &amp;#8220;destructive&amp;#8221;; that puts a limit on its use.&lt;/p&gt;</description>
      <pubDate>Wed, 15 Aug 2007 18:38:21 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:bde54554-4581-438f-bdaf-965d8852fa30</guid>
      <link>http://blog.segment7.net/articles/2007/08/15/david-black-explains-bang-methods#comment-741</link>
    </item>
    <item>
      <title>"David Black Explains Bang Methods" by Eric Hodel</title>
      <description>&lt;p&gt;In the ruby core, that&amp;#8217;s usually the case.&lt;/p&gt;


	&lt;p&gt;People have heard this self-modifying behavior described as &amp;#8220;dangerous&amp;#8221; without finding out the full meaning which typically is &amp;#8220;dangerous with respect to the non-bang version&amp;#8221;.&lt;/p&gt;</description>
      <pubDate>Wed, 15 Aug 2007 17:09:14 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:a72adccc-67b9-4f77-8a4f-4dbc69ae98b5</guid>
      <link>http://blog.segment7.net/articles/2007/08/15/david-black-explains-bang-methods#comment-740</link>
    </item>
    <item>
      <title>"David Black Explains Bang Methods" by James Hill</title>
      <description>&lt;p&gt;I was under the impression that in most cases the bang meant this method is going to modify this (self) object, and not just return a copy of the modified object. An example of this would be the String instance method capitalize.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
str = "hello" 
str.capitalize #=&amp;gt; "Hello" 
str #=&amp;gt; "hello" 

str.capitalize! #=&amp;gt; "Hello" 
str #=&amp;gt; "Hello" 
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Wed, 15 Aug 2007 15:59:23 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:efe67ab9-10f5-485b-a0ee-51f7952fed95</guid>
      <link>http://blog.segment7.net/articles/2007/08/15/david-black-explains-bang-methods#comment-739</link>
    </item>
    <item>
      <title>"David Black Explains Bang Methods" by Eric Hodel</title>
      <description>&lt;p&gt;The lack of a non-bang version of a method just makes me scratch my head.  In Ruby&amp;#8217;s core library the bang provides context to tell me that this method does something different, probably not what I want.  Indiscriminate use of the bang, especially when not paired with non-bang versions, provides me with no extra information.&lt;/p&gt;</description>
      <pubDate>Wed, 15 Aug 2007 15:51:24 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:a1d17e64-f75b-4d34-b8e6-41fa94712024</guid>
      <link>http://blog.segment7.net/articles/2007/08/15/david-black-explains-bang-methods#comment-738</link>
    </item>
    <item>
      <title>"David Black Explains Bang Methods" by David Black</title>
      <description>&lt;p&gt;Hi Pratik&amp;#8212;&lt;/p&gt;


	&lt;p&gt;The thing is, you should &lt;strong&gt;always&lt;/strong&gt; know what you&amp;#8217;re doing :-) Putting a ! on a subset of the methods you write, whether or not they are part of a &amp;#8220;dangerous/non-dangerous&amp;#8221; pair, just arbitrarily chooses some methods to provide a contextless warning for, and means that there&amp;#8217;s no real ! idiom or convention.&lt;/p&gt;</description>
      <pubDate>Wed, 15 Aug 2007 13:03:36 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:24ce145c-b561-4677-a817-4bad545c0f8c</guid>
      <link>http://blog.segment7.net/articles/2007/08/15/david-black-explains-bang-methods#comment-737</link>
    </item>
    <item>
      <title>"David Black Explains Bang Methods" by Pratik</title>
      <description>&lt;p&gt;I sort of disagree with the last statement that &amp;#8221;! doesn’t mean anything at all unless the method name it’s in corresponds to a similar but bang-less method name.&amp;#8221; For me it&amp;#8217;s like, before you&amp;#8217;re calling something that ends with !, know what you&amp;#8217;re doing. And make sure you&amp;#8217;re doing it right. What David said, is based on the assumption that your method names should reflect the &amp;#8220;danger&amp;#8221;. Well, that may not be always possible and it&amp;#8217;s a different issue altogether.&lt;/p&gt;</description>
      <pubDate>Wed, 15 Aug 2007 12:15:12 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:1236d49d-8ad4-4f9f-8187-37a77243dc14</guid>
      <link>http://blog.segment7.net/articles/2007/08/15/david-black-explains-bang-methods#comment-736</link>
    </item>
  </channel>
</rss>
