devxlogo

Encapsulate Your Code

Encapsulate Your Code

One of the most common mistakes developers can make is to extensively use global variables. While they are sometimes necessary, global variables can cause problems in code that are both difficult to find and costly to fix. One way of preventing the use of global variables is by encapsulating all of your code in subroutines.

As in the code fragment below, ASP pages can be organized into a set of functions, all called from a Main subroutine declared at the top of the page. Using this coding standard can prevent debugging later.

 <%@ LANGUAGE="VBSCRIPT" %> <% Main '----------------'Function: Main 'Purpose: Entry point for the page.'
---------- Sub Main %><% DisplayPage() %> <% End Sub %>
See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist