<?xml version="1.0" encoding="UTF-8"?>
<post>
  <body>&lt;p&gt;I always thought the bang sign (!) in Ruby methods were meant to say: &quot;I'm destructive, I'll change your object&quot;. Like this:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;
def do_something
end

def do_something!
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now I know better. Actually the bang sign (!) is only meant to give you and other developers a warning, like &quot;I'm more dangerous than the other version, the non-bang one.&quot;&lt;/p&gt;

&lt;h2&gt;Which methods should have a bang sign?&lt;/h2&gt;

&lt;p&gt;Matz says, on January 28, 2009 (EST):&lt;/p&gt;

&lt;p&gt;The bang (!) does not mean &quot;destructive&quot; nor lack of it mean non destructive either.  The bang sign means &quot;the bang version is more dangerous than its non bang counterpart; handle with care&quot;.  Since Ruby has a lot of &quot;destructive&quot; methods, if bang signs follow your opinion, every Ruby program would be full of bangs, thus ugly.&lt;/p&gt;

&lt;p&gt;And I (David A. Black) say:&lt;/p&gt;

&lt;p&gt;So please stop writing bang methods that have no non-bang equivalent! The bang in isolation literally means nothing. It's purely ornamental, and dilutes the conventional usage (see above) to the point where it's
unrecognizable and pointless.&lt;/p&gt;

&lt;p&gt;(Exception: things like Builder, where the bang/non-bang distinction is completely redefined, and documented as having been redefined, for the sake of domain-specific semantics.)&lt;/p&gt;

&lt;p&gt;Source: &lt;a href=&quot;http://www.wobblini.net/bang.txt&quot;&gt;this comment&lt;/a&gt;.&lt;/p&gt;</body>
  <comments-count type="integer">35</comments-count>
  <created-at type="datetime">2009-02-01T21:52:59Z</created-at>
  <id type="integer">16</id>
  <permalink nil="true"></permalink>
  <slug></slug>
  <title>Which methods in Ruby should contain a bang sign?</title>
  <updated-at type="datetime">2009-02-02T10:56:22Z</updated-at>
  <user-id type="integer" nil="true"></user-id>
</post>
