Friday, August 20, 2010

Option Explicit

The first two lines of your page should look like the following:
<%@ Language=VBScript %>
<% option explicit %>

Why use option explicit? It forces us to declare our variables before we use them. Think about VBScript for a second, it is untyped, not case sensitive and we can just start using a variable wherever we want if we don't declare option explicit. When we start developing REALLY advanced scripted pages we'll need all the help we can get in keeping your code organized. There is nothing worse than some undeclared variable floating around in global scope. Imagine a team of programmers working together on an asp page that has 12 different server side includes. Now, imagine everyone with a variable named 'i' or 'counter' in global scope. Things can quickly get out of hand on large projects. Enforce good coding standards on yourself and others within our team.

1 comment: