Favorite Scripting shortcuts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott McNair

    Favorite Scripting shortcuts

    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.

  • Aaron [SQL Server MVP]

    #2
    Re: Favorite Scripting shortcuts

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

    I've used rw() in the past.
    [color=blue]
    > 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[/color]

    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


    Comment

    • Scott McNair

      #3
      Re: Favorite Scripting shortcuts

      "Aaron [SQL Server MVP]" <ten.xoc@dnartr eb.noraa> wrote in news:Osb
      $AEJWEHA.4024@T K2MSFTNGP12.phx .gbl:
      [color=blue][color=green]
      >> 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[/color]
      >
      > 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. ;-)[/color]

      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!

      Comment

      • Bullschmidt

        #4
        Re: Favorite Scripting shortcuts

        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
        Do you have an idea for a database on the Web? Hi! I'm a freelance Web and/or database developer who can make database information available 'live' on the Web.

        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!

        Comment

        • Zenobia

          #5
          Re: Favorite Scripting shortcuts

          On Tue, 22 Jun 2004 10:36:25 -0700, Scott McNair
          <scott.mcnair@s fmco.takethispa rtout.com> wrote:
          [color=blue]
          >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.[/color]

          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.

          Comment

          • Aaron [SQL Server MVP]

            #6
            Re: Favorite Scripting shortcuts

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

            Uh, because that's much less readable, in most cases.
            [color=blue]
            > I can't stand those people who do:[/color]

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

            A


            Comment

            • Scott McNair

              #7
              Re: Favorite Scripting shortcuts

              Zenobia <6.20.zenobia@s pamgourmet.com> wrote in
              news:ti4jd05eo8 4iss1b3eifqrutu jl28rodcn@4ax.c om:
              [color=blue]
              > Why don't you just use <%= %> instead?[/color]

              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.
              [color=blue]
              > I can't stand those people who do:
              >
              > Response.Write ...
              > Response.Write ...[/color]

              [snip]

              I agree.

              Comment

              • Aaron [SQL Server MVP]

                #8
                Re: Favorite Scripting shortcuts

                > ...not to mention the (admittedly minor) overhead that %><%="words"%>< %[color=blue]
                > causes by switching out of, then into, then out of, then into server-
                > processing.[/color]

                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.

                --

                (Reverse address to reply.)


                Comment

                • Zenobia

                  #9
                  Re: Favorite Scripting shortcuts

                  On Wed, 23 Jun 2004 10:34:29 -0400, "Aaron [SQL Server MVP]"
                  <ten.xoc@dnartr eb.noraa> wrote:
                  [color=blue][color=green]
                  >> Why don't you just use <%= %> instead?[/color]
                  >
                  >Uh, because that's much less readable, in most cases.[/color]

                  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...
                  [color=blue][color=green]
                  >> I can't stand those people who do:[/color]
                  >
                  >Did you mean "I can't stand when people do:"?[/color]

                  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.

                  Comment

                  • Scott McNair

                    #10
                    Re: Favorite Scripting shortcuts

                    Bullschmidt <paul@bullschmi dt.com-nospam> wrote in
                    news:eqQliQOWEH A.1952@TK2MSFTN GP12.phx.gbl:
                    [color=blue]
                    > This line helps a lot (the main code "library" I use on most every
                    > page:
                    >
                    > <!--#include file="include/jpsutility.asp"-->[/color]

                    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.

                    Comment

                    Working...