{"id":281,"date":"2012-08-09T11:08:06","date_gmt":"2012-08-09T11:08:06","guid":{"rendered":"http:\/\/nicholshayes.co.uk\/blog\/?p=281"},"modified":"2016-04-29T21:15:18","modified_gmt":"2016-04-29T21:15:18","slug":"comments-in-gemfile","status":"publish","type":"post","link":"http:\/\/nicholshayes.co.uk\/blog\/?p=281","title":{"rendered":"Comments in Gemfile"},"content":{"rendered":"<p>I wish people would take a little time to consider the best way to arrange and comment the gem insertions in Gemfile.<\/p>\n<p>I am not a great fan of commenting. I believe you should code so that it is easily readable without comments. When I see comments, I tend to think &#8220;There&#8217;s a bit of code that the developer doesn&#8217;t think people will be able to understand&#8221;. Commented methods are usually the ones in prime need of refactoring.<\/p>\n<p>However, there are times where you have little option but to use unintuitive code patterns and a short comment is then required.<\/p>\n<p>One of the best examples of this, and one where I rarely see any comments is the Gemfile. All the team developed rails apps I have worked on, have a range of different gems. I sometimes wonder whether most rails developers measure their skill level on the number of gems they can add to the Gemfile. It&#8217;s certainly become an interview criteria!<\/p>\n<p>Many gems have functionality that is not obvious from their name. For example, nokogiri (Japanese symbol for &#8216;saw&#8217; I believe), is not a name that makes it obvious to me that it is an html parser. I do not think that is the fault of the gem developer. You have to come up with a unique name, and that is not easy. Especially if you want to make it memorable.<\/p>\n<p>It is usually fairly easy to find the gem&#8217;s project in github and\/or via a google search, and then to find out what it does. It is very rare for a commonly used gem not to have at least a basic description of its functionality in its README (polyamorous being one exception).<\/p>\n<p>The problem is do you really want to have to look up every gem README when you are scanning through a Gemfile looking for where some functionality you don&#8217;t recognise, may be added. Some short comments can make this task so much easier.<\/p>\n<p>I&#8217;m working on an application that uses Postgres, and the models are being queried with search_by_title_and_body, and I couldn&#8217;t see where the search_by functionality was coming in. It took me a few minutes looking through the Gemfile and look up READMEs, to find that &#8216;texticle&#8217; was the source. This was far down in the Gemfile and amongst unrelated gems.<\/p>\n<p>So I moved it to the &#8216;pg&#8217; gem declaration and added a comment. I did the same for &#8216;activerecord-postgis-adapter&#8217;:<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">gem 'pg'<br \/>\ngem 'activerecord-postgis-adapter' # Adds postgres spatial querying to active record<br \/>\ngem 'texticle', '~&amp;gt; 2.0', :require =&amp;gt; 'texticle\/rails' # Adds postgres search tools to active record<\/div><\/div>\n<p>Now I hope the next developer who reads the Gemfile, will find it a little easier to identify the functionality being added by these gems.<\/p>\n<h2>Update<\/h2>\n<p>There is now a gem call <strong><a href=\"https:\/\/github.com\/ivantsepp\/grub\">grub<\/a><\/strong>, that will automatically add comments to you Gemfile. I&#8217;d highly recommend you have a look at it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I wish people would take a little time to consider the best way to arrange and comment the gem insertions in Gemfile. I am not a great fan of commenting. I believe you should code so that it is easily &hellip; <a href=\"http:\/\/nicholshayes.co.uk\/blog\/?p=281\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/281"}],"collection":[{"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=281"}],"version-history":[{"count":9,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/281\/revisions"}],"predecessor-version":[{"id":558,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/281\/revisions\/558"}],"wp:attachment":[{"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=281"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nicholshayes.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}