<?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>What did you learn today? - Code Reviews</title>
    <link>http://blog.philknows.net/</link>
    <description>Phil Denoncourt's Technology Rants</description>
    <language>en-us</language>
    <copyright>Phil Denoncourt III</copyright>
    <lastBuildDate>Wed, 21 Mar 2007 15:59:42 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>phil@denoncourtassociates.com</managingEditor>
    <webMaster>phil@denoncourtassociates.com</webMaster>
    <item>
      <trackback:ping>http://blog.philknows.net/Trackback.aspx?guid=49db5acf-a7d6-4c64-8727-50213033e338</trackback:ping>
      <pingback:server>http://blog.philknows.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.philknows.net/PermaLink,guid,49db5acf-a7d6-4c64-8727-50213033e338.aspx</pingback:target>
      <dc:creator>Phil Denoncourt</dc:creator>
      <wfw:comment>http://blog.philknows.net/CommentView,guid,49db5acf-a7d6-4c64-8727-50213033e338.aspx</wfw:comment>
      <wfw:commentRss>http://blog.philknows.net/SyndicationService.asmx/GetEntryCommentsRss?guid=49db5acf-a7d6-4c64-8727-50213033e338</wfw:commentRss>
      <title>Reviewing Databases</title>
      <guid isPermaLink="false">http://blog.philknows.net/PermaLink,guid,49db5acf-a7d6-4c64-8727-50213033e338.aspx</guid>
      <link>http://blog.philknows.net/PermaLink,guid,49db5acf-a7d6-4c64-8727-50213033e338.aspx</link>
      <pubDate>Wed, 21 Mar 2007 15:59:42 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;There is plenty of guidance on reviewing code.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;(Look
at CodeFrisk.Com/Guidance.aspx for some links).&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;I’ve
found that &lt;u&gt;the&lt;/u&gt; one absolutely most critical piece of a traditional application
never undergoes any type of review.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Most
applications live and die by their database, and yet it rarely gets reviewed.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If
you’re lucky (although you might not think so), you’ll have a DBA check things over,
but they are mostly concerned with performance.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Maintainability
and adherence to standards are not at the top of their list.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;I’ve listed some of the things I look at when I review a database:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;-Appropriate Normalization&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;It’s tough to say what is and isn’t appropriate normalization.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You’ll
know it when you see it.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;Stuff
like having a separate table for the 
&lt;st1:country-region w:st="on"&gt;
&lt;st1:place w:st="on"&gt;US&lt;/st1:place&gt;
&lt;/st1:country-region&gt;
states or one called Gender is usually a red flag of having gone too far.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Conversely,
having the same field in multiple tables is usually a sign that normalization hasn’t
gone far enough.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;--Is all access through stored procedures&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;Most development shops have a policy that says, “All data access
shall be done through stored procedures”.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If
you have that policy, check to make sure this is being adhered to.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;An
easy way to check this is to deny access to the tables and allow access to the stored
procedures.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;--Look for premature optimization&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;I’ve seen times when developers are using Join hints or locking
hints in their query.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;“If I force the
query to use a merge join, it goes 5x faster”.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Meaning
it goes 5 times faster on the development box which has far fewer rows and 3 fewer
processors than the production machine.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Once
it goes the to production machine, there’s a good chance that SQL will decide upon
a different plan to execute the statement, making the hint destructive on the production
machine&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;--Are objects secured and scripted&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;Eventually, when you roll the database into a production environment,
access to the database will (or should) be locked down.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Is
the development environment the same?&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Are
the scripts that you have under source control (you do have the database creation
scripts under source control don’t you?)&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;include
securing of the object.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;--Are updates applied in the same order&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;I can think of no better way to create an application that suffers
from chronic &lt;/font&gt;&lt;a href="http://www.sql-server-performance.com/deadlocks.asp"&gt;&lt;font color=#800080&gt;deadlock&lt;/font&gt;&lt;/a&gt;&lt;font color=#000000&gt; situations
than to have one stored procedure update tables A, B, &amp;amp; C (in that order) and
have another stored procedure update tables C, B, &amp;amp; A (in that order).&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Updates
should always be applied in the same order.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Otherwise,
you’re increasing the chance that a row in A will be locked by one stored proc while
waiting for a row in table C locked by the other stored proc.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Generally
the order is enforced naturally because you have to respect foreign keys, but every
now and then I come across this.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;--Biblical stored procedures&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;By biblical, I mean volume, not divinely inspired.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I’m
referring to stored procedures that use up more than one printer cartridge if you
were to print it.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Nowadays when you see
a large stored procedure, it’s one of two things:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;1) Embedded business logic – This seems to be a remnant of client
server programming where you were forced to put your business logic in the stored
procedure.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;It’s arguable about whether
or the database is the best place to keep your business logic.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Most
people (including me) believe it’s not.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Business
logic should be kept in a business logic component that validates, enforces and calculates.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;2) Poorly defined schema.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Most
validations that you see taking place in stored procs could be controlled by using
schema constructs like check constraints, triggers, foreign keys and defaults.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Put
that type of information in the schema where it can be enforced consistently everywhere
rather than burdening the stored procedure.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;--Does the Development database match what’s in source control&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;To reinforce this, database schema objects need to be kept under
source control.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Having a database backup
plan isn’t sufficient.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Putting the objects
in source control allow you to manage changes and releases much more effectively.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Otherwise
you’ll be struggling to determine which objects have changed in the development database
and need to be deployed, and figuring out who added a field to table.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Keeping
the schema under source control used to be a very manual process, but now tools like &lt;/font&gt;&lt;a href="http://msdn2.microsoft.com/en-us/teamsystem/aa718764.aspx"&gt;&lt;font color=#800080&gt;Visual
Studio for Database Professionals&lt;/font&gt;&lt;/a&gt;&lt;font color=#000000&gt; make this painless.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;--Cloned stored procedures / Views.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;This is very common.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;When
you need data, most developers don’t look to see if there is an existing stored procedure
or view that satisfies their needs.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;They’ll
create a brand new one.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Then you end
up with a database that has 3 different stored procedures that get a customer record
by its ID.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Now all these duplicated procs
have to be maintained.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Best prevention
for this is to have a strict naming convention for your procedures.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;Those are some of the quick patterns I look for when reviewing
a database.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;What are the kind of things
that stand out when you look over a database?&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;Wouldn’t you feel comfortable
having your code reviewed by an expert?&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Go
to &lt;/font&gt;&lt;a href="http://www.codefrisk.com/"&gt;&lt;font color=#800080&gt;CodeFrisk.com&lt;/font&gt;&lt;/a&gt;&lt;font color=#000000&gt; to
see how I can proofread your code at a reasonable price.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.philknows.net/aggbug.ashx?id=49db5acf-a7d6-4c64-8727-50213033e338" /&gt;</description>
      <comments>http://blog.philknows.net/CommentView,guid,49db5acf-a7d6-4c64-8727-50213033e338.aspx</comments>
      <category>Development</category>
      <category>SQL</category>
      <category>Code Reviews</category>
    </item>
    <item>
      <trackback:ping>http://blog.philknows.net/Trackback.aspx?guid=4d2b767e-9169-451b-8a23-b7de47092027</trackback:ping>
      <pingback:server>http://blog.philknows.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.philknows.net/PermaLink,guid,4d2b767e-9169-451b-8a23-b7de47092027.aspx</pingback:target>
      <dc:creator>Phil Denoncourt</dc:creator>
      <wfw:comment>http://blog.philknows.net/CommentView,guid,4d2b767e-9169-451b-8a23-b7de47092027.aspx</wfw:comment>
      <wfw:commentRss>http://blog.philknows.net/SyndicationService.asmx/GetEntryCommentsRss?guid=4d2b767e-9169-451b-8a23-b7de47092027</wfw:commentRss>
      <title>Code Reviews</title>
      <guid isPermaLink="false">http://blog.philknows.net/PermaLink,guid,4d2b767e-9169-451b-8a23-b7de47092027.aspx</guid>
      <link>http://blog.philknows.net/PermaLink,guid,4d2b767e-9169-451b-8a23-b7de47092027.aspx</link>
      <pubDate>Sun, 18 Mar 2007 11:18:14 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;As a developer, I love to write code.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Getting
involved with a problem, putting my head down, coming up a solution and getting immersed
in implementing it is an awesome feeling.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;I also enjoy reading code.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I
like to look at a set of code and try to understand what the developer was thinking.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You
can tell a lot about how a person thinks by reading their code.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;To
me, participating in code reviews is a lot of fun.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;I originally wrote these articles 6 months ago when I was about
to launch a new service to review code (For details, go to &lt;/font&gt;&lt;a href="http://www.codefrisk.com/"&gt;http://www.codefrisk.com/&lt;/a&gt;&lt;font color=#000000&gt;).&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I’m
now much too busy to review code, but these articles might be of value, so I’m uploading
them now.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;I’ll be posting a set of articles
about code reviews, best practices, coding standards…&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Here’s
the first article in the series:&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;Coding Standards – How to write a useful Coding Standard document&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;Coding standards are an agreement in a development team on how
the code for an application will be structured.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;They
promote consistency and easier maintenance.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;A
well-written and enforced standards policy will reduce the time that it takes for
new developers to feel comfortable with an application.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;I’ve worked with many organizations over the years, most of which
have some sort of coding standards documentation.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The
needs of each organization are very different.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Some
organizations sold their source code, so they needed to make sure there was a very
high level of consistency.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Others were
in regulated industries and needed to conform to various practices.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/span&gt;Others
were small shops that didn’t see tremendous value in having standards.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;The standards document had varying degrees of success.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Some
negative factors in coding standards I’ve seen are:&lt;/font&gt;
&lt;/p&gt;
&lt;ul style="MARGIN-TOP: 0in" type=disc&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Aggressively guarded by one person&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Enforcing rules that were necessary in older technologies, but
no longer hold relevance (Especially if they were burned by the problem)&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Too slim&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Too thick&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Too strict&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Begun, but never completed.&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l0 level1 lfo1; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Finished, but never enforced.&lt;/font&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;I’ve written a few coding standards docs and want to share what
I’ve found useful, and what you should try to avoid.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;First of all, if you’re the person tasked with writing the documentation,
make sure that you involve the rest of the development team as much as possible.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You
shouldn’t take the Moses approach; climb a mountain and come down with a set of commandments.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If
the developers on your team aren’t consulted on the coding standards, you’ll see a
lot of them not adhering to them.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;These
aren’t &lt;u&gt;your&lt;/u&gt; coding standards; they are the &lt;u&gt;teams&lt;/u&gt; coding standards.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;Recognize that you aren’t writing a document with a stone and
chisel.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Coding standards must evolve
as your team has learned new techniques.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;It’s
also not uncommon to see coding standard docs that never get finished because the
author feels the document must be 100% “complete” before they release it.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Take
an iterative approach and get the document out as soon as possible and continue to
refine it.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;It’s impossible to get it
all right the first, second, or even tenth time.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;You’ll
probably find that most code reviews will result in changes to the standards document.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;Kick off a discussion for an hour or two and brainstorm with the
development team about possible standards.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;There
will be contention.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If the team can’t
come to an agreement after 5 minutes, table the discussion point for later.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If
people have time to think about something, they will usually be able to justify or
back off on their opinion.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;The
important thing is to limit the time of the discussion in the interests of getting
an initial version within the same day.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Good
developers will talk about coding all day.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;Areas to discuss would include:&lt;/font&gt;
&lt;/p&gt;
&lt;ul style="MARGIN-TOP: 0in" type=disc&gt;
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Naming standards – Camel, Pascal, Hungarian, Dewey Decimal System?&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Documentation expectations – XML Documentation, when/where to
put comments, class headers…&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Design Patterns that are expected to be used – Factories, Observers,
Decorators…&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Automated Unit Testing strategy – TDD? Tool type, Code Coverage…&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Exception handling – Handling, Reporting…&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Use of constants/resource files – Yes, No?&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;One
resource for the entire project, one constant class?&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Complexity limits for methods - &amp;gt; 25 is a lot of branches&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Data access methods - Stored Procs, Dynamic SQL, DataSets, ORM,
Async, Transaction strategy…&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Common components to use – Enterprise Library, Log4net, Infragistics…&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Localization strategy -&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Needed?&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Roll
your own or use .NET framework...&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Versioning – Versioning assemblies, strong name, signing, delay
signing…&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
&lt;font color=#000000&gt;Build strategy – Nightly builds, one solution or many solutions,
creating references&lt;/font&gt; 
&lt;li class=MsoNormal style="MARGIN: 0in 0in 0pt; COLOR: red; mso-list: l1 level1 lfo2; tab-stops: list .5in"&gt;
!Code Formatting&lt;o:p&gt;&lt;/o:p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;For the most part try to stay away from talking about code formatting.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Formatting
standards inevitably come down to one developer’s preference over another.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Capable
developers will be able to read the code regardless of how it is formatted.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;After you’ve had your discussion with the team, hole yourself
up in your office/cube and write up the standards doc.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Unless
you’re a dreadfully slow typist, this shouldn’t take more than 1 – 3 hours.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;The important thing is to make sure you get feedback from your
team on the document.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;If they don’t feel
involved and disagree with a particular piece, they will exhibit a little bit of passive-aggressive
behavior and not adhere to the standard.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;The Coding Standards document sets up expectations at code reviews.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;It
is a declaration of what is expected from a developer when they submit code.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Without
some set of coding standards, code reviews can quickly become counterproductive.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font color=#000000&gt;Coding standard docs aren’t hard, aren’t intrusive, and are a
valuable resource.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;When there is a set
of guidelines to use when coding, it is much easier to bring new developers into the
project.&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;The benefits justify the one
day of effort it takes to put one in place.&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;o:p&gt;
&lt;font color=#000000&gt;&amp;nbsp;&lt;/font&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;i style="mso-bidi-font-style: normal"&gt;&lt;font color=#000000&gt;Wouldn’t you feel comfortable
having your code reviewed by an expert?&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/span&gt;Go
to &lt;a href="http://www.codefrisk.com"&gt;CodeFrisk.com &lt;/a&gt;to see how I can proofread
your code at a reasonable price.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/i&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.philknows.net/aggbug.ashx?id=4d2b767e-9169-451b-8a23-b7de47092027" /&gt;</description>
      <comments>http://blog.philknows.net/CommentView,guid,4d2b767e-9169-451b-8a23-b7de47092027.aspx</comments>
      <category>Code Reviews</category>
      <category>Development</category>
    </item>
  </channel>
</rss>