Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP General (http://www.velocityreviews.com/forums/f65-asp-general.html)
-   -   How expensive is object instantication? (http://www.velocityreviews.com/forums/t802138-how-expensive-is-object-instantication.html)

sam.s.kong@gmail.com 10-04-2006 04:47 PM

How expensive is object instantication?
 
Hi,

I'm doing an ASP project in VBScript.
In VBScript, there's no namespace and no static method (class method).
Thus, what I'm trying to do is to make a clas, define instance methods
in the class, create a global object and call the instance methods.
It will simulate a namespace.
My concern is that what's the overhead.

-----------Example----------

[library.asp]

class MyClass
function F1
....
end function

function F2
....
end function
end class

set G = new MyClass 'This will be always created even if it's not used
at all.

[some_page.asp]
<!--#include file="library.asp"-->
G.F1
G.F2

-------------------------

What do you think?
Is it good or bad?
And why so?

If you have any other suggestions about namespace, share with me
please.

Thanks.

Sam


Patrice 10-04-2006 05:11 PM

Re: How expensive is object instantication?
 
If you do nothing in the initialize event, it is likely small compared with
DB access etc... Also this is the kind of question that is easily solved by
testing...

Another option would be to use a prefix before your the sub name (i.e.
something like G_F1 or glbF1)
--
Patrice

<sam.s.kong@gmail.com> a écrit dans le message de news:
1159980435.619025.312710@h48g2000cwc.googlegroups. com...
> Hi,
>
> I'm doing an ASP project in VBScript.
> In VBScript, there's no namespace and no static method (class method).
> Thus, what I'm trying to do is to make a clas, define instance methods
> in the class, create a global object and call the instance methods.
> It will simulate a namespace.
> My concern is that what's the overhead.
>
> -----------Example----------
>
> [library.asp]
>
> class MyClass
> function F1
> ....
> end function
>
> function F2
> ....
> end function
> end class
>
> set G = new MyClass 'This will be always created even if it's not used
> at all.
>
> [some_page.asp]
> <!--#include file="library.asp"-->
> G.F1
> G.F2
>
> -------------------------
>
> What do you think?
> Is it good or bad?
> And why so?
>
> If you have any other suggestions about namespace, share with me
> please.
>
> Thanks.
>
> Sam
>




sam.s.kong@gmail.com 10-04-2006 05:13 PM

Re: How expensive is object instantication?
 
Hi Justin,

Justin Piper wrote:
> You could do it this way instead. It avoids creating the object unless
> it is needed, and it guarantees that the class will be instantiated by
> the time it is used.
>
> G.F1
>
> Function G()
> If IsEmpty([G::Inst]) Then Set [G::Inst] = New MyClass
> Set G = [G::Inst]
> End Function
>
> Class MyClass
> Function F1() : End Function
> End Class
>
> Dim [G::Inst]


Excellent!
That way, I can delay the instantication until it's first used.
So, basically you think that wrapping functions in a class is a good
workaround to simulate namespaces?

By the way, I've never seen a notation like [G::Inst].
Is it a valid syntax?

Thanks.

Sam


Anthony Jones 10-05-2006 07:30 AM

Re: How expensive is object instantication?
 

"Justin Piper" <jpiper@bizco.com> wrote in message
news:op.tgwrd0uzcs3d1w@luxembourg.psg.bizcotech.co m...
> On Wed, 04 Oct 2006 12:13:49 -0500, <sam.s.kong@gmail.com> wrote:
>
> > Hi Justin,
> >
> > Justin Piper wrote:
> >> You could do it this way instead. It avoids creating the object unless
> >> it is needed, and it guarantees that the class will be instantiated by
> >> the time it is used.
> >>
> >> G.F1
> >>
> >> Function G()
> >> If IsEmpty([G::Inst]) Then Set [G::Inst] = New MyClass
> >> Set G = [G::Inst]
> >> End Function
> >>
> >> Class MyClass
> >> Function F1() : End Function
> >> End Class
> >>
> >> Dim [G::Inst]

> >
> > Excellent!
> > That way, I can delay the instantication until it's first used.
> > So, basically you think that wrapping functions in a class is a good
> > workaround to simulate namespaces?

>
> The only other way to simulate namespaces I can think of is to adopt a
> naming convention that includes the namespace name:
>
> Function [G::F1]() : End Function
>
> Function Main()
> Dim F1: Set F1 = GetRef("G::F1")
>
> F1()
> End Function
>
> That might be useful if you wanted to break the G namespace into
> multiple files.
>
> > By the way, I've never seen a notation like [G::Inst].
> > Is it a valid syntax?

>
> It's a quoted identifier. They're not very useful in general, so I tend
> to use them to indicate that one identifier has some relationship to
> another (e.g, I probably would have named the class [G::Impl]).
>


If you had that much complexity that a namespace needed to be split into
seperate files you wouldn't be building your class hiearchy in VBScript.


> --
> Justin Piper
> Bizco Technologies
> http://www.bizco.com/




Anthony Jones 10-05-2006 08:01 AM

Re: How expensive is object instantication?
 

<sam.s.kong@gmail.com> wrote in message
news:1159980435.619025.312710@h48g2000cwc.googlegr oups.com...
> Hi,
>
> I'm doing an ASP project in VBScript.
> In VBScript, there's no namespace and no static method (class method).
> Thus, what I'm trying to do is to make a clas, define instance methods
> in the class, create a global object and call the instance methods.
> It will simulate a namespace.
> My concern is that what's the overhead.
>
> -----------Example----------
>
> [library.asp]
>
> class MyClass
> function F1
> ....
> end function
>
> function F2
> ....
> end function
> end class
>
> set G = new MyClass 'This will be always created even if it's not used
> at all.
>
> [some_page.asp]
> <!--#include file="library.asp"-->
> G.F1
> G.F2
>
> -------------------------
>
> What do you think?
> Is it good or bad?
> And why so?
>


It's a good idea. I use this approach a lot avoid function name collision
between multiple include files and/or functions in the page.

The only thing you need to be careful of then is that the class names that
you use will not collide but since there are far fewer of them that's fairly
easy.




> If you have any other suggestions about namespace, share with me
> please.
>
> Thanks.
>
> Sam
>





All times are GMT. The time now is 11:31 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.