Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > ASP Coding Questions Discussion

Reply
Thread Tools

ASP Coding Questions Discussion

 
 
Lin Ma
Guest
Posts: n/a
 
      08-11-2003
Hi,

I am wondering if I am doing right. Please advise.

I create a system with 8 major steps and each step can go different
direction. General speaking, a lot of if statements and functions inside.

Each page is over 1000 lines. In order for me to debug, I separate the lines
by function and create a template page.

Then I use <--# include... --> to link to this template page.

Also some of the code are shared with other page link query, table..., I
also create a temp page for this and include into other pages.

The pro is that:

1. if update, I just update one temp page and all the page will be updated.
2. easy to debug because it will make the page shorter. The one with include
page has only 140 lines and without the include page is over 1500 lines.

The con may be:

1. too many include command to make the system slow??

My question is Am I Doing correct? Or there is a better solution?

Thanks,

Lin Ma




 
Reply With Quote
 
 
 
 
Aaron Bertrand - MVP
Guest
Posts: n/a
 
      08-11-2003
What kind of application needs 1000 lines per page?

That seems ludicrously overboard, IMHO.





> Each page is over 1000 lines. In order for me to debug, I separate the

lines
> by function and create a template page.



 
Reply With Quote
 
 
 
 
Lin Ma
Guest
Posts: n/a
 
      08-11-2003
Thanks for the response. I have tables, headers, queries, JavaScript, I also
have if statements... Some pages also send email to certain group...

The system is like a documentation approval system, different level people
will take different action, sign their option and move to next level person.
The next person can reject, accept, on hold... A lot of functions.

My point is that Can I divide my code into server area by function. Each of
the area creates a separate file. Then use Include command to assembly this
files together?

Thanks for the response.

Lin



"Aaron Bertrand - MVP" <(E-Mail Removed)> wrote in message
news:%23$(E-Mail Removed)...
> What kind of application needs 1000 lines per page?
>
> That seems ludicrously overboard, IMHO.
>
>
>
>
>
> > Each page is over 1000 lines. In order for me to debug, I separate the

> lines
> > by function and create a template page.

>
>



 
Reply With Quote
 
Martin CLAVREUIL
Guest
Posts: n/a
 
      08-11-2003
Off course you can do it but, always remember that a SSI (include statement)
is writen in the code is always included before any building of the code.
this mean that if you include a file in an if ... end if statement this file
will always be included.
This is a bit heavy for the server but can be really helpful for a debuging
purpose.
do not overuse it, that's all


 
Reply With Quote
 
Aaron Bertrand - MVP
Guest
Posts: n/a
 
      08-11-2003
> My point is that Can I divide my code into server area by function. Each
of
> the area creates a separate file. Then use Include command to assembly

this
> files together?


No, but you could use server.execute(). Includes are processed before ASP,
so any logic you use in ASP to determine which files to include will be too
late.


 
Reply With Quote
 
Lin Ma
Guest
Posts: n/a
 
      08-11-2003
Thanks.

Is there a better way to do to make page shorter?

Thanks a lot.

Lin

"Martin CLAVREUIL" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Off course you can do it but, always remember that a SSI (include

statement)
> is writen in the code is always included before any building of the code.
> this mean that if you include a file in an if ... end if statement this

file
> will always be included.
> This is a bit heavy for the server but can be really helpful for a

debuging
> purpose.
> do not overuse it, that's all
>
>



 
Reply With Quote
 
Jeff Cochran
Guest
Posts: n/a
 
      08-12-2003
On Mon, 11 Aug 2003 09:43:03 -0500, "Lin Ma" <(E-Mail Removed)> wrote:

>I create a system with 8 major steps and each step can go different
>direction. General speaking, a lot of if statements and functions inside.
>
>Each page is over 1000 lines. In order for me to debug, I separate the lines
>by function and create a template page.


Creating functions is smart if the same code is being executed
multiple times. If executed once, just put it there.

1,000 lines is big. Big enough that you're likely causing a slowdown
somewhere that you don't need to. Modularize the options and put them
in separate code pages.

>Then I use <--# include... --> to link to this template page.


In general, use includes to place the exact same block of code in
multiple pages. If it only runs once for the page it's on, don't use
an include.

But, you *might* use an include to separate code from HTML.

>Also some of the code are shared with other page link query, table..., I
>also create a temp page for this and include into other pages.


This is what includes are designed for, shared code or portions of
pages. I don't see the reason for a temp page, but that may be your
explanation or my ignorance that's confusing me.

>1. if update, I just update one temp page and all the page will be updated.


Welcome to the reason for includes.

>2. easy to debug because it will make the page shorter. The one with include
>page has only 140 lines and without the include page is over 1500 lines.


Bleh! Break it into multiple pages. Just beacuse you can put
everything on one page doesn't mean you should.

>The con may be:
>
>1. too many include command to make the system slow??


Maybe, probably not noticably considering the system is processing all
those lines.

>My question is Am I Doing correct? Or there is a better solution?


No matter how you do it, there's *always* a better solution.

I'd look at the programming logic. You mentioned eight major steps.
How many minor steps, and how many of those can be broken into
separate pages. Cheap example:

Big Pages:
===================
If User is Supervisor Then
Do code
Do more code
Do more code
End If

If User is Employee Then
Do code
Do more code
Do more code
End If
====================

Small Pages:
===================
If User is Supervisor Then
Goto Supervisor.asp
End If

If User is Employee Then
Goto Employee.asp
End If
====================

In the separate ASP pages, do the code for that IF statement. In this
pseudocode it saves four lines for the main page, and each individual
page is easier to debug.

Jeff
 
Reply With Quote
 
Guinness Mann
Guest
Posts: n/a
 
      08-12-2003
In article <(E-Mail Removed)>, http://www.velocityreviews.com/forums/(E-Mail Removed) says...
> My point is that Can I divide my code into server area by function.
> ... Then use Include command to assembly this files together?


Sure you can, Lin Ma. Here's an example for you:

-----<begin file capitalizeWord.asp>-------
<%
Function capitalizeWord(w)
dim s, t, u, l
l = Len(w)

if (l = 0) Then
capitalizeWord = ""
exit Function
End If

s = Left(w, 1)
t = Right(w, l - 1)
u = Ucase(s)

capitalizeWord = u & t

End Function
%>
-----<end file capitalizeWord.asp>-------

and in file tests.asp:

------<begin file tests.asp>------
<%@ Language=VBScript %>
<%Option Explicit%>

<!--#include virtual="bmlc_asp/includes/adovbs.inc"-->

<!--#include virtual="bmlc_asp/includes/capitalizeWord.asp"-->
<!--#include virtual="bmlc_asp/includes/ConnectionString.asp"-->

<!--#include virtual="bmlc_asp/includes/debugScreen.asp"-->
<!--#include virtual="bmlc_asp/includes/makeOption.asp"-->
<!--#include virtual="bmlc_asp/includes/queryDatabase.asp"-->

<!--#include virtual="bmlc_asp/TestCreation/TestClass.asp"-->
<!--#include virtual="bmlc_asp/TestCreation/TestQuestionClass.asp"-->

-------<end file .asp>-------

Notice that you have to do the inclusions outside of the asp markers.
Also, there is no built-in protection against redundant including of
symbols, (no #ifdef in C++ speak) so you will have to come up with some
kind of scheme to protect yourself against that.

-- Rick

 
Reply With Quote
 
Aaron Bertrand - MVP
Guest
Posts: n/a
 
      08-12-2003
> I'm a little confused. I'm somewhat new to this ASP stuff, but I've
> been developing software for over 20 years (way over, come to think of
> it), and to my mind 1000 lines is not a big program.


For a "real" application, no. For a web page, that's massive. I've been
developing ASP applications for, what, 7 or 8 years now? IIS 3 beta 2,
whenever that was made available. And I've never seen, much less written,
an ASP page with 1000 lines.

> Rather than have an unruly, unmanageable string of response.redirect-
> related pages like the system it replaces, it has a central ASP page
> that accepts the client-side input and generates the appropriate
> response pages on the fly.


And you think this is more efficient?

> So are you (Aaron, specifically) claiming that I should break that up
> into a dozen individual pages that use the WEB equivalent of "goto"
> (response.redirect) to switch between them?


When I build my sites, almost all of my content is stored in the database.
The information is not always retrieved directly from the database, e.g.
aspfaq.com uses a caching technology which only gets updated when the
articles actually change. The entire aspfaq.com site is about 120 lines of
code, and a good portion of that is style sheets / client-side javascript.

However I'm not claiming at all what you should or should not do. I think
if you have 1500-2000 lines of code, that's going to be a royal PITA to
manage, no matter how you decide to break it up (or not at all). I just
can't, for the life of me, imagine what you would need to do - for a set of
web pages - that would require that much code.

A


 
Reply With Quote
 
Jeff Cochran
Guest
Posts: n/a
 
      08-12-2003
>> >I create a system with 8 major steps and each step can go different
>> >direction. General speaking, a lot of if statements and functions inside.
>> >
>> >Each page is over 1000 lines. In order for me to debug, I separate the lines
>> >by function and create a template page.

>>
>> 1,000 lines is big. Big enough that you're likely causing a slowdown
>> somewhere that you don't need to. Modularize the options and put them
>> in separate code pages.

>
>I'm a little confused. I'm somewhat new to this ASP stuff, but I've
>been developing software for over 20 years (way over, come to think of
>it), and to my mind 1000 lines is not a big program. In fact, it's
>barely non-trivial.


VB apps routinely run many thousands of lines of code. But rarely
does the server need to process an entire VB application just to
display a logon screen. Plus, the nature of ASP and the web means you
don't need all the code for an application in one page.

>Is it a matter of terminology? When Lin Ma says "pages" maybe she
>doesn't mean what you guys mean when you say pages.


My take is a "page" means a single "file" processed and sent to the
browser.

>In one of the subsystems of my application I have a main "page" that has
>about 450 lines in it. About half of that is the main code (about half
>of which is comments) and the other half is utility subroutines. There
>is no display code in this file.


If Lin Ma has 1,000 lines and half are comments and another third are
blank, that's a different story. But in the ASP world, 1,000 lines of
code is pretty danged big.

>In this main "page" I include fourteen directly related ASP files and
>four data files. The ASP files collectively have about 700 lines in
>them. In addition I include another nineteen general purpose ASP files
>that do things like capitalize words, query the database, generate
>dynamic "<select>" controls, etc. That adds another 500 lines of code,
>or so.


That can also be dramtically squeezed from the sounds of it. Or at
least broken up.

>Rather than have an unruly, unmanageable string of response.redirect-
>related pages like the system it replaces, it has a central ASP page
>that accepts the client-side input and generates the appropriate
>response pages on the fly.


Unruly and unmanageable aren't the code's fault. But the solution is
rarely putting everything in one large file.

>I don't see how it could be done in less than, well, 1500 - 2000 lines
>of code.


I don't either. But I don't have the code...

>So are you (Aaron, specifically) claiming that I should break that up
>into a dozen individual pages that use the WEB equivalent of "goto"
>(response.redirect) to switch between them?


No. But discreet points where user input is needed probably should be
in discreet pages. You have 500 lines of code that query databases,
capitalize words, create dynamic SELECT controls, all of which could
possibly be better handled elsewhere. (Well, for one thing, ASP.NET
might help with some of your controls...) If you don't need to query
a database at the same time you capitalize words, don't put the
functions in the same page. In fact, handle capitalization on the
input side instead of the output, you capitalize once instead of every
time.

There's no real "method" to handle any of this. And what works in one
case most certainly won't work in all. For example, I have pages
which could easily be optimized, but they rarely get run and the
performance increae would be minimal so why bother? My efforts are
better spent elsewhere.

Jeff
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: ASP Classic > ASP.net discussion Bob Barrows ASP General 0 02-08-2012 12:33 AM
C++ Event Coding Questions AzizMandar C++ 4 11-09-2006 08:11 PM
general coding issues - coding style... calmar Python 11 02-21-2006 10:36 AM
MCSD Questions - A Discussion ampra MCSD 1 11-20-2004 06:01 AM
Re: Questions....questions....questions Patrick Michael A+ Certification 0 06-16-2004 04:53 PM



Advertisments