{"id":517,"date":"2009-12-07T16:35:51","date_gmt":"2009-12-07T21:35:51","guid":{"rendered":"http:\/\/vgable.com\/blog\/?p=517"},"modified":"2009-12-07T16:35:59","modified_gmt":"2009-12-07T21:35:59","slug":"dot-syntax-solution","status":"publish","type":"post","link":"https:\/\/vgable.com\/blog\/2009\/12\/07\/dot-syntax-solution\/","title":{"rendered":"Dot Syntax Solution"},"content":{"rendered":"<p>Surprisingly, the addition of dot <em>syntax<\/em> to Objective-C 2.0 has been a major source of controversy. I wonder if there&#8217;s some kind of <a href=\"http:\/\/en.wikipedia.org\/wiki\/Parkinson's_Law_of_Triviality\">Bike Shed effect<\/a> at work here: the problem dot-syntax causes is trivial<sup>1<\/sup>; while the clarity it brings to code is minor. So it essentially boils down to <em>aesthetics<\/em>. (For the record, I like the dot, even with it&#8217;s current flaws, but I don&#8217;t believe it&#8217;s worth fighting for).<\/p>\n<h3>The Actual Problem<\/h3>\n<p>The <a href=\"http:\/\/weblog.bignerdranch.com\/?p=83\">problem<\/a> is that when you see <code>a.b = c;<\/code> you don&#8217;t know if it&#8217;s:<\/p>\n<ol>\n<li><strong>Assigning<\/strong> the <code>b<\/code> field of a <strong><code>struct<\/code><\/strong> to <code>c<\/code>. This basically compiles down to one <code>move<\/code> instruction.<\/li>\n<li><strong>Invoking<\/strong> the <code>-setB:<\/code> method on an <strong>Objective-C object<\/strong>. By convention <code>-setB:<\/code> should update the <code>b<\/code> property of the object to hold the value <code>c<\/code>, and nothing else. But it might have side effects, or be really slow.<\/li>\n<\/ol>\n<h3>A Solution<\/h3>\n<p>Using a different symbol to access Objective-C properties would remove all ambiguity. Nobody would mistake <code>a@b = c;<\/code> as assigning to a C-<code>struct<\/code>. It&#8217;s clearly an Objective-C construct.<\/p>\n<p>But personally, I&#8217;m not a big fan of the <code>@<\/code> character. It&#8217;s ugly; it&#8217;s noisy; there&#8217;re just too many lines in it. I think <a href=\"http:\/\/www.fileformat.info\/info\/unicode\/char\/25b8\/index.htm\">U+25B8<\/a> &#8216;BLACK RIGHT-POINTING SMALL TRIANGLE&#8217; would make a better choice,<\/p>\n<blockquote><p><code>obj&#x25B8;property = value;<\/code><\/p><\/blockquote>\n<p>And since &#8216;&#x25B8;&#8217; can&#8217;t be part of a valid C identifier, you can basically preprocess your code with <code>s\/&#x25B8;\/.\/<\/code>, then compile it with existing tools.<\/p>\n<p>Of course, it doesn&#8217;t matter what character(s) is picked, so long as it&#8217;s clearly different from existing C syntax; and you have a way of replacing it with a <code>.<\/code> before building it.<\/p>\n<p><sup>1<\/sup> <small>I&#8217;ve heard experienced developers complain that dot-syntax = <a href=\"http:\/\/weblog.bignerdranch.com\/?p=83\">a steeper learning curve for <em>newbies<\/em><\/a>, and that it <em>can<\/em> be confusing, but I haven&#8217;t actually seen one come out and say &#8216;I spent X hours debugging a problem that I couldn&#8217;t see because of it&#8217;. The fact is, any situation that dot-syntax would obscure is <em>already pathological<\/em>. In the end I just can&#8217;t see dot-syntax mattering much.<\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Surprisingly, the addition of dot syntax to Objective-C 2.0 has been a major source of controversy. I wonder if there&#8217;s some kind of Bike Shed effect at work here: the problem dot-syntax causes is trivial1; while the clarity it brings to code is minor. So it essentially boils down to aesthetics. (For the record, I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,12,5,4,8],"tags":[543,263,358,48,134],"class_list":["post-517","post","type-post","status-publish","format-standard","hentry","category-cocoa","category-design","category-objective-c","category-programming","category-usability","tag-dot-syntax","tag-objective-c-20","tag-steal-my-ideas-please","tag-syntax","tag-xcode"],"_links":{"self":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/517","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/comments?post=517"}],"version-history":[{"count":1,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/517\/revisions"}],"predecessor-version":[{"id":518,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/posts\/517\/revisions\/518"}],"wp:attachment":[{"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/media?parent=517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/categories?post=517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vgable.com\/blog\/wp-json\/wp\/v2\/tags?post=517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}