<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[Important Shock]]></provider_name><provider_url><![CDATA[https://importantshock.wordpress.com]]></provider_url><author_name><![CDATA[Patrick Thomson]]></author_name><author_url><![CDATA[https://importantshock.wordpress.com/author/importantshock/]]></author_url><title><![CDATA[Why I Dig&nbsp;Objective-C]]></title><type><![CDATA[link]]></type><html><![CDATA[<p>I apologize if this entry is incoherent or trivial. But I need to build up the habit of blogging.</p>
<p>I recently picked up a copy of <a href="http://www.amazon.com/Refactoring-Improving-Design-Existing-Code/dp/0201485672">Refactoring</a>. I hadn&#8217;t heard of that book before I read Steve Yegge&#8217;s thoughts on it &#8211; indeed, my entire concept of refactoring had previously been limited to Eclipse&#8217;s built-in tools. To describe this book as an eye-opener would be an understatement; not only has it taught me many coding strategies (upon reading the entry for Introduce Null Object, I practically screamed &#8220;Why didn&#8217;t <em><strong>I</strong></em> think of that?&#8221;), but it&#8217;s also changed many of my ideas about the way I code.</p>
<p>Fowler&#8217;s clear, direct writing is one of the strengths of Refactoring; during the book, he introduces the concept of the <a href="http://en.wikipedia.org/wiki/Code_smell">code smell</a> &#8211; a term which I had not heard before, and which perfectly describes a situation with which I have been familiar ever since I started coding &#8211; and points out that a sure-fire sign of smelly code is the presence of many comments; if you need to explain a method in excruciating detail, then you&#8217;re probably made it too complex.</p>
<p>One of the reasons why I adore Eclipse for Java development is because it shows JavaDoc attributes in its Intellisense methods &#8211; I don&#8217;t need to navigate through the Java API when I can hit Ctrl+Space and see the arguments the method takes. Without Eclipse, I have to either rely on memory (and in my opinion, life&#8217;s too short to memorize the proper sequence of arguments that a proper BufferedReader instance takes) or waste time navigating the API docs.</p>
<p>Objective-C, on the other hand, doesn&#8217;t have this &#8211; because method signatures can be broken up into multiple pieces. Take a look at these two method signatures &#8211; taken <a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/rangeOfString:options:range:">straight</a> <a href="http://storrow.org/cocoa-javadoc/com/apple/cocoa/foundation/NSStringReference.html#rangeOfString(java.lang.String,%20int,%20com.apple.cocoa.foundation.NSRange)">from</a> the documentation:</p>
<p><code>- (NSRange)rangeOfString:(NSString *)subString options:(unsigned)mask range:(NSRange)aRange</code></p>
<p>versus:</p>
<p><code>public NSRange rangeOfString(String s, int i, NSRange nsrange)</code></p>
<p>When looking at the first method signature, I know that the second object will be an integer that controls the masking &#8211; simply by virtue of the fact that, like its parent Smalltalk, its methods recieve messages via <a href="http://en.wikipedia.org/wiki/Smalltalk#Messages">keyword messaging</a>. I can also make the assumption &#8211; and it is only an assumption &#8211; that <code>- (NSRange)rangeOfString:(NSString *)subString options:(unsigned)mask</code> and <code>- (NSRange)rangeOfString:(NSString *)subString</code> are valid methods. With the Java API, on the other hand, I have no clue what the second argument does; if I had to know, I&#8217;d need to be using Eclipse or XCode, not Emacs or Textmate. Textmate&#8217;s Cocoa completions don&#8217;t show any HeaderDoc information &#8211; but that doesn&#8217;t matter: the keywords tell me what the arguments are used for.</p>
<p>It seems to me that Objective-C&#8217;s syntax lends itself to clarity by its very nature; Java, on the other hand, depends on other programmers being clear and helpful in their method signatures. And as a short perusal through The Daily WTF reveals, programmers can be very, very unhelpful at times.</p>
]]></html></oembed>