coding faster - easier maintenance

Hey Web Gods,

How do I code faster and make my code easier to maintain?  I need your tips and
ideas.  I've been building dynamic websites for awhile now.  But as they get more
complex, I find I'm spending too much time on maintenance.  I have to do more with

Currently, I use html kit to develop my asp/access or sql websites.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

If you are still using table based layouts, stop.  Use semantic code and CSS for presentation.  

Completely separate HTML, CSS, JavaScript and Server Side code.

Learn how to create simple reusable objects in JavaScript and ServerSide code.

Don't cut and paste examples from code libraries into your code unless you truly understand the code and have verified it has proper error handling and security.

Don't start a web design until you have a model of the site and its functions.

Believe it or not the following page is very complex in functionality, but as you can see all the page parts are separated into reusable and easy to maintain parts.  This is a login page which has subscription, e-mail a friend, add to bookmarks, registration, member account management, advertisments, etc. etc.  

If the owner want's a style change, I only have to work on the css files.
If there is a bug in the authentication routine, ot the database changes, I only have to look at the asp page.
It the privacy policy changes, I make a change in one places and several hundred pages all reflect the change.
Almost every page in the entire site has the same structure.

<% Option Explicit %>
<!--#include file="content/page_2.asp"-->

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="expires" content="now-1">
<meta http-equiv="pragma" content="no-cache">
<meta name="author" content="Roderick Divilbiss">
<meta name="copyright" content="© 2005 Roderick Divilbiss">
<meta name="description" content="snip....">
<meta name="keywords" content="snip...">
<meta name=robots content="index,follow">
<link rel="shortcut icon" href="../../favicon2.ico" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="../../include/css/all.css">
<link rel="stylesheet" type="text/css" href="../../include/css/code.css">
<script language="javascript" type="text/javascript" src="content/page_2.js"></script>

<div id="topmenu"><!--#include virtual="common/authentication_topmenu.htm"--></div>
<div id="banner"><!--#include virtual="include/banner.htm"--></div>
<div id="mainmenu"><!--#include virtual="common/authentication_mainmenu.htm"--></div>
<div id="middle">
  <div id="content"><!--#include virtual="content/page_2.htm"--></div>
  <div id="nav"><!--#include virtual="common/authentication_leftnav.htm"--></div>
  <div id="right"><!--#include virtual="common/authentication_right.htm"--></div>
  <div id="bottomMenu"><!--#include virtual="include/bottommenu.htm"--></div>
  <div id="copyright"><!--#include virtual="include/copyright.htm"--></div>

On your server side code, you should also use good documentations and code libraries:

<% option explicit %>
Dim page_version
page_version = "0.01 delta 02-07-2005 08:30 AM"
'  PURPOSE            :  
'  ON ENTRY            :
'  ON EXIT              :
'  ASSUMPTIONS          :
'  ERROR CHECK           :
'  CALLED BY              :
'  AUTHOR            : Rod Divilbiss
'  LAST MOD             : 03-24-2004
'  BY                       : RD
'  CHANGES              : most recent first
'                          02-24-2004 RD original ASP
' STATUS                 : Development

'* This const declaration must proceed thisPageClass.asp
' const secureCertificateServerName = "" ' N/A

<!--#include virtual="include/thisPageClass.asp" -->
'* On form pages or pages which should expire add the
'* following to the header of the page.
response.addheader "Cache-Control", "no-store"
response.addheader "Cache-Control", "no-cache"
response.addheader "Cache-Control", "private"
response.addheader "Cache-Control", "max-age=0, must-revalidate"
response.addheader "Expires", Now-1
response.addHeader "Pragma", "no-cache"

'* Now we can call our server side includes
'* Best to put in aplha order unless there are dependencies
'* that require another order
<!--#include virtual="include/arrayClass.asp"-->  <!-- encapsulates returning arrays from databases, with debug & error checking --?
<!--#include virtual="auth/authorizeClass.asp"-->  <!-- NT authorization routines -->
<!--#include virtual="include/debugClass.asp"-->   <!-- debug class, simulates a VB debug.print -->
<!--#include virtual="include/errorObject.asp"-->   <!-- custom error handling -->
<!--#include virtual="include/generalPurpose.asp"-->   <!-- often needed routines -->
<!--#include virtual="auth/getrecordsetClass.asp"-->    <!-- ADO RS routines with error checking and debug -->
<!--#include virtual="include/inputClass.asp"-->           <!-- for building dynamic HTML form fields -->
<!--#include virtual="include/tableClass.asp"-->            <!-- for building dynamic HTML tables -->

'* Best to put in aplha order unless there are dependencies
'* that require another order.  Also, one Dim per line
'* allows useful comments to the right of the declarations.

Dim debug            ' The debug object
Dim production             ' Is this page in production?  Controls messages returned to the browser on errors, etc.

'* Best to put in aplha order unless there are dependencies
'* that require another order.
'* The debug object would naturally be first.
'* Error checking to insure objects are created properly
'* and that all classes were included should occur.

production = false

on error resume next
Set debug = new clsDebug
debug.enabled = true

if err then
      '* Notify developer if not production
      if NOT production then
            response.write "ERROR: Unable to initialize the debug object. Check for SSI:<br>" & vbLF
            response.write server.HTMLencode("<!--#include virtual="&chr(34)&"include/debugClass.asp"&chr(34)&"-->") & "<br>" & vbLF
            response.write "DETAILS: " & err.number & " " & err.description & " " & err.source
      end if
      debug.enabled = true
      ' debug.notify = ""
      debug.subject = "Purchase Order Debug Information"
end if
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

I personally keep each page very very minimal and let all the include functions do the work.

This is madeup, but to give an idea...

   <!--#include virtual="include/subroutines.asp"-->
   output-displaybox("my heading","html text")

denamAuthor Commented:
How about tools?  I'd love to have Dreamweaver MX but right now can't afford it.  Do any of you use
freeware or other tools to handle, for example, writing css?
There are many freeware development programs.

I generally work strictly in the code, so anything with color coded markup and intelligent completion for the languages I use is a boon.  I work against a local web server and can open pages in a real browser if I need to look at the layout.  WYSIWYG editors will force choices you may not want, and often suffer from outdated code constructs.

FrontPage, DreamWeaver, ColdFusion, are just ways to hide what's going on, bloat your code, and make maintenance more difficult.

FirstPage 2000

are pretty popular.  PSPad probably has the bigger market share.

I've never found anything I like for CSS other than the text editor, it's self.
TopStyle Lite for CSS is a good one...
Can't be better than Notepad, LOL
SUUUURRREE.....ya....cause Notepad is GREAT..... lol
denamAuthor Commented:
Great info you all.  

Separating HTML, CSS, JavaScript and Server Side code makes total sense.

One thing I spend a lot of time doing is writing out dim statements and asp code.  I've got some
sites (they always want them yesterday and then tommorrow they want them tweaked a little)
that have tons of variables input by forms, and then processed in some way.

Several are on access.  So I end up writing page after page of queries and vbscript and asp.
My understanding is that something like dreamweaver writes this for you.  I've certainly resisted.
I hate FrontPage ;o)  But I've seen developers produce this stuff quicker using DW.

I hope I'm not dragging this on.  I know it's only 50 points.  But I figure it's a chance to get a good discussion
 on this.  I'm sure there are others out there who'll benefit.

DreamWeaver, FrontPage and ColdFusion will all "write" code for you but it will be bloated, hard to maintain, goop.

Put your database access code in an include file and use it over and over.  When it is right it is right.  If it is wrong, you only have one file to fix, rather than multiple pages.

If you are dimensioning lots of variables to match what the form posted, you can probably eliminate that effort except for form fields that you actually need have to perform calculations or manipulations.  If you are only submitting it to the database, you can substitue a finction that retrieves the field, cleanses it for XSS scripting and SQL injection and puts it directly into you database command, rather than putting it in a local variable and putting that variable's value into the database connection.

I'll post an example later as I'm not feeling well, (no I have not been celebrating St. Patrick's day - but if I feeel better I might).

Let's suppose you have posted a form to this page.

While I don't recommend building dynamic SQL from user input, this is an example and can easily be used for paramaterized SQL or stored procedures.

GOAL:  Not having to dimension local variables for posted form fields.

Remember, the form fields already exist in a collection accessible by the page, so there is really little point in putting thos in local variables, unless you need to change its value or perform repeated operations.

function getField(fieldName)
   Dim tmp
   tmp = ''
   if request.form(fieldName) & "x" <> "x" then
      tmp = request.form(fieldName)
      ' now you can perform various routines to clean tmp
      ' for hostile input and to deal with quotes in the input
      ' and encrypt it so if a hacker steals your database the hacker has to brute force the data
      getField = tmp
   end if
end function

Dim commandText

commandText = "INSERT INTO TABLE (field1, field2, field3, ... fieldn) VALUES " &_
                         "VALUES (getField(field1), getField(field2), getField(field3)  .... getField(fieldn));"

Similarly, if you are going to put the posted fields back into other form fields or display them in the client browser,

<input type="text" name="field1" value="<%=Server.HTMLEncode(getField(field1))%>">

or Response.write Server.HTMLEncode(getField(field1))

No local variables, and you are protecting yourself from evil user input.

You can take this a step further and make one getField function for all your pages which you would include as discussed above, so if you discover a flaw in your code, you only have one place to fix it.

My version of this is actually an object, so in my code I can do this....

Dim fh
Set fh as new fieldHandlerClass

fh.field = "field1"   <--- that invokes the function to get the posted form field and filter it.

When I need to output the value

fh.toDB  <--- gives me a value safe to put in the database
fh.toHash <---- gives me a HASH (for passwords)
fh.toCrypt <---- gives my the field encrypted
fh.toHTML <--- gives me the field safe to use in HTML output.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Thank You!!!

I'm glad I could help.
denamAuthor Commented:
You're welcome.  It is good advice.  I'm trying to turn anything I do multiple times into a function or subroutine.
Much easier to deal with.
denamAuthor Commented:
This is the best developer advice I've ever gotten.  It's taken some time to fully appreciate just how good.  I'm wondering if you can recommend any websites, books or articles that go into more depth on this topic.  For example, ways to separate html, css and server side code (form from content from function?).  When I asked the question I was using asp.  Since then, I've started learning  I am told this is easier to do in .net.  But haven't gotten far enough to know first hand.

And thanks again for the yoda-like advice.
WOW! I wish I could force a few people to subscribe to this question, LOL. Thank you very much.

I can really recommend any books on web design, not because they don't exist, just because I've been doing this so long I've absorbed the information incrementally from other sources.  However, closely related and highly recommended is Writing Secure Code 2 by Microsoft Press and I have pre-ordered The 19 Deadly Sins of Software Security.  Designing with security in mind not only makes you a better developer but also reinforces the importance of keeping code, markup and style separate.

There are a number of experts here that are worth searching their answer history (click their username, and read their question history.) A very good leaning experience.

COBOLdinosaur is the guru of HTML and standards compliant development.  seanpowell,      Batalf, mplungjan,  fritz_the_blank, and  GrandSchtroumpf are some good ones to read.  Check their profiles for personal web sites.

Some recent favorite web sites relating to design (and follow their links to other sites) are:  <-- three really good articles on CSS layout (LOL)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.