{"id":1477,"date":"2013-08-15T10:35:45","date_gmt":"2013-08-14T22:35:45","guid":{"rendered":"https:\/\/www.deltics.co.nz\/blog\/?p=1477"},"modified":"2013-08-15T10:38:27","modified_gmt":"2013-08-14T22:38:27","slug":"a-case-of-insensitivity","status":"publish","type":"post","link":"https:\/\/www.deltics.co.nz\/blog\/posts\/1477\/","title":{"rendered":"A Case of Insensitivity"},"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>I closed <a href=\"https:\/\/www.deltics.co.nz\/blog\/?p=1457\">my previous post<\/a> 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.<\/p>\n<p><!--more--><\/p>\n<h2>Loose Ends<\/h2>\n<p>This is the code we ended up with last time:<\/p>\n<pre class=\"brush: oxygene; gutter: true; highlight: [12,13]; title: ; notranslate\" title=\"\">\r\nmethod AppDelegate.application(application: UIApplication)\r\n                   didFinishLaunchingWithOptions(launchOptions: NSDictionary): Boolean;\r\nbegin\r\n  \/\/ Override point for customization after application launch.\r\n\r\n  window := UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds);\r\n  window.backgroundColor := UIColor.whiteColor;\r\n\r\n  \/\/ Create an instance of our view controller\r\n  \/\/  then set it as the window's root view controller\r\n    \r\n  var mainViewController := MainViewController.alloc.init;\r\n  window.rootViewController := mainViewController;\r\n\r\n  window.makeKeyAndVisible;\r\n\r\n  result := true;\r\nend;\r\n<\/pre>\n<p><em>You might notice that I have now figured out how to extend the language support of the syntax highlighter plugin I use with WordPress, and having implemented an Oxygene &#8220;brush&#8221; I can now present Oxygene source without having to resort to screen grabs! \ud83d\ude42<\/em><\/p>\n<p>The potential gotcha is on lines 12 and 13 (highlighted) in the use of two different identifiers each called <strong>MainViewController<\/strong>.  There is an apparent difference between them in that one is named with an initial lowercase &#8220;<em>m<\/em>&#8221; while the other has an initial capital &#8220;<em>M<\/em>&#8220;.<\/p>\n<p>In <em>Objective-C<\/em> this is fine, since that language is case sensitive and &#8211; in common with <em>C#<\/em> for example &#8211; it is quite a common convention to see instance identifiers being named for the class they represent, with only this case difference to distinguish them (one of the reasons I personally dislike C style languages, incidentally).<\/p>\n<p>But <em>Oxygene<\/em> is <strong>not<\/strong> case sensitive.<\/p>\n<p>Because we have introduced an in-line variable declaration, from line 13 onwards both <strong>mainViewController<\/strong> and <strong>MainViewController<\/strong> will refer to the variable &#8211; an instance of the class &#8211; not the class itself.<\/p>\n<p>This can be avoided in two ways:<\/p>\n<ol>\n<li>Use a different name for the variable<\/li>\n<li>Namespace qualify any references to the class from that point on<\/li>\n<\/ol>\n<p>I personally favour the first of these.<\/p>\n<p>In addition I favour not using in-line variable declarations for precisely this reason, that it potentially changes scope resolutions part-way through a method body.  Its use in this case was intended only to illustrate the fact that this technique can be preserved directly when translating from Objective-C.<\/p>\n<p>Had this variable been declared at the top of the method, the potential conflict would have been identified much more quickly since in that scenario the <em>Oxygene<\/em> compiler issues a warning that the <strong>MainViewController<\/strong> reference in the method body differs in case from the &#8220;initial declaration&#8221;.<\/p>\n<p>This warning does not arise in the in-line declaration case, and arguably rightly so, since in that case the two identifiers are, well, identifiably distinct until after the initialisation of the variable has taken place.  i.e. the code as written does not actually contain any problem arising from this potential gotcha.  It is only a <em>potential<\/em> gotcha.<\/p>\n<p>But these have a nasty habit of becoming actual gotchas when you least expect it, which is why I prefer to avoid them.  \ud83d\ude42<\/p>\n<h2>Coming Soon&#8230;<\/h2>\n<p>So that deals with the vestigial issue from that previous post and I am thankfully finding myself at last with more time to spend with <em>Oxygene<\/em>.  High on my list of things to explore is the extent to which non-platform specific code can be shared between the different &#8220;flavours&#8221; of Oxygene.<\/p>\n<p>All I know at this stage is that it is not only possible but obviously desirable, so that we may write applications that specialise their UI as appropriate to the different platforms with their different UI and UX needs, whilst avoiding having to duplicate any non-UI code.<\/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> 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.<\/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":true,"jetpack_social_options":[]},"categories":[4,204,180],"tags":[13,181],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1TKYv-nP","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":2280,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2280\/","url_meta":{"origin":1477,"position":0},"title":"Oxygene Constructor Magic on Cocoa","date":"30 Aug 2014","format":false,"excerpt":"Earlier this week I mentioned that I had published my TXT-2-PARK app for Android in the Google Play Store. Today I published the iOS version to the Apple App Store (still awaiting approval at this stage). As with the Android version, I implemented the iOS version using Oxygene, and things\u2026","rel":"","context":"In &quot;Android&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2523,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2523\/","url_meta":{"origin":1477,"position":1},"title":"Anonymous Classes: Anonymous POCO&#8217;s","date":"14 Feb 2017","format":false,"excerpt":"There is another use case for anonymous classes, even simpler than that of providing implementations of interfaces: Anonymous POCO's. We're all familiar with the idea of declaring a class that identifies the members that all instances (objects) of that class have, and then creating instances of that class. Anonymous classes,\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/code-completion-java.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1503,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1503\/","url_meta":{"origin":1477,"position":2},"title":"Sharing Code Across Platforms in Oxygene","date":"22 Aug 2013","format":false,"excerpt":"There seems to be a perception among some people that Delphi is in the unique position of allowing developers to share and re-use code across the various platforms that it's compiler can now (and will soon) target. But this is not the case. Oxygene has had this capability right from\u2026","rel":"","context":"In &quot;Cooper&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1713,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1713\/","url_meta":{"origin":1477,"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":1624,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1624\/","url_meta":{"origin":1477,"position":4},"title":"Exploring Listeners With Oxygene","date":"16 Sep 2013","format":false,"excerpt":"Part 2 in a short series demonstrating the development of a simple camera app for Android using Oxygene. In the previous instalment we looked at the basic framework of our app. For this instalment I was going to show how to implement the camera preview or viewfinder for this instalment,\u2026","rel":"","context":"In &quot;Android&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2470,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2470\/","url_meta":{"origin":1477,"position":5},"title":"Mix-in Unified and Segregated Syntax: An (Extended) Example","date":"25 Nov 2016","format":false,"excerpt":"Yesterday I initially posted that you couldn't mix Unified Syntax with \"traditional\" interface and implementation sections. Or what I am now calling Segregated Syntax. As sometimes happens, shortly after writing what I thought I knew to be true I discovered it wasn't ! Sorry about that. :) I promised to\u2026","rel":"","context":"In &quot;Cooper&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1477"}],"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=1477"}],"version-history":[{"count":10,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1477\/revisions"}],"predecessor-version":[{"id":1490,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/1477\/revisions\/1490"}],"wp:attachment":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=1477"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=1477"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=1477"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}