<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: SQL Super Hero</title>
    <description>The latest articles on DEV Community by SQL Super Hero (@sqlsuperhero).</description>
    <link>https://dev.to/sqlsuperhero</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4%2F1482899164846.jpeg</url>
      <title>DEV Community: SQL Super Hero</title>
      <link>https://dev.to/sqlsuperhero</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sqlsuperhero"/>
    <language>en</language>
    <item>
      <title>Quick Tip: Grepping Rails Routes</title>
      <dc:creator>SQL Super Hero</dc:creator>
      <pubDate>Sun, 14 Feb 2016 18:44:19 +0000</pubDate>
      <link>https://dev.to/sqlsuperhero/quick-tip-grepping-rails-routes</link>
      <guid>https://dev.to/sqlsuperhero/quick-tip-grepping-rails-routes</guid>
      <description>&lt;p&gt;It is probably safe to say that &lt;em&gt;most&lt;/em&gt; Rails developers today are working off either Linux or Mac. However, extensive knowledge of *nix command line tools is not usually required to be a proficient Rails dev. In todays tip, i'll be showing a super simple use case for the &lt;code&gt;grep&lt;/code&gt; command to quickly filter the routes output.&lt;/p&gt;

&lt;p&gt;As you probably know, &lt;code&gt;rake routes&lt;/code&gt; (also &lt;code&gt;rails routes&lt;/code&gt; in rails 5) prints a list of all routes in your application - simple enough. As a project grows however, the &lt;code&gt;routes.rb&lt;/code&gt; file can get pretty large fairly quickly. This can make finding the actual route you are looking for tough, especially after adding a few engines.&lt;/p&gt;

&lt;p&gt;The fix:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rake routes | grep KEYWORD&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This will filter the output of the lines to match your keyword.&lt;/p&gt;

&lt;p&gt;To return all routes related to a controller, simply add the name of the controller:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rake routes | grep users&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To return all routes with a specific HTTP Verb, simply add GET, POST, PATCH:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rake routes | grep GET&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;To return all routes related to an action:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rake routes | grep update&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Super simple, but I find it really useful.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>commandline</category>
    </item>
    <item>
      <title>Communicating Intent: The Perpetually Misunderstood Ruby Bang(!)</title>
      <dc:creator>SQL Super Hero</dc:creator>
      <pubDate>Thu, 11 Feb 2016 18:44:47 +0000</pubDate>
      <link>https://dev.to/sqlsuperhero/communicating-intent-the-perpetually-misunderstood-ruby-bang</link>
      <guid>https://dev.to/sqlsuperhero/communicating-intent-the-perpetually-misunderstood-ruby-bang</guid>
      <description>&lt;p&gt;As software projects grow, being able to demonstrate your intention to other developers through clear and reasonable code is paramount. In this series I cover short tips to do just that. The first article in the series can be found on my blog: &lt;a href="http://tombroomfield.com/communicating-intent-1-tap/"&gt;Ruby's Tap&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Today we cover the bang(!) symbol. In my opinion is one of the most common, yet misunderstood tactics for communicating intent to other developers. While subtle, it can actually be pretty useful when used consistently.&lt;/p&gt;

&lt;p&gt;The first thing to remember is that the &lt;code&gt;!&lt;/code&gt; in ruby, at the end of a method name, such as &lt;code&gt;save!&lt;/code&gt; does nothing special on it's own. It forms part of the method name and it's only purpose is to communicate something else about what that method might do.&lt;/p&gt;

&lt;p&gt;A quick google search will lead to a lot of incorrect information. For instance, &lt;a href="http://stackoverflow.com/a/612196"&gt;here&lt;/a&gt;, &lt;a href="http://stackoverflow.com/a/18801459"&gt;here&lt;/a&gt;, &lt;a href="http://stackoverflow.com/a/31598104"&gt;here&lt;/a&gt;, &lt;a href="http://stackoverflow.com/a/16301829"&gt;here&lt;/a&gt;, &lt;a href="http://stackoverflow.com/a/16301928"&gt;here&lt;/a&gt;, &lt;a href="http://stackoverflow.com/a/6208446"&gt;here&lt;/a&gt;, &lt;a href="http://stackoverflow.com/a/6208856"&gt;here&lt;/a&gt;, &lt;a href="http://stackoverflow.com/a/6208417"&gt;here&lt;/a&gt;, &lt;a href="http://stackoverflow.com/a/6260608"&gt;here&lt;/a&gt;, &lt;a href="http://stackoverflow.com/a/33923572"&gt;here&lt;/a&gt;, &lt;a href="http://qr.ae/RO9KE9"&gt;here&lt;/a&gt; and &lt;a href="http://www.wellho.net/mouth/2893_Exclamation-marks-and-question-marks-on-ruby-method-names.html"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;These all tell you that the bang symbol simply modifies the object in place. It certainly &lt;em&gt;does&lt;/em&gt; do this in some cases, but it is definitely &lt;em&gt;not&lt;/em&gt; what bang means. An example of this is &lt;code&gt;downcase&lt;/code&gt; vs &lt;code&gt;downcase!&lt;/code&gt;. The &lt;code&gt;downcase!&lt;/code&gt; will modify the existing string, while &lt;code&gt;downcase&lt;/code&gt; will return a new string.&lt;/p&gt;

&lt;p&gt;This is useful, however, the logic falls down very quickly. For example, the &lt;code&gt;pop&lt;/code&gt; method:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;a = [1,2,3]
a.pop
a #=&amp;gt; [1,2]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;&lt;code&gt;pop&lt;/code&gt; modified the array, but has no &lt;code&gt;!&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Another example is the &lt;code&gt;save/save!&lt;/code&gt; methods in Rails. &lt;code&gt;save&lt;/code&gt; returns &lt;code&gt;nil&lt;/code&gt; on a validation error, while &lt;code&gt;save!&lt;/code&gt; throws an error.&lt;/p&gt;

&lt;p&gt;In the &lt;a href="https://github.com/geekq/workflow"&gt;Workflow&lt;/a&gt; gem, you use &lt;code&gt;state!&lt;/code&gt; to move to a particular state.&lt;/p&gt;

&lt;p&gt;None of these methods have anything to do with modifying the object, so why are they using bang?&lt;/p&gt;

&lt;p&gt;Luckily Matz - the creator of Ruby - has something to say on the issue:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The bang (!) does not mean "destructive" nor lack of it mean non destructive either. The bang sign means "the bang version is more dangerous than its non bang counterpart; handle with care". Since Ruby has a lot of "destructive" methods, if bang signs follow your opinion, every Ruby program would be full of bangs, thus ugly.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;~ Yukihiro Matsumoto&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;&lt;a href="https://www.ruby-forum.com/topic/176830#773946"&gt;Source&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So there we go. Use bang when you have a method that has the potential to be more dangerous. I find it nice to leave a comment on any bang method, explaining the danger.&lt;/p&gt;

&lt;p&gt;Some good use cases for the bang:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Throwing an error on failure instead of returning nil.&lt;/li&gt;
&lt;li&gt;Forcing a fetch to bypass cache and recalculate.&lt;/li&gt;
&lt;li&gt;A method that hides a lot of complexity, or has performance implications.&lt;/li&gt;
&lt;li&gt;Any other method that has may cause side effects that may not be expected.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bang can be a fantastic tool for letting other developers know to proceed with caution, so use it when it makes sense. When exploring code, take special care to look out for these methods and ensure they are being used correctly. They can often reveal bugs or performance issues if the danger has not been respected.&lt;/p&gt;

</description>
      <category>ruby</category>
    </item>
  </channel>
</rss>
