{"id":2223,"date":"2014-03-10T09:26:00","date_gmt":"2014-03-09T21:26:00","guid":{"rendered":"https:\/\/www.deltics.co.nz\/blog\/?p=2223"},"modified":"2014-03-10T09:26:00","modified_gmt":"2014-03-09T21:26:00","slug":"when-you-say-nothing-at-all","status":"publish","type":"post","link":"https:\/\/www.deltics.co.nz\/blog\/posts\/2223\/","title":{"rendered":"When You Say Nothing At All&#8230;"},"content":{"rendered":"<span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">[Estimated Reading Time: <\/span> <span class=\"rt-time\">5<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span><p>This is another one of those posts that has a bit of a double meaning in the same title.  First, there is the matter of a useful hint\/warning that I think could be emitted by a Pascal compiler.  The other is what I have been up to in recent months that I have been so busy that I wasn&#8217;t posting much (i.e. at all) !<\/p>\n<p>First the more relevant point to this blog:<\/p>\n<h3>When you say nothing at all, in Pascal<\/h3>\n<p><!--more--><\/p>\n<p>Consider this very simple piece of code:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n  if SomeCondition then\r\n    i := 42\r\n  else\r\n    i := -1;\r\n<\/pre>\n<p>Nothing controversial here, obviously (and just as obviously, this isn&#8217;t real code; it&#8217;s just for illustration).  Where <strong>SomeCondition<\/strong> is <strong>TRUE<\/strong>, <strong>i<\/strong> takes the value <strong>42<\/strong>, otherwise it takes the value <strong>-1<\/strong>.  Simple.  What could possibly go wrong ?<\/p>\n<p>The addition of just one character to this code will silently change the outcome completely, resulting in <strong>i<\/strong> <em>always<\/em> taking the value <strong>-1<\/strong>:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n  if SomeCondition then\r\n    i := 42\r\n  else;\r\n    i := -1;\r\n<\/pre>\n<p>Do you see it ?<\/p>\n<p>Of course, it&#8217;s going to be much easier to spot in an isolated example like this, but imagine reading this amongst the background noise of real world application code and you should appreciate how much harder it could be to identify in practice.<\/p>\n<p>The problem is of course that little semi-colon that has crept in after the <strong>else<\/strong>, completing the <strong>if-else<\/strong> with a null statement.  What I call a &#8220;NO-OP&#8221; (NO OPeration).<\/p>\n<p>The <strong>if-else<\/strong> now has an empty <strong>else<\/strong> clause and is immediately followed by an <em>unconditional<\/em> assignment of <strong>-1<\/strong> to <strong>i<\/strong>.  Now in this case you do get a hint that the value (<strong>42<\/strong>) assigned to <strong>i<\/strong> is never used, but I think a more specific warning about the empty statement would be more useful.<\/p>\n<p>Of course, such empty\/null statement <strong>NO-OP<\/strong>&#8216;s <strong>can<\/strong> be useful.  I use them quite often with <strong>case<\/strong> statements for example, or anywhere else that I need to demonstrate and self-document that some potential case has been &#8220;<em>left intentionally blank<\/em>&#8221; rather than having simply forgotten to deal with the case, but I always document them as such:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n  case Status of\r\n    asError   : Color := clRed;\r\n    asWarning : Color := clOrange;\r\n    asOK      : { NO-OP - no color change } ;\r\n  end;\r\n<\/pre>\n<p>Or an introduced <strong>virtual<\/strong> method which is specifically not abstract but which explicitly has no base class implementation.  Or in an <strong>override<\/strong> which deliberately suppresses the inherited implementation (i.e. does not call <strong>inherited<\/strong> and provides no replacement implementation):<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\n  procedure TFoo.OverrideMe;\r\n  begin\r\n    \/\/ NO-OP\r\n  end;\r\n<\/pre>\n<p>You don&#8217;t actually need to comment\/document your NO-OP&#8217;s in this way because they are perfectly valid, but I consider it a useful indication that the NO-OP is a deliberate and considered aspect of the implementation, rather than an accident of oversight or omission.<\/p>\n<p>Which is great when you deliberately introduce these NO-OP&#8217;s, but when you do so <em>unintentionally<\/em>, you get no warning.  I think it might be useful to have such a warning, or at least a hint.  Of course, this will result in a slew of warnings in existing code which contains perfectly valid, empty statements, and no easy way to deal with those warnings.<\/p>\n<p>Two ways of dealing with this <em>might<\/em> be:<\/p>\n<ol>\n<li>Introduce a new keyword specifically to indicate a deliberate empty statement.  Even without compiler support this could be approximated by simply have a particular named procedure that you call in such cases.  This might be preferable anyway given that this would be necessary in code that has to support older compilers which would be unaware of the keyword.<\/li>\n<li>Emit the hint\/warning as part of the source parser and allow a comment to be treated as representing a &#8220;statement&#8221; in such cases.  Then as long as an empty statement at least contains some comment (i.e. documentation) it would be considered not requiring a warning.<\/li>\n<\/ol>\n<p>In the latter case of course the parser has no way of knowing whether any comment in an otherwise empty statement is actually useful documentation for that empty statement or not.  So perhaps there should be different levels of strictness that may be applied.  i.e. emit hints\/warnings for all empty statements or only for only those that do not contain comment(s), to be applied as suits your individual coding standards in such areas.<\/p>\n<p>In any event, any such hint\/warning is probably best introduced as disabled\/turned off by default.<\/p>\n<p>It&#8217;s not a world changing improvement to the language, but it could be a useful one.  \ud83d\ude42<\/p>\n<h3>A Busy Start to the year&#8230;<\/h3>\n<p>As for my own relative silence in recent months&#8230; what can I say ?  It&#8217;s been a <strong>very<\/strong> busy start to the year !<\/p>\n<p>In January my fianc\u00e9e and I resumed house hunting as we had always intended to do after Christmas, expecting it to take a few months.  Within a week we had found a house and one thing followed another and another week later we had a purchase agreement in place !<\/p>\n<p>Then in February <a href=\"https:\/\/plus.google.com\/photos\/111874043401122099650\/albums\/5982688705579548145\" target=\"_blank\">we got married<\/a>.  Unlike the house, this had been planned <strong>well<\/strong> in advance but still took a great deal of last minute organising, not least due to the logistical challenges arising from our decision to get married in <a href=\"http:\/\/www.northlandnz.com\/destinations\/hokianga_harbour\" target=\"_blank\">Hokianga<\/a>, a beautiful location in the Far North of New Zealand but about 4 hours drive from Auckland where we live.  Natural beauty aside, Hokianga is a special place for us as it is where we went on our first trip away together.<\/p>\n<p>Hokianga in Maori means &#8220;Returning Place&#8221;.<\/p>\n<p>Then, the week before the wedding we were invited to a ceremony (along with almost 500 other new citizens!) to receive our certificates of New Zealand Citizenship, to occur just a week after the wedding itself.<\/p>\n<p>My wife&#8217;s parents had travelled to New Zealand for the wedding and were staying on for a further month after.  Being able to be present at the Citizenship ceremony was an unexpected bonus for them.  Also unexpected but unfortunate were the events unfolding for them back home, in Ukraine.  If you have been at all aware of <a href=\"http:\/\/www.bbc.com\/news\/world-middle-east-26248275\" target=\"_blank\">events in that region<\/a> you can appreciate that the joy of the wedding was soon overtaken by concern for what they might have to return home to (last week).  They live in <a href=\"http:\/\/www.bbc.com\/news\/world-europe-26487096\" target=\"_blank\">Donetsk<\/a>.<\/p>\n<p>Fortunately it has been a relief for them to find that life in Donetsk is actually far less affected by the goings on there than we had feared might be the case in the former President&#8217;s home region.  We can only hope that things remain that way and that the situation is soon resolved.<\/p>\n<p>One additional complication arising from the wedding came from our decision to blend our names.  Had either of us taken the other&#8217;s name this could have been achieved simply by making that change on the marriage certificate.  But since we were <strong>both<\/strong> taking a <strong>new<\/strong> name we instead had to apply for a legal name change, separately.<\/p>\n<p>That took effect last week, so I am now legally &#8220;<em>Jolyon <strong>Direnko-<\/strong>Smith<\/em>&#8220;.<\/p>\n<p>And last but not least (as if all that wasn&#8217;t enough to be dealing with!) I decided to move on from my job at Flow Software.  I am currently &#8220;between jobs&#8221;, waiting to take up a new post at Datacom, next week.<\/p>\n<p>So, all in all, <strong>very<\/strong> exciting and <strong>very<\/strong> busy times. \ud83d\ude42<\/p>\n<p>And that&#8217;s without even mentioning the release of <a href=\"http:\/\/techcrunch.com\/2014\/03\/06\/embarcadero-launches-appmethod-a-new-multi-device-development-platform-for-native-apps\/\" target=\"_blank\">AppMethod<\/a> and <a href=\"http:\/\/blogs.remobjects.com\/\" target=\"_blank\">RemObjects Elements<\/a> with a major new release of Oxygene and an exciting new direction for C# !<\/p>\n<p>A couple of commenters have mentioned these developments already and I of course expect to be blogging about these in the near future, now that the world is spinning at a (slightly) more manageable rate !  \ud83d\ude42<\/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\">5<\/span> <span class=\"rt-label rt-postfix\">minutes]<\/span><\/span> This is another one of those posts that has a bit of a double meaning in the same title. First, there is the matter of a useful hint\/warning that I think could be emitted by a Pascal compiler. The other is what I have been up to in recent months that I have been so [&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":true,"jetpack_social_options":[]},"categories":[4],"tags":[268,13,267,173],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1TKYv-zR","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":700,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/700\/","url_meta":{"origin":2223,"position":0},"title":"The case for case[]","date":"30 Nov 2010","format":false,"excerpt":"Eric Grange (resurrector of the increasingly interesting looking DWS project) recently posted about a new idea he has had for the DWS engine, which in turn gave me an idea, or rather, prompted me to come up with what I think may be a new spin on an old one.\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2624,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2624\/","url_meta":{"origin":2223,"position":1},"title":"Expressive If and Case &#8230;","date":"25 Apr 2017","format":false,"excerpt":"A quick post on a small but hugely useful little language feature in Oxygene... if expressions. Many people will be familiar with the so-called ternary operator. Delphi developers will also be aware that there is no direct equivalent in Delphi. In 'C' and other languages we can write a statement\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2337,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2337\/","url_meta":{"origin":2223,"position":2},"title":"A Silent Danger&#8230;","date":"07 Jun 2015","format":false,"excerpt":"A brief post on a long standing omission in type checking in Pascal and the limitations of Range Checking as applied to the problem. Consider this contrived example of a simple function: This very simple function accepts an explicitly 32-bit Integer parameter and simply returns TRUE if the value passed\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1224,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1224\/","url_meta":{"origin":2223,"position":3},"title":"Sugary Goodness in &#8220;Nougat&#8221;","date":"13 Sep 2012","format":false,"excerpt":"Continuing the theme of recent - and upcoming - 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\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1207,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1207\/","url_meta":{"origin":2223,"position":4},"title":"Adventures in Syntax: Something Old, Something New etc&#8230;","date":"20 Sep 2012","format":false,"excerpt":"As the post title says, this will be a brief detour through some features of the Pascal language and a presentation of some (theoretical) alternatives that could have been introduced instead. That is, some are real but little known syntax, others are what I think might be preferable to the\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":900,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/900\/","url_meta":{"origin":2223,"position":5},"title":"Porting the Objective-C CFFTPSample to XE2: Part 1","date":"04 Jul 2012","format":false,"excerpt":"On the NZ DUG email list (yes, we still have those here) a question was recently posted asking for help with getting some FTP code working on OSX, using XE2. This coincided nicely with my reaching a point in my Objective-C learning where this sort of exercise was of interest\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/2223"}],"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=2223"}],"version-history":[{"count":3,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/2223\/revisions"}],"predecessor-version":[{"id":2226,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/2223\/revisions\/2226"}],"wp:attachment":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=2223"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=2223"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=2223"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}