is better to have more/less parameters for a funct

Results 1 to 3 of 3

Thread: is better to have more/less parameters for a funct

  1. #1
    bubba Guest

    Default is better to have more/less parameters for a funct

    okie suppose there is a function within a function.<BR><BR>function reserveTicket (memberobject as variant, airlineInfo as variant) as boolean <BR> &#039do stuff to memberobject, do stuff to airlineinfo object<BR> emailAirline() &#039this is the other function <BR>end function <BR><BR>so my question is is better to pass in a lot of parameters to emailAirline like emailAirline(,, or is better<BR>to just pass in an ID and do more work within the other function.<BR>so it would emailAirline(airlineInfo.ID).<BR><BR>what is the pros/cons of passing a lot of variables around?<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: is better to have more/less parameters for a f

    &nbsp;<BR>Well, you wrote<BR><BR>&#062; function reserveTicket (memberobject as variant, airlineInfo as variant) as boolean <BR><BR>Which is VB and not VBScript, so I presume you are asking the question from the point of view of that language.<BR><BR>And I note that you are passing class instances around as the arguments, right?<BR><BR>So I think you already have the answer: When you pass a class instance, you are really simply passing a pointer to the given object. Minimal overhead in the call. And yet the callee has access to all the public members of that class at the cost, in a compiled language, of only one extra pointer indirection (perhaps one memory cycle? 10ns on a PC100 bus? maybe not even that much if the memory is cached?). Each argument passed, on the other hand, requires a handful of instructions (both to put it on the stack and then to retrieve it in the callee, but how efficiently this is done depends heavily on the compiler). So pass references to objects when you can.<BR><BR>Oh, and with VB, do *NOT* pass something as Variant if you can help it! If you know that it is supposed to be an AirlineInfo object, that declare it to be so! Much, much more efficient. Maybe 100 times or more in some cases.<BR><BR>*******************<BR><BR>Now, if you goofed in your example and you really meant to ask the question relevant to VBScript, then the answers are all different. Reason: Since everything in VBS is *always* passed by Variant, if you have to do<BR>&nbsp;&nbsp;&nbsp;&nbsp;objectName.fieldName <BR>then the lookup of the field by "fieldName" *must* be done at runtime using the actual BSTR value "fieldName" (that is, a text based lookup). HORRIBLY slow! So in VBS the "trick" is to avoid doing member lookup as much as possible. Assign the member to a local variable and use it. Or, if you already have the value in a local variable in the caller, then pass it as an argument to the callee so it doesn&#039t have to be looked up again. <BR><BR>Summary: In VBScript, it&#039s always slow and the answers aren&#039t as obvious.<BR><BR><BR><BR><BR><BR>everything is always

  3. #3
    bubba Guest

    Default thanks bill


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts