<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Alastair Revell - Blog - Coding</title>
    <link>http://blogs.rrs.co.uk/revella/</link>
    <description>The Web Log (Blog) of Alastair Revell, the Managing Consultant of Revell Research Systems, a Management and Technology Consulting Practice, based at Exeter in the United Kingdom.</description>
    <language>en-GB</language>
    <copyright>Revell Research Systems Limited</copyright>
    <lastBuildDate>Tue, 04 Sep 2007 08:26:43 GMT</lastBuildDate>
    <generator>RRS dasBlog 2.0.7226.0</generator>
    <managingEditor>revella@rrs.co.uk</managingEditor>
    <webMaster>revella@rrs.co.uk</webMaster>
    <item>
      <trackback:ping>http://blogs.rrs.co.uk/revella/Trackback.aspx?guid=fdfc809f-ef0c-4bad-940a-8c0127975186</trackback:ping>
      <pingback:server>http://blogs.rrs.co.uk/revella/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.rrs.co.uk/revella/PermaLink,guid,fdfc809f-ef0c-4bad-940a-8c0127975186.aspx</pingback:target>
      <dc:creator>Alastair Revell</dc:creator>
      <wfw:comment>http://blogs.rrs.co.uk/revella/CommentView,guid,fdfc809f-ef0c-4bad-940a-8c0127975186.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.rrs.co.uk/revella/SyndicationService.asmx/GetEntryCommentsRss?guid=fdfc809f-ef0c-4bad-940a-8c0127975186</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>Nostalgia for Turbo Pascal</title>
      <guid isPermaLink="false">http://blogs.rrs.co.uk/revella/PermaLink,guid,fdfc809f-ef0c-4bad-940a-8c0127975186.aspx</guid>
      <link>http://blogs.rrs.co.uk/revella/PermaLink,guid,fdfc809f-ef0c-4bad-940a-8c0127975186.aspx</link>
      <pubDate>Tue, 04 Sep 2007 08:26:43 GMT</pubDate>
      <description>&lt;p&gt;
I was interested in &lt;a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=fdfc809f-ef0c-4bad-940a-8c0127975186&amp;amp;url=http%3a%2f%2fwww.hans-eric.com%2f2007%2f09%2f02%2frest-in-peace-delphi%2f"&gt;Hans-Eric
Gr&amp;ouml;nlund's post&lt;/a&gt; on the decline of Delphi and (implicitly) its predecessor
Turbo Pascal. I used Turbo Pascal extensively in the late 1980s and early 1990s, particularly
versions 4.0 and 5.5, and then later Turbo Pascal for Windows 1.0 and 1.5.
&lt;/p&gt;
&lt;p&gt;
Version 5.5 introduced me to objected-oriented programming (OOP) in practical terms
and I fondly remember the OOP guide that was part of the documentation for version
5.5.
&lt;/p&gt;
&lt;p&gt;
I stopped using Turbo Pascal for Windows in favour of Visual Basic and never really
adopted Delphi, which I always thought would have faired better if it had been called
Visual Pascal.
&lt;/p&gt;
&lt;p&gt;
A considerable amount of my original code library built in Pascal survives today as
part of&amp;nbsp;the internal &lt;a target="_blank" href="http://blogs.rrs.co.uk/revella/ct.ashx?id=fdfc809f-ef0c-4bad-940a-8c0127975186&amp;amp;url=http%3a%2f%2fwww.rrs.co.uk"&gt;Revell
Research Systems&lt;/a&gt; code library, having been ported to the .NET Framework. Indeed,
much of my thinking around &lt;a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=fdfc809f-ef0c-4bad-940a-8c0127975186&amp;amp;url=http%3a%2f%2fblogs.rrs.co.uk%2frevella%2fpermalink%2cguid%2c404fc7bf-9ab7-4092-9d55-fe74e55e16fa.aspx"&gt;bannering&lt;/a&gt; emerged
while writing code in Turbo Pascal and 6502 Assembly and was much influenced by Lance
Leventhal's approach to documenting assembly code.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=fdfc809f-ef0c-4bad-940a-8c0127975186" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is produced by &lt;a href="http://www.rrs.co.uk"&gt;Revell Research Systems&lt;/a&gt;.</description>
      <comments>http://blogs.rrs.co.uk/revella/CommentView,guid,fdfc809f-ef0c-4bad-940a-8c0127975186.aspx</comments>
      <category>Coding</category>
    </item>
    <item>
      <trackback:ping>http://blogs.rrs.co.uk/revella/Trackback.aspx?guid=7fad1202-0e3a-4e38-af11-deaf22e7fa96</trackback:ping>
      <pingback:server>http://blogs.rrs.co.uk/revella/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.rrs.co.uk/revella/PermaLink,guid,7fad1202-0e3a-4e38-af11-deaf22e7fa96.aspx</pingback:target>
      <dc:creator>Alastair Revell</dc:creator>
      <wfw:comment>http://blogs.rrs.co.uk/revella/CommentView,guid,7fad1202-0e3a-4e38-af11-deaf22e7fa96.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.rrs.co.uk/revella/SyndicationService.asmx/GetEntryCommentsRss?guid=7fad1202-0e3a-4e38-af11-deaf22e7fa96</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>Language Convergence</title>
      <guid isPermaLink="false">http://blogs.rrs.co.uk/revella/PermaLink,guid,7fad1202-0e3a-4e38-af11-deaf22e7fa96.aspx</guid>
      <link>http://blogs.rrs.co.uk/revella/PermaLink,guid,7fad1202-0e3a-4e38-af11-deaf22e7fa96.aspx</link>
      <pubDate>Wed, 22 Aug 2007 11:54:58 GMT</pubDate>
      <description>&lt;p&gt;
I've just read an article on &lt;a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=7fad1202-0e3a-4e38-af11-deaf22e7fa96&amp;amp;url=http%3a%2f%2fwww.hans-eric.com%2f2007%2f07%2f20%2fjava-versus-cnet-i-have-been-working-on-an-arti%2f"&gt;Hans-Eric
Gr&amp;ouml;nlund's blog&lt;/a&gt;, which discusses how close Java and C# are as languages.
He concludes that &amp;quot;C#.NET is the best platform for Windows based systems since
it was in fact designed for it. Java on the other hand is the only option for systems
that are targeting other operating systems.&amp;quot;
&lt;/p&gt;
&lt;p&gt;
I would agree that Java is probably the only realistic option for systems targeting
non-Windows environments. However, I would be reluctant to assert that C# was the
best language for Windows development, although&amp;nbsp;I would certainly agree that
.NET is now the best platform for it.
&lt;/p&gt;
&lt;p&gt;
The issue is that on this front we are discussing three levels: the language, the
platform and the operating system. The only language supported by the &amp;quot;Java&amp;quot;
platform is Java, but it targets multiple operating systems; whereas .NET supports
multiple languages and mainly targets the Windows operating system (although as Hans-Eric
mentions the Mono project widens this base a little).
&lt;/p&gt;
&lt;p&gt;
While I would certainly agree that C# is the lead language for the .NET platform,
I would suggest that the differences between the majority of the .NET languages (such
as VB.NET, etc) are now almost non-existent, which leads to an interesting conclusion.
&lt;/p&gt;
&lt;p&gt;
It seems to me that an undeniable trend is that modern programming languages are converging
in terms of their functionality and that sooner or later the choice between one language
and another will largely be down to personal preference over the syntax used by a
particular language.
&lt;/p&gt;
&lt;p&gt;
Obviously, this trend is driven by the use of virtual machines that run compiled bytecode
(ie: virtual machine code) rather than native machine code.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=7fad1202-0e3a-4e38-af11-deaf22e7fa96" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is produced by &lt;a href="http://www.rrs.co.uk"&gt;Revell Research Systems&lt;/a&gt;.</description>
      <comments>http://blogs.rrs.co.uk/revella/CommentView,guid,7fad1202-0e3a-4e38-af11-deaf22e7fa96.aspx</comments>
      <category>Coding</category>
    </item>
    <item>
      <trackback:ping>http://blogs.rrs.co.uk/revella/Trackback.aspx?guid=38a1e7c2-bb8b-43fb-849f-7801289958c1</trackback:ping>
      <pingback:server>http://blogs.rrs.co.uk/revella/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.rrs.co.uk/revella/PermaLink,guid,38a1e7c2-bb8b-43fb-849f-7801289958c1.aspx</pingback:target>
      <dc:creator>Alastair Revell</dc:creator>
      <wfw:comment>http://blogs.rrs.co.uk/revella/CommentView,guid,38a1e7c2-bb8b-43fb-849f-7801289958c1.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.rrs.co.uk/revella/SyndicationService.asmx/GetEntryCommentsRss?guid=38a1e7c2-bb8b-43fb-849f-7801289958c1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I understand from <a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=38a1e7c2-bb8b-43fb-849f-7801289958c1&amp;url=http%3a%2f%2fblogs.msdn.com%2ftomholl%2farchive%2f2007%2f04%2f05%2fjust-released-enterprise-library-3-0-april-2007.aspx">Tom
Hollander's Blog</a> that Microsoft's Pattern &amp; Practices team have just
released Enterprise Library 3.0.<br /><br />
To quote Microsoft:-
</p>
        <blockquote dir="ltr" style="margin-right: 0px">
          <p>
The patterns &amp; practices Enterprise Library is a library of application blocks
designed to assist developers with common enterprise development challenges. Application
blocks are a type of guidance, provided as source code that can be used "as is,"
extended, or modified by developers to use on enterprise development projects.
</p>
        </blockquote>
        <p>
The previous two libraries have been great resources for the .NET developer community.
I understand that this new library has no breaking changes, which is great news.
</p>
        <p>
I haven't had time recently to follow the Community Technology Preview (CTP) releases
while this version of the library has been in development, but I am definitely looking
forward to reviewing its new application blocks.
</p>
        <img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=38a1e7c2-bb8b-43fb-849f-7801289958c1" />
        <br />
        <hr />
This weblog is produced by <a href="http://www.rrs.co.uk">Revell Research Systems</a>.</body>
      <title>Enterprise Library 3.0</title>
      <guid isPermaLink="false">http://blogs.rrs.co.uk/revella/PermaLink,guid,38a1e7c2-bb8b-43fb-849f-7801289958c1.aspx</guid>
      <link>http://blogs.rrs.co.uk/revella/PermaLink,guid,38a1e7c2-bb8b-43fb-849f-7801289958c1.aspx</link>
      <pubDate>Sat, 07 Apr 2007 12:56:42 GMT</pubDate>
      <description>&lt;p&gt;
I understand from &lt;a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=38a1e7c2-bb8b-43fb-849f-7801289958c1&amp;amp;url=http%3a%2f%2fblogs.msdn.com%2ftomholl%2farchive%2f2007%2f04%2f05%2fjust-released-enterprise-library-3-0-april-2007.aspx"&gt;Tom
Hollander's Blog&lt;/a&gt; that Microsoft's Pattern&amp;nbsp;&amp;amp; Practices team have just
released Enterprise Library 3.0.&lt;br /&gt;
&lt;br /&gt;
To quote Microsoft:-
&lt;/p&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt; 
&lt;p&gt;
The patterns &amp;amp; practices Enterprise Library is a library of application blocks
designed to assist developers with common enterprise development challenges. Application
blocks are a type of guidance, provided as source code that can be used &amp;quot;as is,&amp;quot;
extended, or modified by developers to use on enterprise development projects.
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
The previous two libraries have been great resources for the .NET developer community.
I understand that this new library has no breaking changes, which is great news.
&lt;/p&gt;
&lt;p&gt;
I haven't had time recently to follow the Community Technology Preview (CTP) releases
while this version of the library has been in development, but I am definitely looking
forward to reviewing its new application blocks.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=38a1e7c2-bb8b-43fb-849f-7801289958c1" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is produced by &lt;a href="http://www.rrs.co.uk"&gt;Revell Research Systems&lt;/a&gt;.</description>
      <comments>http://blogs.rrs.co.uk/revella/CommentView,guid,38a1e7c2-bb8b-43fb-849f-7801289958c1.aspx</comments>
      <category>.NET</category>
      <category>Coding</category>
    </item>
    <item>
      <trackback:ping>http://blogs.rrs.co.uk/revella/Trackback.aspx?guid=2e9958dc-2cac-4dbd-82b2-b76123c4b103</trackback:ping>
      <pingback:server>http://blogs.rrs.co.uk/revella/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.rrs.co.uk/revella/PermaLink,guid,2e9958dc-2cac-4dbd-82b2-b76123c4b103.aspx</pingback:target>
      <dc:creator>Alastair Revell</dc:creator>
      <wfw:comment>http://blogs.rrs.co.uk/revella/CommentView,guid,2e9958dc-2cac-4dbd-82b2-b76123c4b103.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.rrs.co.uk/revella/SyndicationService.asmx/GetEntryCommentsRss?guid=2e9958dc-2cac-4dbd-82b2-b76123c4b103</wfw:commentRss>
      <title>Irritation with Generics</title>
      <guid isPermaLink="false">http://blogs.rrs.co.uk/revella/PermaLink,guid,2e9958dc-2cac-4dbd-82b2-b76123c4b103.aspx</guid>
      <link>http://blogs.rrs.co.uk/revella/PermaLink,guid,2e9958dc-2cac-4dbd-82b2-b76123c4b103.aspx</link>
      <pubDate>Thu, 18 Jan 2007 13:05:42 GMT</pubDate>
      <description>&lt;p&gt;
I have been porting our code library to the .NET Framework 2.0 and have been using
the new generics feature in many places to improve the code.
&lt;/p&gt;
&lt;p&gt;
I've generally been impressed by the functionality offered by generics, but was a
little disillusioned when I realised that they would be of little or no use in refactoring
our matrix and vector maths libraries.
&lt;/p&gt;
&lt;p&gt;
Perhaps, as a graduate mathematician, I had been more excited than most by the prospect
of being able to write generic matrix and vector classes that could be instantiated
just as easily on a built-in &lt;strong&gt;Double&lt;/strong&gt; type as a custom &lt;strong&gt;Complex&lt;/strong&gt; number
type.
&lt;/p&gt;
&lt;p&gt;
However, the gradual realisation dawned that the built-in types in the .NET Framework
don't share any common &lt;em&gt;numeric&lt;/em&gt; ancestor type and don't implement a common&amp;nbsp;interface
such as &lt;strong&gt;IArithmetic&lt;/strong&gt; that might be used to constrain the generic matrix
and vector classes to being instantiated ONLY over&amp;nbsp;&lt;em&gt;numeric&lt;/em&gt; types.
&lt;/p&gt;
&lt;p&gt;
R&amp;uuml;diger Klaehn, a German freelance programmer,&amp;nbsp;has proposed that Microsoft
should augment the basic numeric types in the .NET Framework with an &lt;strong&gt;IArithmetic&lt;/strong&gt; interface
that would define the basic arithmetic operators on these types. This&amp;nbsp;would allow
generic types to be defined over types that guarantee this interface, allowing such
classes as a matrix or vector to be built that can be constrained to types that support
basic arithmetic.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=2e9958dc-2cac-4dbd-82b2-b76123c4b103" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is produced by &lt;a href="http://www.rrs.co.uk"&gt;Revell Research Systems&lt;/a&gt;.</description>
      <comments>http://blogs.rrs.co.uk/revella/CommentView,guid,2e9958dc-2cac-4dbd-82b2-b76123c4b103.aspx</comments>
      <category>Coding</category>
    </item>
    <item>
      <trackback:ping>http://blogs.rrs.co.uk/revella/Trackback.aspx?guid=92292934-782c-4726-a51d-c9f04493bc1d</trackback:ping>
      <pingback:server>http://blogs.rrs.co.uk/revella/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.rrs.co.uk/revella/PermaLink,guid,92292934-782c-4726-a51d-c9f04493bc1d.aspx</pingback:target>
      <dc:creator>Alastair Revell</dc:creator>
      <wfw:comment>http://blogs.rrs.co.uk/revella/CommentView,guid,92292934-782c-4726-a51d-c9f04493bc1d.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.rrs.co.uk/revella/SyndicationService.asmx/GetEntryCommentsRss?guid=92292934-782c-4726-a51d-c9f04493bc1d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font face="verdana" color="#003300">We've recently started porting our large .NET
class libraries from .NET 1.1 to .NET 2.0, which has to date been a fairly smooth
process. We've also been revising and enhancing classes as we go and I stumbled across
a rather nasty catch during this process.</font>
        </p>
        <p>
          <font face="verdana">I was working on a numerical class library that represents trigonometric
angles, which is heavily dependent on the <strong>Double</strong> type (as you might
expect).</font>
        </p>
        <p>
          <font face="verdana">It took me quite a while to track down the cause of some strange
results I was getting from our code. The essence of the problem was similar to the
code below:-</font> 
</p>
        <p>
          <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
            <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
              <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">Dim</span> result <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">As</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">Double</span><span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent">=</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">Double</span>.MaxValue <span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent">*</span> 3/10</span>
          </span>
        </p>
        <p>
(Obviously, the situation was a little more complex!)
</p>
        <p>
What quantity would you expect result to hold? Would you be surprised to learn that
it was PositiveInfinity? I was initially...
</p>
        <p>
A quick scan of the line suggests that result will hold something well below the maximum
value allowed by the Double type. However, the VB.NET compiler sticks to the normal
rules of operator precedence and finds itself with a value three times greater than
the maximum allowable value (after multiplying by 3), which it concludes is PositiveInfinity.
It then divides this by 10, which nonetheless still evaluates to PositiveInfinity...
</p>
        <p>
Now consider:-
</p>
        <p>
          <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
            <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
              <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">Dim</span> value <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">As</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">Double</span><br /><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">Dim</span> result <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">As</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">Double</span><br /><br />
value <span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent">=</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent">Double</span>.MaxValue<br />
result <span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent">=</span> value <span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent">*</span> 3 <span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent">/</span> 10</span>
          </span>
        </p>
        <p>
          <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
            <font face="verdana" color="#003300">
              <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
                <font face="verdana" color="#003300">What
quantity would you expect <font face="courier new">result</font> to hold? Would you
be surprised to learn that it was NOT <strong>PositiveInfinity </strong>but the <em>correct</em> mathematical
value?</font>
              </span>
            </font>
          </span>
        </p>
        <p>
          <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
            <font face="verdana" color="#003300">
              <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
                <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
                  <font face="verdana" color="#003300">
                    <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
                      <font face="verdana" color="#003300">Obviously,
the VB.NET compiler evaluates differently if the right-hand side of an expression
is a combination of constants and literals rather than based on a variable.</font>
                    </span>
                  </font>
                </span>
              </span>
            </font>
          </span>
        </p>
        <img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=92292934-782c-4726-a51d-c9f04493bc1d" />
        <br />
        <hr />
This weblog is produced by <a href="http://www.rrs.co.uk">Revell Research Systems</a>.</body>
      <title>Infinity!</title>
      <guid isPermaLink="false">http://blogs.rrs.co.uk/revella/PermaLink,guid,92292934-782c-4726-a51d-c9f04493bc1d.aspx</guid>
      <link>http://blogs.rrs.co.uk/revella/PermaLink,guid,92292934-782c-4726-a51d-c9f04493bc1d.aspx</link>
      <pubDate>Tue, 31 Oct 2006 17:52:39 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font face="verdana" color="#003300"&gt;We've recently started porting our large .NET
class libraries from .NET 1.1 to .NET 2.0, which has to date been a fairly smooth
process. We've also been revising and enhancing classes as we go and I stumbled across
a rather nasty catch during this process.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="verdana"&gt;I was working on a numerical class library that represents trigonometric
angles, which is heavily dependent on the &lt;strong&gt;Double&lt;/strong&gt; type (as you might
expect).&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="verdana"&gt;It took me quite a while to track down the cause of some strange
results I was getting from our code. The essence of the problem was similar to the
code below:-&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt;&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt;&lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;Dim&lt;/span&gt; result &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;As&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;Double&lt;/span&gt; &lt;span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent"&gt;=&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;Double&lt;/span&gt;.MaxValue &lt;span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent"&gt;*&lt;/span&gt; 3/10&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
(Obviously, the situation was a little more complex!)
&lt;/p&gt;
&lt;p&gt;
What quantity would you expect result to hold? Would you be surprised to learn that
it was PositiveInfinity? I was initially...
&lt;/p&gt;
&lt;p&gt;
A quick scan of the line suggests that result will hold something well below the maximum
value allowed by the Double type. However, the VB.NET compiler sticks to the normal
rules of operator precedence and finds itself with a value three times greater than
the maximum allowable value (after multiplying by 3), which it concludes is PositiveInfinity.
It then divides this by 10, which nonetheless still evaluates to PositiveInfinity...
&lt;/p&gt;
&lt;p&gt;
Now consider:-
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt;&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt;&lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;Dim&lt;/span&gt; value &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;As&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;Double&lt;/span&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;Dim&lt;/span&gt; result &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;As&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;Double&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
value &lt;span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent"&gt;=&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt;Double&lt;/span&gt;.MaxValue&lt;br /&gt;
result &lt;span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent"&gt;=&lt;/span&gt; value &lt;span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent"&gt;*&lt;/span&gt; 3 &lt;span style="font-size: 11px; color: red; font-family: courier new; background-color: transparent"&gt;/&lt;/span&gt; 10&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt;&lt;font face="verdana" color="#003300"&gt;&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt;&lt;font face="verdana" color="#003300"&gt;What
quantity would you expect &lt;font face="courier new"&gt;result&lt;/font&gt; to hold? Would you
be surprised to learn that it was NOT &lt;strong&gt;PositiveInfinity &lt;/strong&gt;but the &lt;em&gt;correct&lt;/em&gt; mathematical
value?&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt;&lt;font face="verdana" color="#003300"&gt;&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt;&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt;&lt;font face="verdana" color="#003300"&gt;&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt;&lt;font face="verdana" color="#003300"&gt;Obviously,
the VB.NET compiler evaluates differently if the right-hand side of an expression
is a combination of constants and literals rather than based on a variable.&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=92292934-782c-4726-a51d-c9f04493bc1d" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is produced by &lt;a href="http://www.rrs.co.uk"&gt;Revell Research Systems&lt;/a&gt;.</description>
      <comments>http://blogs.rrs.co.uk/revella/CommentView,guid,92292934-782c-4726-a51d-c9f04493bc1d.aspx</comments>
      <category>.NET</category>
      <category>Coding</category>
    </item>
    <item>
      <trackback:ping>http://blogs.rrs.co.uk/revella/Trackback.aspx?guid=25317174-a40a-4795-be17-10cd8396b49e</trackback:ping>
      <pingback:server>http://blogs.rrs.co.uk/revella/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.rrs.co.uk/revella/PermaLink,guid,25317174-a40a-4795-be17-10cd8396b49e.aspx</pingback:target>
      <dc:creator>Alastair Revell</dc:creator>
      <wfw:comment>http://blogs.rrs.co.uk/revella/CommentView,guid,25317174-a40a-4795-be17-10cd8396b49e.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.rrs.co.uk/revella/SyndicationService.asmx/GetEntryCommentsRss?guid=25317174-a40a-4795-be17-10cd8396b49e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I note from <a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=25317174-a40a-4795-be17-10cd8396b49e&amp;url=http%3a%2f%2fblogs.msdn.com%2fsomasegar%2farchive%2f2006%2f06%2f09%2f624300.aspx">Somasegar's
blog</a> that Microsoft are to rebrand their forthcoming WinFX technologies as .NET
Framework 3.0. (<a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=25317174-a40a-4795-be17-10cd8396b49e&amp;url=http%3a%2f%2fwww.microsoft.com%2fpresspass%2fexec%2fsomasegar%2fdefault.mspx">S
Somasegar</a> is Microsoft's Corporate Vice-President of the Developer Division.)
</p>
        <p>
This is essentially the existing .NET 2.0 Framework combined with the new WinFX technologies.
The new technologies are Windows Presentation Foundation (WPF), Windows Communication
Foundation (WCF), Windows Workflow Foundation (WF) and Windows Card Space (WCS), together
with some supporting new base class libraries.
</p>
        <p>
It is apparent that this name change has not met with universal approval from the
developer community.
</p>
        <p>
However, it is equally clear that many people were finding it difficult to understand
exactly how WinFX fitted in with Microsoft's overall strategy. In particular, a number
of people seem to believe that WinFX was to replace the .NET Framework. In technical
terms, WinFX has only ever been an extension of the existing .NET Framework 2.0.
</p>
        <p>
I actually think that in some respects WinFX is a better name for the .NET Framework,
since it is clear that the .NET Framework is destined to be the new way of programming
Windows. WinFX is really the next step in the Win16 and Win32 series...
</p>
        <p>
Ultimately, I'm happy with Microsoft .NET Framework 3.0 (WinFX).
</p>
        <img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=25317174-a40a-4795-be17-10cd8396b49e" />
        <br />
        <hr />
This weblog is produced by <a href="http://www.rrs.co.uk">Revell Research Systems</a>.</body>
      <title>.NET Framework 3.0</title>
      <guid isPermaLink="false">http://blogs.rrs.co.uk/revella/PermaLink,guid,25317174-a40a-4795-be17-10cd8396b49e.aspx</guid>
      <link>http://blogs.rrs.co.uk/revella/PermaLink,guid,25317174-a40a-4795-be17-10cd8396b49e.aspx</link>
      <pubDate>Sun, 18 Jun 2006 12:01:41 GMT</pubDate>
      <description>&lt;p&gt;
I note from &lt;a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=25317174-a40a-4795-be17-10cd8396b49e&amp;amp;url=http%3a%2f%2fblogs.msdn.com%2fsomasegar%2farchive%2f2006%2f06%2f09%2f624300.aspx"&gt;Somasegar's
blog&lt;/a&gt; that Microsoft are to rebrand their forthcoming WinFX technologies as .NET
Framework 3.0. (&lt;a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=25317174-a40a-4795-be17-10cd8396b49e&amp;amp;url=http%3a%2f%2fwww.microsoft.com%2fpresspass%2fexec%2fsomasegar%2fdefault.mspx"&gt;S
Somasegar&lt;/a&gt; is Microsoft's Corporate Vice-President of the Developer Division.)
&lt;/p&gt;
&lt;p&gt;
This is essentially the existing .NET 2.0 Framework combined with the new WinFX technologies.
The new technologies are Windows Presentation Foundation (WPF), Windows Communication
Foundation (WCF), Windows Workflow Foundation (WF) and Windows Card Space (WCS), together
with some supporting new base class libraries.
&lt;/p&gt;
&lt;p&gt;
It is apparent that this name change has not met with universal approval from the
developer community.
&lt;/p&gt;
&lt;p&gt;
However, it is equally clear that many people were finding it difficult to understand
exactly how WinFX fitted in with Microsoft's overall strategy. In particular, a number
of people seem to believe that WinFX was to replace the .NET Framework. In technical
terms, WinFX has only ever been an extension of the existing .NET Framework 2.0.
&lt;/p&gt;
&lt;p&gt;
I actually think that in some respects WinFX is a better name for the .NET Framework,
since it is clear that the .NET Framework is destined to be the new way of programming
Windows. WinFX is really the next step in the Win16 and Win32 series...
&lt;/p&gt;
&lt;p&gt;
Ultimately, I'm happy with Microsoft .NET Framework 3.0 (WinFX).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=25317174-a40a-4795-be17-10cd8396b49e" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is produced by &lt;a href="http://www.rrs.co.uk"&gt;Revell Research Systems&lt;/a&gt;.</description>
      <comments>http://blogs.rrs.co.uk/revella/CommentView,guid,25317174-a40a-4795-be17-10cd8396b49e.aspx</comments>
      <category>.NET</category>
      <category>Coding</category>
    </item>
    <item>
      <trackback:ping>http://blogs.rrs.co.uk/revella/Trackback.aspx?guid=404fc7bf-9ab7-4092-9d55-fe74e55e16fa</trackback:ping>
      <pingback:server>http://blogs.rrs.co.uk/revella/pingback.aspx</pingback:server>
      <pingback:target>http://blogs.rrs.co.uk/revella/PermaLink,guid,404fc7bf-9ab7-4092-9d55-fe74e55e16fa.aspx</pingback:target>
      <dc:creator>Alastair Revell</dc:creator>
      <wfw:comment>http://blogs.rrs.co.uk/revella/CommentView,guid,404fc7bf-9ab7-4092-9d55-fe74e55e16fa.aspx</wfw:comment>
      <wfw:commentRss>http://blogs.rrs.co.uk/revella/SyndicationService.asmx/GetEntryCommentsRss?guid=404fc7bf-9ab7-4092-9d55-fe74e55e16fa</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am a strong advocate of bannering (ie: the use of boiler-plate comments in source
code). Typically, bannering provides some form of "header" to a module and
each of its subroutines, together with standard "sections" within each routine
for defining its purpose, interface and for stating any assumptions that have been
made. It also includes comment <em>dividers that</em> break the code within a routine
into logical chunks.
</p>
        <p>
I believe that bannering, along with other coding standards, makes code more approachable
and therefore more valuable. It especially helps with maintenance and re-use, where
the current programmer may not be the original developer.
</p>
        <p>
Making code more approachable is important to commercial organisations looking to
maximise their return-on-investment (ROI). However, such standards tend to be derided
by developers who predominantly work on their own because they cannot see the value.
</p>
        <p>
A typical piece of bannering might be:- 
<br /><br /><br /><span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Rem</span><font color="#006400">*********************************************<br /></font><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Rem</span><font color="#008000"> *
SUB </font><font color="#008000">Routine                              
*<br /></font><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Rem</span><font color="#008000">*********************************************</font><br /><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Sub</span> Routine 
<br /><br /><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Rem</span> **
Purpose **********************************<br /><span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"> 'The
purpose of this routine is to demonstrate </span><br /><span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"> 'bannering.</span><br /><br /><br /><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Rem</span><font color="#008000">**
Declarations *****************************<br /></font><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Dim</span> variable1 <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> As</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> String</span>             <span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"> 'A
String</span><br /><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Dim</span> variable2 <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> As</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> String</span>             <span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"> 'An
Integer</span><br /><br /><br /><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Rem</span><font color="#008000">**
Routine **********************************<br /></font><span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"> 'The
real code would start here... </span><br /><br /><br /><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> End</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Sub</span><span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent">'Routine<br /><br /><br /></span></span><font size="1"><em>Generally, the bannering would stretch to column
90 rather than to where it does above. Certainly, the variable names and corresponding
comments would be much more meaningful!</em></font></p>
        <p>
The banner box at the top highlights the start of the routine. This makes it very
easy to locate code while scanning the source. The 'Purpose' section is extremely
important and states what the routine does.<br /><br />
Anyone who has ever looked at someone else's code will realise how important this
simple section is. It helps people new to the code to immediately comprehend what
the aim of this particular routine is. Our internal coding standards at Revell Research
Systems stipulate that any input parameters and the return result for a function should
be woven into the Purpose section. The Purpose section is mandatory for every routine.<br /><br />
A typical Purpose banner for the VB.Net routine:-
</p>
        <p>
          <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
            <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Function
Left</span>(text <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> As</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> String</span>, <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"><font color="#000000">number</font></span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> As</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Integer</span>) <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> As</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> String</span></span>
        </p>
        <p dir="ltr" style="margin-right: 0px">
might be:-
</p>
        <blockquote dir="ltr" style="margin-right: 0px">
          <p dir="ltr" style="margin-right: 0px">
            <font color="#006400">The Purpose of this routine is to return the first &lt;number&gt;
characters from the left of &lt;text&gt;. If &lt;number&gt; is larger than the length
of &lt;text&gt; then the whole of &lt;text&gt; will be returned. &lt;number&gt; must
be zero or more, otherwise an exception will be thrown.</font>
          </p>
        </blockquote>
        <p dir="ltr" style="margin-right: 0px">
Angle brackets are used to identify the routine's parameters within the Purpose
text.<br /><br />
The 'Declarations' section is also important. Our guidelines stipulate that
all variables used inside a routine should be stated in this section and not declared
inline later in the code. The only exception to this rule is for variables declared
solely for use in controlling loops, such as in:-
</p>
        <blockquote dir="ltr" style="margin-right: 0px">
          <p>
            <span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent">
              <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> For</span> i <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> As</span><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Integer
= </span>1 <span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> to</span> 5<br /><br /><span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent">  
'....</span><br /><br /><span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"> Next</span></span>
          </p>
        </blockquote>
        <p>
          <span style="font-size: 11px; color: black; background-color: transparent">Our standards
insist that each declaration should be accompanied with a terse comment that elaborates
on the variable's use, although we also expect meaningful names to be used as
well to improve code readability. Our guidelines suggest that these comments should
start at column 50, but whatever, they should always start at the same column for
a particular Declaration section.</span>
        </p>
        <p dir="ltr" style="margin-right: 0px">
          <span style="font-size: 11px; color: black; background-color: transparent">Incidentally,
we also mandate that full XML comments are provided for declarations (and for such
matters as exceptions, etc).</span>
        </p>
        <p>
The 'Routine' section marks the start of the real code. We might use further <em>dividers </em>to
break up a particularly long routine, but our standing advice is to make the body
of routines shorter than one screen so that anyone reviewing the code can see the
whole routine on screen without needing to scroll. We believe this cuts down on errors
being introduced because some code is <em>out of sight</em> and therefore <em>out
of mind</em>.
</p>
        <p dir="ltr" style="margin-right: 0px">
Subsequent <em>dividers </em>should have appropriately descriptive names to <em>head
up</em> the code that follows. Consequently, someone skim-reading the code should
immediately be able to see the overall structure of a complicated routine. We use
these dividers less now in OOP code, but when developing procedural code from typical
Jackson Structure Diagrams (JSDs) such as SSADM 4.3's Update Process Models (UPMs)
or Enquiry Process Models (EPMs), we would have made dividers tally with key nodes
within these diagrams.
</p>
        <p dir="ltr" style="margin-right: 0px">
Our commenting standards also insist that routines should have their "end"
commented as well. So in VB.Net, <font color="#0000ff">End Sub</font> and <font color="#0000ff">End
Function</font> statements should be followed by the name of the corresponding routine
as a trailing comment. This is important because each End statement can then be easily
matched with its opening definition.
</p>
        <p dir="ltr" style="margin-right: 0px">
The <a target="_blank" href="http://blogs.rrs.co.uk/revella/ct.ashx?id=404fc7bf-9ab7-4092-9d55-fe74e55e16fa&amp;url=http%3a%2f%2fwww.rrs.co.uk">Revell
Research Systems</a> (RRS) standards also stipulate that code should not exceed column
90, which ensures that code can be printed at a reasonable font size on A4 paper.
The various banner lines are mandated to continue to column 90, which also provides
a visual cue to programmers when they need to consider wrapping code. Our guidelines
recommend that code should be wrapped at logical places within code rather than simply
where column 90 dictates. The guiding principal is that no code should ever extend
beyond column 90.
</p>
        <p dir="ltr" style="margin-right: 0px">
We used to also include much more extensive documentation in source code, but with
the advent of XML Comments in .NET, we have used this innovation to move documentary
comments out into subsidiary <em>comment files</em>. We realised early on that as
good as XML comments are, they do clutter the source code.
</p>
        <p dir="ltr" style="margin-right: 0px">
We insist on heavy documentation at Revell Research Systems because we think this
increases the code's value. The ability to provide comprehensive documentation
for any code library we have developed to either new team members or to contract developers
is invaluable. It helps them get up to speed quickly. It saves us money and improves
our profitability.
</p>
        <p dir="ltr" style="margin-right: 0px">
We also insist that code is commented, where appropriate, to explain what is going
on. However, we believe that commenting should not be excessive. Indeed, good code
almost never needs commenting. The choice of good identifier names combined with clear
code design should obviate the need to explain what is going on. It should be abundantly
clear.
</p>
        <p dir="ltr" style="margin-right: 0px">
Indeed, we review code to ensure that code is abundantly clear. If it is complicated
or convoluted, it gets re-written. If complicated code is ultimately proved to be
necessary, then we use comments to adequately explain what is going on. We would expect
supporting documentation (in XML comment files) to provide detailed explanations of
any algorithms being used, together with references to other sources.
</p>
        <p dir="ltr" style="margin-right: 0px">
These standards (together with code layout standards and the use of proper naming
conventions such as those dictated by Microsoft's <a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=404fc7bf-9ab7-4092-9d55-fe74e55e16fa&amp;url=http%3a%2f%2fmsdn.microsoft.com%2flibrary%2fdefault.asp%3furl%3d%2flibrary%2fen-us%2fcpgenref%2fhtml%2fcpconnetframeworkdesignguidelines.asp"> Design
Guidelines for Class Library Developers</a>) are important but are often derided by
less commercially oriented developers. I suspect that they concentrate on getting
the code to work without reflecting on the importance of reuse by others, simply because
they often work alone.
</p>
        <p dir="ltr" style="margin-right: 0px">
The key point is that commercially valuable code needs to be readily usable and understood
by programmers other than just the developer. The more readily understood the code
is then the more valuable that code must be. I believe that proper formatting, including
bannering, makes code more approachable and easier to share amongst teams. (Obviously,
the code also needs to be well-written!)
</p>
        <p dir="ltr" style="margin-right: 0px">
The problem is that this requires developers to subvert their egos. Developers tend
to believe that their code is particularly special. Their style is the best and it
provides a way of stamping their identity onto the code. Few home-hobbyists and small
developers are open to the prospect of others using their code.
</p>
        <p dir="ltr" style="margin-right: 0px">
However, commercial code ideally will be reused by others, perhaps long after the
developer has left the organisation. An organisation's corpus of code will be
much more <em>approachable </em>if it is presented in a consistent way. It will also
help to facilitate much greater code re-use, which is one of the Holy Grails of software
engineering.
</p>
        <p dir="ltr" style="margin-right: 0px">
I've insisted on these standards while teaching undergraduates over the past ten
years or more. Initially, there is huge resistance, particularly from students who
have already been developing code. However, eventually the message that coding standards
are extremely valuable does get through, particularly when they start working in teams.
</p>
        <p dir="ltr" style="margin-right: 0px">
What I do know is that marking well-presented, "bannered" code is much easier.
It is much more approachable...!
</p>
        <img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=404fc7bf-9ab7-4092-9d55-fe74e55e16fa" />
        <br />
        <hr />
This weblog is produced by <a href="http://www.rrs.co.uk">Revell Research Systems</a>.</body>
      <title>Bannering</title>
      <guid isPermaLink="false">http://blogs.rrs.co.uk/revella/PermaLink,guid,404fc7bf-9ab7-4092-9d55-fe74e55e16fa.aspx</guid>
      <link>http://blogs.rrs.co.uk/revella/PermaLink,guid,404fc7bf-9ab7-4092-9d55-fe74e55e16fa.aspx</link>
      <pubDate>Sat, 10 Jun 2006 12:07:15 GMT</pubDate>
      <description>&lt;p&gt;
I am a strong advocate of bannering (ie: the use of boiler-plate comments in source
code). Typically, bannering provides some form of &amp;quot;header&amp;quot; to a module and
each of its subroutines, together with standard &amp;quot;sections&amp;quot; within each routine
for defining its purpose, interface and for stating any assumptions that have been
made. It also includes comment &lt;em&gt;dividers that&lt;/em&gt; break the code within a routine
into logical chunks.
&lt;/p&gt;
&lt;p&gt;
I believe that bannering, along with other coding standards, makes code more approachable
and therefore more valuable. It especially helps with maintenance and re-use, where
the current programmer may not be the original developer.
&lt;/p&gt;
&lt;p&gt;
Making code more approachable is important to commercial organisations looking to
maximise their return-on-investment (ROI). However, such standards tend to be derided
by developers who predominantly work on their own because they cannot see the value.
&lt;/p&gt;
&lt;p&gt;
A typical piece of bannering might be:- 
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Rem&lt;/span&gt; &lt;font color="#006400"&gt;*********************************************&lt;br /&gt;
&lt;/font&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Rem&lt;/span&gt;&lt;font color="#008000"&gt; *
SUB &lt;/font&gt;&lt;font color="#008000"&gt;Routine&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
*&lt;br /&gt;
&lt;/font&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Rem&lt;/span&gt; &lt;font color="#008000"&gt;*********************************************&lt;/font&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Sub&lt;/span&gt; Routine 
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Rem&lt;/span&gt; **
Purpose **********************************&lt;br /&gt;
&lt;span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"&gt; &amp;#39;The
purpose of this routine is to demonstrate &lt;/span&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"&gt; &amp;#39;bannering.&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Rem&lt;/span&gt; &lt;font color="#008000"&gt;**
Declarations *****************************&lt;br /&gt;
&lt;/font&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Dim&lt;/span&gt; variable1 &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; As&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; String&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"&gt; &amp;#39;A
String&lt;/span&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Dim&lt;/span&gt; variable2 &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; As&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; String&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"&gt; &amp;#39;An
Integer&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Rem&lt;/span&gt; &lt;font color="#008000"&gt;**
Routine **********************************&lt;br /&gt;
&lt;/font&gt; &lt;span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"&gt; &amp;#39;The
real code would start here... &lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; End&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Sub&lt;/span&gt;&lt;span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"&gt;&amp;#39;Routine&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;font size="1"&gt;&lt;em&gt;Generally, the bannering would stretch to column
90 rather than to where it does above. Certainly, the variable names and corresponding
comments would be much more meaningful!&lt;/em&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
The banner box at the top highlights the start of the routine. This makes it very
easy to locate code while scanning the source. The &amp;#39;Purpose&amp;#39; section is extremely
important and states what the routine does.&lt;br /&gt;
&lt;br /&gt;
Anyone who has ever looked at someone else&amp;#39;s code will realise how important this
simple section is. It helps people new to the code to immediately comprehend what
the aim of this particular routine is. Our internal coding standards at Revell Research
Systems stipulate that any input parameters and the return result for a function should
be woven into the Purpose section. The Purpose section is mandatory for every routine.&lt;br /&gt;
&lt;br /&gt;
A typical Purpose banner for the VB.Net routine:-
&lt;/p&gt;
&lt;p&gt;
&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Function
Left&lt;/span&gt;(text &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; As&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; String&lt;/span&gt;, &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; &lt;font color="#000000"&gt;number&lt;/font&gt;&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; As&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Integer&lt;/span&gt;) &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; As&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; String&lt;/span&gt; &lt;/span&gt;
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
might be:-
&lt;/p&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt; 
&lt;p dir="ltr" style="margin-right: 0px"&gt;
&lt;font color="#006400"&gt;The Purpose of this routine is to return the first &amp;lt;number&amp;gt;
characters from the left of &amp;lt;text&amp;gt;. If &amp;lt;number&amp;gt; is larger than the length
of &amp;lt;text&amp;gt; then the whole of &amp;lt;text&amp;gt; will be returned. &amp;lt;number&amp;gt; must
be zero or more, otherwise an exception will be thrown.&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p dir="ltr" style="margin-right: 0px"&gt;
Angle brackets are used to identify the routine&amp;#39;s parameters within the Purpose
text.&lt;br /&gt;
&lt;br /&gt;
The &amp;#39;Declarations&amp;#39; section is also important. Our guidelines stipulate that
all variables used inside a routine should be stated in this section and not declared
inline later in the code. The only exception to this rule is for variables declared
solely for use in controlling loops, such as in:-
&lt;/p&gt;
&lt;blockquote dir="ltr" style="margin-right: 0px"&gt; 
&lt;p&gt;
&lt;span style="font-size: 11px; color: black; font-family: courier new; background-color: transparent"&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; For&lt;/span&gt; i &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; As&lt;/span&gt; &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Integer
= &lt;/span&gt;1 &lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; to&lt;/span&gt; 5&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: green; font-family: courier new; background-color: transparent"&gt;&amp;nbsp;&amp;nbsp;
&amp;#39;....&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style="font-size: 11px; color: blue; font-family: courier new; background-color: transparent"&gt; Next&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;span style="font-size: 11px; color: black; background-color: transparent"&gt;Our standards
insist that each declaration should be accompanied with a terse comment that elaborates
on the variable&amp;#39;s use, although we also expect meaningful names to be used as
well to improve code readability. Our guidelines suggest that these comments should
start at column 50, but whatever, they should always start at the same column for
a particular Declaration section.&lt;/span&gt;
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
&lt;span style="font-size: 11px; color: black; background-color: transparent"&gt;Incidentally,
we also mandate that full XML comments are provided for declarations (and for such
matters as exceptions, etc).&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
The &amp;#39;Routine&amp;#39; section marks the start of the real code. We might use further &lt;em&gt;dividers &lt;/em&gt;to
break up a particularly long routine, but our standing advice is to make the body
of routines shorter than one screen so that anyone reviewing the code can see the
whole routine on screen without needing to scroll. We believe this cuts down on errors
being introduced because some code is &lt;em&gt;out of sight&lt;/em&gt; and therefore &lt;em&gt;out
of mind&lt;/em&gt;.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
Subsequent &lt;em&gt;dividers &lt;/em&gt;should have appropriately descriptive names to &lt;em&gt;head
up&lt;/em&gt; the code that follows. Consequently, someone skim-reading the code should
immediately be able to see the overall structure of a complicated routine. We use
these dividers less now in OOP code, but when developing procedural code from typical
Jackson Structure Diagrams (JSDs) such as SSADM 4.3&amp;#39;s Update Process Models (UPMs)
or Enquiry Process Models (EPMs), we would have made dividers tally with key nodes
within these diagrams.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
Our commenting standards also insist that routines should have their &amp;quot;end&amp;quot;
commented as well. So in VB.Net, &lt;font color="#0000ff"&gt;End Sub&lt;/font&gt; and &lt;font color="#0000ff"&gt;End
Function&lt;/font&gt; statements should be followed by the name of the corresponding routine
as a trailing comment. This is important because each End statement can then be easily
matched with its opening definition.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
The &lt;a target="_blank" href="http://blogs.rrs.co.uk/revella/ct.ashx?id=404fc7bf-9ab7-4092-9d55-fe74e55e16fa&amp;amp;url=http%3a%2f%2fwww.rrs.co.uk"&gt;Revell
Research Systems&lt;/a&gt; (RRS) standards also stipulate that code should not exceed column
90, which ensures that code can be printed at a reasonable font size on A4 paper.
The various banner lines are mandated to continue to column 90, which also provides
a visual cue to programmers when they need to consider wrapping code. Our guidelines
recommend that code should be wrapped at logical places within code rather than simply
where column 90 dictates. The guiding principal is that no code should ever extend
beyond column 90.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
We used to also include much more extensive documentation in source code, but with
the advent of XML Comments in .NET, we have used this innovation to move documentary
comments out into subsidiary &lt;em&gt;comment files&lt;/em&gt;. We realised early on that as
good as XML comments are, they do clutter the source code.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
We insist on heavy documentation at Revell Research Systems because we think this
increases the code&amp;#39;s value. The ability to provide comprehensive documentation
for any code library we have developed to either new team members or to contract developers
is invaluable. It helps them get up to speed quickly. It saves us money and improves
our profitability.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
We also insist that code is commented, where appropriate, to explain what is going
on. However, we believe that commenting should not be excessive. Indeed, good code
almost never needs commenting. The choice of good identifier names combined with clear
code design should obviate the need to explain what is going on. It should be abundantly
clear.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
Indeed, we review code to ensure that code is abundantly clear. If it is complicated
or convoluted, it gets re-written. If complicated code is ultimately proved to be
necessary, then we use comments to adequately explain what is going on. We would expect
supporting documentation (in XML comment files) to provide detailed explanations of
any algorithms being used, together with references to other sources.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
These standards (together with code layout standards and the use of proper naming
conventions such as those dictated by Microsoft&amp;#39;s &lt;a href="http://blogs.rrs.co.uk/revella/ct.ashx?id=404fc7bf-9ab7-4092-9d55-fe74e55e16fa&amp;amp;url=http%3a%2f%2fmsdn.microsoft.com%2flibrary%2fdefault.asp%3furl%3d%2flibrary%2fen-us%2fcpgenref%2fhtml%2fcpconnetframeworkdesignguidelines.asp"&gt; Design
Guidelines for Class Library Developers&lt;/a&gt;) are important but are often derided by
less commercially oriented developers. I suspect that they concentrate on getting
the code to work without reflecting on the importance of reuse by others, simply because
they often work alone.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
The key point is that commercially valuable code needs to be readily usable and understood
by programmers other than just the developer. The more readily understood the code
is then the more valuable that code must be. I believe that proper formatting, including
bannering, makes code more approachable and easier to share amongst teams. (Obviously,
the code also needs to be well-written!)
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
The problem is that this requires developers to subvert their egos. Developers tend
to believe that their code is particularly special. Their style is the best and it
provides a way of stamping their identity onto the code. Few home-hobbyists and small
developers are open to the prospect of others using their code.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
However, commercial code ideally will be reused by others, perhaps long after the
developer has left the organisation. An organisation&amp;#39;s corpus of code will be
much more &lt;em&gt;approachable &lt;/em&gt;if it is presented in a consistent way. It will also
help to facilitate much greater code re-use, which is one of the Holy Grails of software
engineering.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
I&amp;#39;ve insisted on these standards while teaching undergraduates over the past ten
years or more. Initially, there is huge resistance, particularly from students who
have already been developing code. However, eventually the message that coding standards
are extremely valuable does get through, particularly when they start working in teams.
&lt;/p&gt;
&lt;p dir="ltr" style="margin-right: 0px"&gt;
What I do know is that marking well-presented, &amp;quot;bannered&amp;quot; code is much easier.
It is much more approachable...!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blogs.rrs.co.uk/revella/aggbug.ashx?id=404fc7bf-9ab7-4092-9d55-fe74e55e16fa" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is produced by &lt;a href="http://www.rrs.co.uk"&gt;Revell Research Systems&lt;/a&gt;.</description>
      <comments>http://blogs.rrs.co.uk/revella/CommentView,guid,404fc7bf-9ab7-4092-9d55-fe74e55e16fa.aspx</comments>
      <category>Coding</category>
    </item>
  </channel>
</rss>