Favorite Scripting shortcuts

S

Scott McNair

What's your favorite bit of "short-cut" code that you use?

One of my favorite shortcuts I'll use when coding a page is to create a sub
along the lines of the following:

Sub Print(myText)
Response.Write myText & vbcrlf
End Sub

And then I use Print instead of Response.Write thru my code.

I do this for several reasons:

A) I'm an old-skool coder, and I started coding back in the days when you
wrote to the screen with "PRINT"

B) It's shorter than doing Response.Write [insert string here] & vbcrlf for
every instance where you want to write to the client.

C) It's easier to use for debug purposes: If for example I want to do a
time-trace to see where a slow-down is occuring, I'll change the code to
Response.Write "<!--" & Now() & "-->" & myText

D) If I want to adapt a particular snippet of code for client-side, I'll
usually just have to copy/paste (along with minor changes), and include the
Print sub, except with Response.Write changed to Document.Write.
 
A

Aaron [SQL Server MVP]

B) It's shorter than doing Response.Write [insert string here] & vbcrlf
for
every instance where you want to write to the client.

I've used rw() in the past.
C) It's easier to use for debug purposes: If for example I want to do a
time-trace to see where a slow-down is occuring, I'll change the code to
Response.Write "<!--" & Now() & "-->" & myText

Wow. If you call this function a lot of times in a single page, the mere
writing out of the now() data is going to skew your results. ;-)

A
 
S

Scott McNair

Wow. If you call this function a lot of times in a single page, the mere
writing out of the now() data is going to skew your results. ;-)

hehe, it was an example. And probably a poor one at that. ;-)

I think the main reason I do it is for comfort-level... I'm so used to
PRINT "My Data" that I find myself wanting to revert to it.

Now if only I could figure out how to ? "My Data" I'd be a happy man!
 
B

Bullschmidt

This line helps a lot (the main code "library" I use on most every page:

<!--#include file="include/jpsutility.asp"-->

Best regards,
J. Paul Schmidt, Freelance ASP Web Designer
http://www.Bullschmidt.com
ASP Designer Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Z

Zenobia

What's your favorite bit of "short-cut" code that you use?

One of my favorite shortcuts I'll use when coding a page is to create a sub
along the lines of the following:

Sub Print(myText)
Response.Write myText & vbcrlf
End Sub

And then I use Print instead of Response.Write thru my code.

Why don't you just use <%= %> instead?

I can't stand those people who do:

Response.Write ...
Response.Write ...
Response.Write ...

rather than
Response.Write ... &_
... &_
...

Worse are the ones who do

strSQL = ...
strSQL = strSQL & ...
strSQL = strSQL & ...
etc

rather than

strSQL = ... &_
... &_
...

Talk about slow cuts.
 
A

Aaron [SQL Server MVP]

Why don't you just use <%= %> instead?

Uh, because that's much less readable, in most cases.
I can't stand those people who do:

Did you mean "I can't stand when people do:"?

A
 
S

Scott McNair

Why don't you just use <%= %> instead?

Well, for one - I may not be breaking out of HTML. Quite a bit of my
code is actually very server-intensive, and I would be going out of my
way to <%=%> things...

'Code goes here
'Code goes here
'Code goes here
%>
<%=NewValue%>
<%
'Code goes here
'Code goes here
[...]


....not to mention the (admittedly minor) overhead that %><%="words"%><%
causes by switching out of, then into, then out of, then into server-
processing.
I can't stand those people who do:

Response.Write ...
Response.Write ...

[snip]

I agree.
 
A

Aaron [SQL Server MVP]

...not to mention the (admittedly minor) overhead that %> said:
causes by switching out of, then into, then out of, then into server-
processing.

This is minor in IIS 4.0 and below.

In IIS 5.0 and above, the parser is MUCH smarter and you will be very
hard-pressed to find ANY overhead difference.
 
Z

Zenobia

Uh, because that's much less readable, in most cases.

In many cases <%= %> is more readable than using Response.Write
because with <%= %> one tends to embed the server output within
HTML but when using Response.Write people I know tend to output
HTML with variables, which means doubling quotes, for instance.
Making the code less readable...
Did you mean "I can't stand when people do:"?

Yes. Well spotted. One has to work with them even if they
completely ignore you when you tell them why they shouldn't do
it.
 
S

Scott McNair

This line helps a lot (the main code "library" I use on most every
page:

<!--#include file="include/jpsutility.asp"-->

Yeah, at work we maintain a "miscfunctions.asp" page which is
more-or-less the same thing. =) Really nice place to dump all those
frequently-used functions.

A couple of functions I've got in mine:

Function DevNotes(Note)
If Dev=True Then Response.Write "<b>" & Now() & ":</b> " &_
Note & "<br>" : Response.Flush
End Function

(I usually put a line at the top of my code while developing it, "Dev =
True". Once it goes into production, I change the line to something
like "If Request("Dev") = "asdfg" Then Dev = True". We use it to
display SQL statements, key steps in a process, etc.)

Function Break(MyText)
Response.Write MyText
Response.End
End Function

[Another development-level function. If something squirrelly is
happening at a particular point, I'll put error-trapping to the effect
of 'If xyz Then Break("XYZ Happened")']

And needless to say, the aforementioned Print function is in there too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,156
Messages
2,570,878
Members
47,413
Latest member
KeiraLight

Latest Threads

Top