{"id":1224,"date":"2012-09-13T10:16:47","date_gmt":"2012-09-12T22:16:47","guid":{"rendered":"https:\/\/www.deltics.co.nz\/blog\/?p=1224"},"modified":"2012-09-13T10:16:47","modified_gmt":"2012-09-12T22:16:47","slug":"sugary-goodness-in-nougat","status":"publish","type":"post","link":"https:\/\/www.deltics.co.nz\/blog\/posts\/1224\/","title":{"rendered":"Sugary Goodness in &#8220;Nougat&#8221;"},"content":{"rendered":"<span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\"> 2<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span><p>Continuing the theme of recent &#8211; and upcoming &#8211; posts about new (and not so new) syntax in modern (and not so modern) variations on the Pascal language, I just have to comment on what I regard as yet another stunningly good job that the guys at RemObjects have done in their &#8220;Nougat&#8221; flavoured Oxygene. &nbsp;Specifically in relation to how they have implemented the named method parts syntax in Objective-C.<\/p>\n<p><!--more--><\/p>\n<p>The example that Marc Hoffman provides in his <a href=\"http:\/\/blogs.remobjects.com\/blogs\/mh\/2012\/09\/12\/p4738\" target=\"_blank\">recent blog post<\/a>, is the constructor method for a string,&nbsp;<code class=\"\" data-line=\"\">&lt;a href=&quot;https:\/\/developer.apple.com\/library\/mac\/#documentation\/Cocoa\/Reference\/Foundation\/Classes\/NSString_Class\/Reference\/NSString.html&quot; target=&quot;_blank&quot;&gt;stringByPaddingToLength:withString:startingAtIndex:&lt;\/a&gt;<\/code>.<\/p>\n<p>This would be called in Objective-C thusly:<br \/>\n<code class=\"\" data-line=\"\"><br \/>\n[myString stringByPaddingToLength: 9 withString: @&quot;.&quot; startingAtIndex:0];<br \/>\n<\/code><\/p>\n<p>How on earth can you contrive to make such a call in a Pascal derived language ?<\/p>\n<p>Well, as Marc describes, there are a number of possible approaches, most of which are dictated by whether you are extending the language or merely providing a bridge from the language into the runtime.<\/p>\n<p>The bridge approach results in the most cumbersome &#8211; and imho downright ugly &#8211; solutions but remains strictly and technically within the limits of the existing Pascal language.<\/p>\n<p>A first cut at providing a bridge to this Objective-C API might simply ignore named method parts by implementing them as simple parameters to the base method name, overloading where necessary:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n  myString.stringByPaddingToLength(9, '.', 0);\r\n<\/pre>\n<p>Or you might encode the method part names in the method itself either by preference or by necessity (if there are methods whose method parts differ in name, but not type &#8211; though I am not as yet away of any such examples in the Objective-C runtime):<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n  myString.stringByPaddingToLengthWithStringStartingAtIndex(9, '.', 0);\r\n<\/pre>\n<h3>Not Your Daddy&#8217;s Pascal<\/h3>\n<p>Whilst both of these are demonstrably &#8220;Pascal&#8221;, within the existing syntax of the language, neither maps very comfortably or intuitively to the Objective-C runtime.<\/p>\n<p>Extending the language, by contrast, creates something that is arguably not Pascal at all &#8211; by definition, since it involves changes or additions to the syntax &#8211; but which is, ironically, the most Pascal-like in terms of preserving elegance and clarity not only in the language but in way that it exposes the underlying RTL:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n\/\/ &#x5B;myString stringByPaddingToLength: 9 withString: @&quot;.&quot; startingAtIndex:0];\r\n   myString.stringByPaddingToLength(9) withString('.') startingAtIndex(0);\r\n<\/pre>\n<p>imho, not only is this cleaner code and closer to the underlying RTL, but it is, if anything, an improvement even on the &#8220;native platform&#8221; code for that RTL!<\/p>\n<p>Whilst some might rail at this, crying &#8220;<strong>But this isn&#8217;t Pascal!!<\/strong>&#8220;, I would ask whether this would be considered more or less &#8220;Pascal-ish&#8221; than:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n  TMyWindowClass = class(TMyBaseControl)\r\n    procedure WMPaint(var aMessage: TWMPaint); message WM_PAINT;\r\n  end;\r\n<\/pre>\n<h3>Colour Me Excited<\/h3>\n<p>For myself, I am increasingly excited to see how RemObjects approach targeting new platforms with the language that I am most familiar with, in the same way that I was excited when I first saw Delphi 1.0 and how the language was adapted to suit Windows, back in the day.<\/p>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"span-reading-time rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\"> 2<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span>Continuing the theme of recent &#8211; and upcoming &#8211; posts about new (and not so new) syntax in modern (and not so modern) variations on the Pascal language, I just have to comment on what I regard as yet another stunningly good job that the guys at RemObjects have done in their &#8220;Nougat&#8221; flavoured Oxygene. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[4,180],"tags":[13,151,173],"class_list":["post-1224","post","type-post","status-publish","format-standard","hentry","category-delphi","category-oxygene","tag-language","tag-objective-c","tag-pascal"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1TKYv-jK","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/comments?post=1224"}],"version-history":[{"count":3,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1224\/revisions"}],"predecessor-version":[{"id":1227,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1224\/revisions\/1227"}],"wp:attachment":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=1224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=1224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=1224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}