{"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=\"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>&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><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\/\/ [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=\"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_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[4,180],"tags":[13,151,173],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1TKYv-jK","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1199,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1199\/","url_meta":{"origin":1224,"position":0},"title":"Oxygene &#8220;Nougat&#8221; is Mac and iOS !","date":"06 Sep 2012","format":false,"excerpt":"Marc Hoffman has confirmed that \"Nougat\" is to Mac\/iOS as \"Cooper\" was to Java. \u00a0Some have speculated that this will be based on Mono, but Oxygene has had Mono covered for some time already, so I strongly doubt that this is the case. Far more likely is that just as\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1593,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1593\/","url_meta":{"origin":1224,"position":1},"title":"Learning Valuable Lessons","date":"14 Sep 2013","format":false,"excerpt":"Iztok has been at it again, making comments that prompt another post. :) He expresses his view that there are only two viable options for mobile development. The first is essentially the web-based technology approach (HTML\/JS\/PhoneGap etc) and the other is the platform native tool chains, Eclipse\/AndroidStudio\/Xcode etc. He may\u2026","rel":"","context":"In &quot;Android&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1477,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1477\/","url_meta":{"origin":1224,"position":2},"title":"A Case of Insensitivity","date":"15 Aug 2013","format":false,"excerpt":"I closed my previous post with an observation that the code for initialising an iOS user interface programmatically, as translated from equivalent Objective-C, contained a potential gotcha. I now have a little more time to expand on that. Loose Ends This is the code we ended up with last time:\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1713,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1713\/","url_meta":{"origin":1224,"position":3},"title":"How to Call Java Code from an Oxygene Android Application","date":"20 Sep 2013","format":false,"excerpt":"Lachlan just posted a link to a post on Google+ (also available as a PDF) demonstrating how to call Java from Delphi XE5. I was shocked at both the amount and the nature of the code involved. It is long, convoluted and ugly stuff (nb. that isn't a criticism of\u2026","rel":"","context":"In &quot;Android&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2416,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2416\/","url_meta":{"origin":1224,"position":4},"title":"Relight My Fire","date":"01 May 2016","format":false,"excerpt":"I'm not sure how many more song inspired Fire references I can keep coming up with, but here at least is one more. In response to my previous post Wouter commented that he had a much simpler cross platform solution to the random number problem: Which is very pithy but\u2026","rel":"","context":"In &quot;Cooper&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1882,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1882\/","url_meta":{"origin":1224,"position":5},"title":"Not Your Grand-Daddy&#8217;s Pascal (or Java)","date":"15 Oct 2013","format":false,"excerpt":"I've mentioned some of the cool stuff in the Oxygene language in various posts and thought it would be a good idea to list them again, along with some others that I've not previously mentioned. Oxygene Everywhere First some of the core language features that are available on all supported\u2026","rel":"","context":"In &quot;Android&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1224"}],"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}]}}