February 2004 - Posts

Curly Brackets
25 February 04 09:19 PM | alexcampbell | 16 comment(s)

My co-programmers and I have been talking about coding standards within our organisation (the conversations tend to be very civilised as there are only three of us!)   The most contentious point has been whether curly brackets for procedures and if/for/foreach/do statements should begin on the same line as the statement or on the line below.

i.e. is this:

public class myPage : System.Web.UI.Page
{
     protected void Page_Load(object Sender, EventArgs e)
     {
          if(Request.QueryString[“category“] != null)
         {
               Response.Write(Request.QueryString[“category“]);
         }
     }
}

better than this:

public class myPage : System.Web.UI.Page
{
     protected void Page_Load(object Sender, EventArgs e) {
          if(Request.QueryString[“category“] != null) {
               Response.Write(Request.QueryString[“category“]);
         }
     }
}

I am inclined to think the former is better because you can immediately tell whether every curly bracket has been closed.  The consensus here, however, is that the latter is better because you can immediately tell whether something is a class or an if statement.  I'm interested in different justifications for different coding standards so anyone has any ideas please post them to the comments section of this post.

Source Code Commenting Technique
20 February 04 02:21 PM | alexcampbell | 3 comment(s)

This article has cast a new light on how fun commenting source code can be... everyone just has to remember to be really careful not to leave <compilation debug=“true” /> on any live sites.  Imagine this scenario:

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1585: Request too stupid.

Source Error:

Line 35:   /// Implements client's fucking stupid idea of having giant purpledots all
Line 36: /// all over the fucking page Line 37: /// </summary> Line 38: public void WriteBigPurplePokaDots(int DotSize, string ) Line 39: { Line 40: PurplePokaDotWriter myDotWriter = new PurplePokaDotWriter();

In the meantime, I'm not sure why MSFT is so worried about people downloading files like “windows_2000_source_code.zip” from Kazaa.  Everyone knows that the content of files on Kazaa has no correlation to the titles and descriptions of those files.  Potential MS source-code readers are more likely to waste 200mb of their download allowance and then discover that they have downloaded a renamed archive of really wierd stuff.  Which serves them right.

More Posts