Page

9.3.1- Indent Your Code

  by NT Community Manager.
Last Updated  by NT Community Manager.  

PublicCategorized as 09. Error Handling.

Not tagged.
<< 9.3.0- Good Coding PracticeChapter99.3.2- Comment Your Code >>

Indent Your Code

While not necessary to ensure that your code works correctly, you can make your life so mucheasier by formatting and indenting your code as you write it. So for each loopstructure or conditional structure, common convention is to indent the codewith a tab or several spaces. So an example snippet of code might look likethis:

 

If strText = "right" Then

  strNum = 7

  If strText2 = "right" Then

    StrNum2 = 8

  Else

    StrNum2 = 0

  End If

End If

 

In this case it makes it easier to see towhich bit of code each End If refers. If an End If hadbeen omitted, it would be much easier to spot with the code indented in thismanner. When debugging, you would only need to glance at the code to spot, forexample, code at the end of the structure that was still indented by severalcharacters. You would know immediately that something had been left out.

Of course the flip side to this is that theexcessive indentation can make your code more difficult to read. One line mightstart outside of your viewing area to the left and another line might finishoutside it to the right. In other words, you can't read the ASP script all atonce and find yourself constantly scrolling back and forth. To counteract thisyou always reduce the amount you indent code, to two or three characters perindent.

<< 9.3.0- Good Coding PracticeChapter99.3.2- Comment Your Code >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |