<?xml version="1.0"?>
<xml>
      <title>Coding Standards: The Ugly Duckling of Web Development</title>
<keywords/>
<description/>
      <meta content="text/xml;" http-equiv="Content-Type"/>
<main-content>
   <system-data-structure><datetime>1166218200000</datetime><author><content><system-data-structure><name>Brett Goodwin</name><position>Systems Analyst</position><ext>113</ext><email>brett.goodwin@hannonhill.com</email><cell>703-258-5471</cell><im>Yahoo - BMGinATL</im><birthday>455169600000</birthday><picture><content/><path>/intranet/files/pictures/small/brett.jpg</path><name>brett.jpg</name><display-name>spacer.gif</display-name><title>brett</title></picture><favorites><restaurant>Dante's Down the Hatch</restaurant><restaurant>Cafe Intermezzo</restaurant><movie>I Heart Huckabees</movie><candy>Melty Mints (those pastel colored Hershey kiss shaped things with little white balls stuck to the bottom)</candy><vacation-spot>Cancun</vacation-spot><vacation-spot>Amsterdam</vacation-spot></favorites><bio><p>As a Services Integrator Brett is responsible for bringing existing websites and designs into your Content Management System.&#160; Presented with some wireframes or several pages of markup, Brett will create a fully functional templatized site complete with automated navigation.&#160; This involves converting any markup supplied into a barebones template divided into practical content regions, then creating XSL stylesheets to render this content as supplied by appropriately selected index blocks.&#160; He is also involved in delivery and maintenance of these sites, and is happy to help you set up your web server and the appropriate publish transports to make sure everything goes where it&#39;s supposed to and doesn&#39;t get lost in the world wide web.<br/>
<br/>
Aside from his primary duties integrating web pages into Cascade-compatible sites, Brett has extensive experience using server-side scripting languages including PHP, ASP, and Javascript.&#160; These skills allow him to create custom web applications when requested by clients, using Cascade Server&#39;s web services layer to automate tasks within the CMS.&#160; He has been responsible for writing the majority of the calendar applications that we have created for our clients, and developed a fully-featured mapping system.<br/>
<br/>
Brett attended Thomas Jefferson High School for Science and Technology in Alexandria, Virginia which is renowned nationwide for its advanced course offerings and high caliber students.&#160; He studied Systems Engineering for two years at the University of Virginia before moving to Atlanta, where he is presently working on a degree in Computer Information Systems from Georgia State University&#39;s Robinson College of Business.&#160; Brett has developed web applications fordefense contractors in Washington DC, and briefly contributed to an artificial intelligence project at the University of Virginia before signing on with Hannon Hill.&#160; He has also worked as a receptionist, a shipper/receiver at a computer warehouse, a bus driver, and a Starbucks Barista.</p></bio></system-data-structure></content><path>/intranet/company/team-members/brett-goodwin</path><name>brett-goodwin</name><display-name>Brett Goodwin</display-name><title>Systems Analyst</title></author><body-content>A few weeks ago a document came across my desk, which at first glance caused me to grimace with distaste. It was a department-wide memo to our Professional Services team reminding us of Best Practices procedures for writing XSLT code. Anyone who has experience with programming has inevitably had that one professor or supervisor who insisted that you comment every single line of code and organize your code sections as though he were going to print out the finished source, frame it, and stick it on the wall. Most people know on some level what they are supposed to do to maintain their code&#8217;s readability, but very often it gets ignored. In fact among some programmers there is a kind of perverse pride in being able to write functions so complex and obscure that no one could ever decipher them. And sometimes this is seen as a kind of job security, if your employer is dependent on you to maintain the rat&#8217;s nest, which supports the entire corporate infrastructure.<br/>
<br/>
 
<p>Nevertheless, on further reflection I decided that it might not be a bad idea to make an effort to keep my code in line with our established best practices. It is, after all, a show of courtesy towards my coworkers, and would help cut back on the number of people coming by my desk to ask me about things I had written. And as much as we like to think that we have the capacity to interpret everything we&#8217;ve written at a later date, sometimes reviewing things that I&#8217;ve coded as little as two weeks ago can require 15 minutes spent refreshing my memory.</p>
<p>That being said, I&#8217;d like to go over some best practices that we&#8217;ve been putting to use here at Hannon Hill in the development of our XSLT stylesheets. Ignore them at the risk of your own frustration.</p>
<p class="ListParagraph"><br/>
</p>
<ul>
<li>First, and most obvious, <em>indent</em> (and do it with tabs, not spaces).&#160; The standard practice is to add one tab of indent for each enclosing tag.&#160; For example:<br/>
<br/>
<em><span class="code">&#60;xsl:stylesheet&#62;<br/>
&#160;&#160;&#160;&#160;&#160; &#60;xsl:template match=&quot;/system-index-block&quot;&#62;<br/>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;h1&#62;xsl:value-of select=&quot;heading&quot;/&#62;&#60;/h1&#62;<br/>
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#60;p&#62;&#60;xsl:value-of select=&quot;paragraph&quot;/&#62;&#60;/h1&#62;<br/>
&#160;&#160;&#160;&#160;&#160; &#60;/xsl:template&#62;</span></em>&#160; &#160;&#160;<br/>
<br/>
</li>
</ul>
<ul>
<li>Comment your code liberally. If you feel like you&#8217;re putting in too many comments, it&#8217;s probably just enough. Specifically, be sure to give explanations of the purpose of any variables you use, and the function of each template.<br/>
<br/>
</li>
<li>Try to keep your XPath statements simple. These are the statements that appear with <em>select=&#8221;&#8230;&#8221;</em> sections. When these statements get too long they can be very hard to decipher, so it&#8217;s best to simplify as much as possible.<br/>
<br/>
</li>
</ul>
These are just a few of the most significant rules, but there are many other things you can do to improve your code&#8217;s readability. You will develop your own style as you become more proficient in XSL, but hopefully it will be one that won&#8217;t cause future generations of developers any grief. Just remember the golden rule: &#8220;submit code unto others as you would have them submit code unto you.&#8221;</body-content><graphic><path>/</path></graphic><podcast><content/><path>/internet/files/podcasts/2006/18_coding_standards.mp3</path><name>18_coding_standards.mp3</name><display-name>Coding Standards: The Ugly Duckling of Web Development</display-name><title>Coding Standards: The Ugly Duckling of Web Development</title><keywords>hannon hill, content management, coding standards, xml, xslt, programming</keywords><author>Brett Goodwin</author></podcast><related-page><path>/</path></related-page><category>Commentary</category></system-data-structure>
</main-content>
<copyright>
    
</copyright>
</xml>