{"id":847,"date":"2012-04-30T15:01:58","date_gmt":"2012-04-30T03:01:58","guid":{"rendered":"https:\/\/www.deltics.co.nz\/blog\/?p=847"},"modified":"2012-04-30T15:04:00","modified_gmt":"2012-04-30T03:04:00","slug":"nested-types-in-the-spirit-of-delphi","status":"publish","type":"post","link":"https:\/\/www.deltics.co.nz\/blog\/posts\/847\/","title":{"rendered":"Nested Types in the &#8220;Spirit of Delphi&#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>I have posted before about <a href=\"https:\/\/www.deltics.co.nz\/blog\/?p=484\">new language features introduced in a way that does not adhere to the (admittedly quite notional) &#8220;Spirit of Delphi&#8221;<\/a>.  It&#8217;s time for another one, this time inspired by <a href=\"http:\/\/members.adug.org.au\/2012\/04\/27\/nested-type-enumerators\/\">a post by Paul Klink of the ADUG<\/a>.<br \/>\n<!--more--><br \/>\nIn his post, Paul makes the following observation:<\/p>\n<blockquote><p>The obvious downside is that class\/type declarations are larger and harder to read.  With practice, I have gotten better at reading types with nested types but you can only go so far.\n<\/p><\/blockquote>\n<p>I think nested types would be more livable with if we were able to separate the physical organisation in the source code from the logical organisation of the types.  Isn&#8217;t that what software development languages in particular are supposed to help us do ?  To abstract the physical from the logical ?<\/p>\n<p>Indeed, Pascal already contained the exact construct we needed to achieve this: the forward declaration:<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\ntype\r\n   TDocument = class\r\n      type TParagraph = class;  \/\/ forward decl of TDocument.TParagraph\r\n     ..\r\n   end;\r\n\r\n  TDocument.TParagraph = class\r\n    ..\r\n  end;\r\n<\/pre>\n<p>The fact that a logically nested type is required also to be physically nested shows what appears to me to be a shocking (but sadly all too common) lack of imagination or forward thinking on the part of the developers working on the language spec\/implementation.<\/p>\n<p>i.e. It should have been obvious that creating nested types in anything other than trivial cases would quickly lead to convoluted and hard to read source and taken steps to ensure that the &#8220;Spirit of Pascal&#8221; was preserved in and by their endeavours.<\/p>\n<p>It is that lack of awareness of the heritage and intents of the language they are working with\/on in the language feature arms race that is most worrying to me and is the main reason I steer well clear of almost all language features introduced to Delphi in recent years as they almost all suffer from the same problem: <strong>Whatever good they do, they also make code harder for mere humans to read and understand<\/strong>.<\/p>\n<p>(<em>another huge problem is the fact that if you are creating code intended to be shared with a broad group, then by using new language features you cut off users of older versions of the compiler for which they may have good reason to be stuck with, no matter how much we might think they should upgrade and could benefit from doing so.  But I digress&#8230;<\/em>)<\/p>\n<p>It is far more important to me that a human be able to read and understand code productively than it is for a compiler, because when a compiler doesn&#8217;t understand it will tell me in seconds by refusing to compile (or producing strange results), allowing me to identify and correct where I had made the mistake that lead to the compiler&#8217;s confusion.<\/p>\n<p>A human on the other hand can go for extended periods working on the basis of flawed interpretations, blissfully unaware of their unenlightened state or, perhaps more commonly, will take an extended period to gain the level of understanding needed to proceed beyond the point of simply acquiring that understanding and doing something useful with the knowledge.<\/p>\n<p>Sadly most language features these days seem designed for easier machine parsing than human.<\/p>\n<p>And it&#8217;s not even as if this has lead to decent IDE support for these language features to justify the bias toward ease of machine reading &#8230; more often than not, using them not only makes code harder to read but also breaks a great deal of the supposed productivity aids in the IDE, as Martin Franke observes in the comments on Paul&#8217;s post.<\/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 have posted before about new language features introduced in a way that does not adhere to the (admittedly quite notional) &#8220;Spirit of Delphi&#8221;. It&#8217;s time for another one, this time inspired by a post by Paul Klink of the ADUG.<\/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],"tags":[13,146,127,145],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1TKYv-dF","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1207,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1207\/","url_meta":{"origin":847,"position":0},"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":2337,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2337\/","url_meta":{"origin":847,"position":1},"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":2597,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2597\/","url_meta":{"origin":847,"position":2},"title":"(True = 1) and (True = &#8216;-1&#8217;) ?","date":"17 Mar 2017","format":false,"excerpt":"It has been observed that the Delphi documentation states that the constants True and False have the values 1 and 0 respectively, not the -1 and 0 that the default string conversions apply. This does actually make sense but also lays a trap for the unwary. True, True, Wherefore Art\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":847,"position":3},"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":1224,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/1224\/","url_meta":{"origin":847,"position":4},"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":2552,"url":"https:\/\/www.deltics.co.nz\/blog\/posts\/2552\/","url_meta":{"origin":847,"position":5},"title":"Musings on TIOBE","date":"14 Feb 2017","format":false,"excerpt":"It seems like only 12 months ago that a lot of fuss was being made about Delphi re-entering the TIOBE Index Top 10 and now it's done it again! Um... hang on... To enter the Top 10 again doesn't that mean that somewhere along the way it must have dropped\u2026","rel":"","context":"In &quot;Delphi&quot;","img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.deltics.co.nz\/blog\/wp-content\/uploads\/tiobe-volatilezone.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/847"}],"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=847"}],"version-history":[{"count":10,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/847\/revisions"}],"predecessor-version":[{"id":857,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/posts\/847\/revisions\/857"}],"wp:attachment":[{"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/media?parent=847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/categories?post=847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.deltics.co.nz\/blog\/wp-json\/wp\/v2\/tags?post=847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}