More performative way to work with Request in Classic ASP?

Asked

Viewed 321 times

1

I’m working on a web page that uses Classic ASP and I got a question, store the value of a request in a variable improves performance when compared to staying using the request("value") throughout the code?

The best is so?

if Request("valor") > 0 AND cond1 Then
   ...
Elseif Request("valor") < 0 AND cond2 Then
   umaVar = Request("valor") + 2
End If

Or so

Dim dblValor : dblValor = Request("valor")
if dblValor  > 0 AND cond1 Then
   ...
Elseif dblValor  < 0 AND cond2 Then
   umaVar = dblValor  + 2
End If

Or there’s no difference?

EDIT: A motivation for doubt: When we send n data to capture with the request, among them the "value", when performing the call Request("value") I have a unique memory address to be consulted or there is something similar to a list or dictionary that the application needs to go through, Worst-case scenario in the records, every time the call is made? I don’t know how the request behavior works but I found that ASP does a search* to know if it is a Request.Form, or Request.Querystring and so on, but what about the storage of these values?

*https://msdn.microsoft.com/en-us/library/ms524948(v=vs.90). aspx

  • Hello Seffrin, your question is a little more or less, could you put a code to improve the understanding of who will answer? Preferably a more complete code, exemplifying your doubt.

  • I edited it, I think it’s clearer now.

  • I believe that the performance will not be changed in the two forms exposed, but if we take into account the maintenance of the code create a variable to store the value is the best way; since it will be a single entry point. We assume that one day you resolve to change the name from "value" to "foo" you will have to change at all points, since if you assign to a variable you will have to change only in a single location. You should also consider that Request("value") might not be loaded with a monetary value and this would result in an error in the application.

  • I made an edition to illustrate better what generated the doubt, because I do not know how the behavior of the request works. I know he does a search to find out if it’s a Request.Form, or Request.Querystring and so on, but what about storing those values?

1 answer

0

Much better assign the request() to a variable:

variavel = request("variavel")

Besides the code getting thinner, it is much better to work with the data received, especially if there is need to treat them:

variavel = trim(replace(replace(request("variavel"),"'",""),"_",""))

Imagine having to repeat trim(replace(replace(request("variavel"),"'",""),"_","")) every time you want to take the request()? And if you want to change the way you treat request()? You would have to change all the code. Using a variable for the request() this becomes much simpler.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.