{"id":734,"date":"2003-12-07T16:59:22","date_gmt":"2003-12-07T21:59:22","guid":{"rendered":"\/?p=734"},"modified":"2015-05-09T13:42:15","modified_gmt":"2015-05-09T17:42:15","slug":"a_balanced_and_fair_look_","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2003\/12\/07\/a_balanced_and_fair_look_\/","title":{"rendered":"A Balanced and Fair Look at Objective-C"},"content":{"rendered":"<p>\r\nJonathan Rentzsch has written a great article about <a href=\"http:\/\/rentzsch.com\/papers\/loveHateObjC\">what he loves and hates about Objective-C<\/a>. [Update (2015-05-09): Here\u2019s an <a href=\"http:\/\/web.archive.org\/web\/20080131215725\/http:\/\/rentzsch.com\/papers\/loveHateObjC\">archive.org link<\/a> since the original site is down.] I&rsquo;ve wanted to write this article for a long time, but now Rentzsch has saved me the time and also done a better job than I probably would have. Now I can just cover the places where I disagree or have something to add.\r\n<\/p>\r\n\r\n<dl>\r\n\r\n<dt>\r\nLove 7: Key Value Coding\r\n<\/dt>\r\n<dd>\r\nI like Key Value Coding, too, but I think it&rsquo;s really part of the framework, not the language. It&rsquo;s made possible by <em>Love 3: (Fairly Good) Runtime Object Model<\/em>.\r\n<\/dd>\r\n\r\n<dt>\r\nHate 1: Method-call Syntax\r\n<\/dt>\r\n\r\n<dd>\r\nI think the Smalltalk-style interspersing of the method name and the parameters (<em>contra<\/em> keyed parameters) is a big win. This is probably my favorite part of Objective-C. The square braces, though by no means bad once you get used to them, <em>are<\/em> kind of ugly and annoying for editing. (It helps to use a BBEdit glossary item such as <tt>#inline#[#select##insertion#]<\/tt>, coupled with the Balance command.) Smalltalk uses parens instead of braces, and you can omit them in certain circumstances. I don&rsquo;t know whether this would be possible with Objective-C, given that it has to be compatible with C&rsquo;s grammar.\r\n<\/dd>\r\n\r\n<dt>\r\nHate 6: Initialization Idiom\r\n<\/dt>\r\n\r\n<dd>\r\nThis is kind of a restatement of <em>Hate 2: Lightweight<\/em>. I agree that assigning to <code>self<\/code> is disturbing, even if it affords a little extra power. However, I don&rsquo;t think it&rsquo;s fair to blast Objective-C because many of its users like to put assignments in conditions. This is a feature inherited from C, and you could say that deficiencies in Objective-C encourage the use of this idiom. But it doesn&rsquo;t bother me. I&rsquo;ve read about how people accidentally use <code>=<\/code> instead of <code>==<\/code>, and how some experienced programmers like to contort the order of their equality operands to help catch this error, but I don&rsquo;t think this has ever bitten me&mdash;so I vote for the extra expressiveness.\r\n<\/dd>\r\n\r\n<dt>\r\nHate 7: No Stack Objects\r\n<\/dt>\r\n\r\n<dd>\r\nThis is on the right track, but I&rsquo;m not convinced that stack objects are the right solution.\r\n<\/dd>\r\n\r\n<dt>\r\nHate 10: Messaging nil\r\n<\/dt>\r\n\r\n<dd>\r\nI&rsquo;ve got mixed feelings on this one. I really like the expressiveness of being able to message <code>nil<\/code>, for instance with locks, broadcasters, and releasing. Wacky idea: perhaps there should be a way to tell the compiler (via a type modifier, perhaps) in which cases you want to be able to message <code>nil<\/code> silently.\r\n<\/dd>\r\n\r\n<dt>\r\nHate 14: id should be id*\r\n<\/dt>\r\n\r\n<dd>\r\nI think this is historical. Originally, all Objective-C objects had type <code>id<\/code>, and you were supposed to treat them like primitives, not pointers. It was only later that static typing, such as <code>NSString *foo<\/code>, was added. So it might be more appropriate to ask why we have to write <code>NSString *<\/code> instead of <code>NSString<\/code>.\r\n<\/dd>\r\n\r\n<dt>\r\nIndifferent 2: Memory Management\r\n<\/dt>\r\n\r\n<dd>\r\nConceptually, this doesn&rsquo;t bother me, but my intuition is that the hybrid scheme is the worst of both worlds, performancewise.\r\n<\/dd>\r\n\r\n<\/dl>\r\n\r\n<p>\r\nAnd the conclusion:\r\n<\/p>\r\n\r\n<blockquote cite=\"http:\/\/rentzsch.com\/papers\/loveHateObjC\">\r\nObjC is a mediocre language propped-up by a great framework.\r\n<\/blockquote>\r\n\r\n<p>\r\nThe framework is certainly the gem. Whether the language is mediocre depends on what you compare it to. It&rsquo;s no Dylan, but I generally like it better than C++ and Java.\r\n<\/p>\r\n\r\n<p>\r\nFurther reading: <a href=\"http:\/\/nslog.com\/archives\/2003\/11\/29\/objectivec.php#comments\">the discussion on Erik Barzeski&rsquo;s blog<\/a>.\r\n<\/p>","protected":false},"excerpt":{"rendered":"<p>Jonathan Rentzsch has written a great article about what he loves and hates about Objective-C. [Update (2015-05-09): Here\u2019s an archive.org link since the original site is down.] I&rsquo;ve wanted to write this article for a long time, but now Rentzsch has saved me the time and also done a better job than I probably would [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"","apple_news_api_id":"","apple_news_api_modified_at":"","apple_news_api_revision":"","apple_news_api_share_url":"","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-734","post","type-post","status-publish","format-standard","hentry","category-programming-category"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=734"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/734\/revisions"}],"predecessor-version":[{"id":11176,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/734\/revisions\/11176"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}