Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #809

Re: What is a class?

From GS <gs@somewhere.net>
Newsgroups comp.lang.basic.visual.misc
Subject Re: What is a class?
Date 2012-02-26 01:26 -0500
Organization A noiseless patient Spider
Message-ID <jicjab$6ta$1@dont-email.me> (permalink)
References (4 earlier) <m_WdnZ1BdOYv6NTSnZ2dnUVZ_jydnZ2d@giganews.com> <XnsA004CD148B656auricauricauricauric@88.198.244.100> <cLCdnTOc3IH0NdTSnZ2dnUVZ_tudnZ2d@giganews.com> <jicag2$87f$1@dont-email.me> <5odjk75idm6fgl98vbmabap2djd38nvum5@4ax.com>

Show all headers | View raw


ralph formulated the question :
> On Sat, 25 Feb 2012 22:55:37 -0500, GS <gs@somewhere.net> wrote:
>
>> Jim Mack wrote :
>>>> Jim Mack wrote:
>>>> 
>>>>>>   Dim duck As monster
>>>>>>   Set duck = New monster
>>>>>> 
>>>>>> "Dim duck As New monster" is essentially the same thing as the above 2
>>>>>> lines.
>>>>> 
>>>>> For the purpose of this discussion, maybe. But "Dim As New" is frowned
>>>>> on because it adds an implicit 'is nothing' check on every reference to
>>>>> the object, and you lose control over the object lifetime.
>>>> 
>>>> Interesting. First I've heard of it (but then, I don't use VB very much 
>>>> any   more, and can't recall having ever used VB for "serious" OOP).
>>>> 
>>>> Is this documented anywhere? Help file, MSDN, whatever?
>>> 
>>> The help files do mention it, but obliquely. What is said (from memory) is 
>>> that when you 'Dim As New' the object is not immediately created, as it 
>>> would  be if you did a Dim followed by a Set = New, but rather is 
>>> instantiated on  first reference.
>>> 
>>> The obvious question is, how does it know which is the first reference? It 
>>> knows that because _every_ reference contains a check to see if it's been 
>>> created yet -- the implicit 'is nothing' check I mentioned.
>>> 
>>> What follows from that is that you can't then legitimately test "If x Is 
>>> Nothing" yourself, because doing so references X, and so creates it... 
>>> that's  how you lose (some) control over object lifetime.
>> 
>> I thought that the object created by "Dim As New" existed until the 
>> exit from the scope they were created in. So...
>> 
>> In a procedure: (local scope)
>> Dim colItems As New Collection
>> ..lives for the entire procedure if not explicitly destroyed beforhand.
>> 
>
> ... But you can not "explicitly" destroy the collection object.
> You can clear the contents but never get rid of the object until the
> object reference goes out of scope.
>
>> In a module: (module scope)
>> Dim colItems As New Collection
>> ..lives for the duration code executes within the module if not 
>> explicitly destroyed beforhand.
>> 
>
> ... but you can not "explicitly" destroy the collection object.
> You can clear the contents, but you'll never be shed of the object
> inside the module.
>
>> Global scope:
>> Dim colItems As New Collection
>> ..lives for the entire runtime if not explicitly destroyed beforhand.
>> 
>
> ... but (you guessed it <g>) you can not "explicity" destroy the
> collection object for the life of the program.
>
>> Also, I've created objects in this manner, tested them other than "If 
>> colItems Is Nothing" via ways like "If colItems.Count > 0" so I know if 
>> the created instance exists. Also, creating a new instance by using "If 
>> colItems Is Nothing" doesn't cause any problems when you access its 
>> items later, indicating VB is not at all confused about which 
>> 'instance' you're referring to.
>
> That is less an issue than all that extra code you have added to your
> Application every single time you reference the object. Most of the
> more serious consequences (e.g. memory leaks, circular references,
> problems on Application exits, etc.) only present themselves in highly
> specialized circumstances involving specific objects. Thus one can
> probably program with the "As New" construct for years and never
> notice a problem or bloat, however it only takes a few wasted hours on
> tracking down a particular odd behavior of an object to appreciate it
> is best not to go there in the first place. <g>
>
> -ralph

As usual, you persist to share your great (and much appreciated) 
knowledge and wisdom. Fact is, I've heard this arg before but there was 
never any convincing evidence presented to abondon implicit 
instantiation in local scope. I actually don't practice this at 
module/global levels because it just never sat 'right' with me to do 
so. Thanks for sharing more details about the facts behind the args!

-- 
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion

Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

What is a class? Peter Nolan <peter.nolan40@gmail.com> - 2012-02-24 04:02 -0800
  Re: What is a class? "Auric__" <not.my.real@email.address> - 2012-02-24 14:06 +0000
    Re: What is a class? Peter Nolan <peter.nolan40@gmail.com> - 2012-02-25 03:07 -0800
      Re: What is a class? Helmut_Meukel <Helmut_Meukel@bn-hof.invalid> - 2012-02-25 14:19 +0100
      Re: What is a class? "Auric__" <not.my.real@email.address> - 2012-02-25 21:26 +0000
        Re: What is a class? Jim Mack <no-uce-ube@mdxi.com> - 2012-02-25 18:58 -0500
          Re: What is a class? GS <gs@somewhere.net> - 2012-02-25 19:39 -0500
          Re: What is a class? "Auric__" <not.my.real@email.address> - 2012-02-26 03:09 +0000
            Re: What is a class? Jim Mack <no-uce-ube@mdxi.com> - 2012-02-25 22:35 -0500
              Re: What is a class? GS <gs@somewhere.net> - 2012-02-25 22:55 -0500
                Re: What is a class? "Farnsworth" <nospam@nospam.com> - 2012-02-25 23:27 -0500
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-26 01:30 -0500
                Re: What is a class? "Auric__" <not.my.real@email.address> - 2012-02-26 04:41 +0000
                Re: What is a class? ralph <nt_consulting64@yahoo.net> - 2012-02-25 23:05 -0600
                Re: What is a class? "Henning" <computer_hero@coldmail.com> - 2012-02-26 11:24 +0100
                Re: What is a class? ralph <nt_consulting64@yahoo.net> - 2012-02-25 23:03 -0600
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-26 01:26 -0500
                Re: What is a class? "Stuart McCall" <smccall@myunrealbox.com> - 2012-02-27 04:15 +0000
                Re: What is a class? ralph <nt_consulting64@yahoo.net> - 2012-02-27 00:48 -0600
                Re: What is a class? "Mayayana" <mayayana@invalid.nospam> - 2012-02-27 08:57 -0500
                Re: What is a class? "Stuart McCall" <smccall@myunrealbox.com> - 2012-02-27 19:19 +0000
                Re: What is a class? "Stuart McCall" <smccall@myunrealbox.com> - 2012-02-27 19:12 +0000
                Re: What is a class? "Bob Butler" <bob_butler@cox.invalid> - 2012-02-27 06:06 -0800
                Re: What is a class? "Stuart McCall" <smccall@myunrealbox.com> - 2012-02-27 19:24 +0000
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-27 11:01 -0500
                Re: What is a class? ralph <nt_consulting64@yahoo.net> - 2012-02-27 11:07 -0600
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-27 13:10 -0500
                Re: What is a class? Schmidt <sss@online.de> - 2012-02-27 19:09 +0100
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-27 13:29 -0500
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-27 14:43 -0500
                Re: What is a class? Schmidt <sss@online.de> - 2012-02-27 22:14 +0100
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-27 16:45 -0500
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-27 18:23 -0500
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-27 23:26 -0500
                Re: What is a class? Schmidt <sss@online.de> - 2012-02-28 13:54 +0100
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-28 08:37 -0500
                Re: What is a class? ralph <nt_consulting64@yahoo.net> - 2012-02-28 09:19 -0600
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-28 10:42 -0500
                Re: What is a class? Schmidt <sss@online.de> - 2012-02-29 06:47 +0100
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-29 09:39 -0500
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-29 13:33 -0500
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-29 14:43 -0500
                Re: What is a class? Schmidt <sss@online.de> - 2012-02-29 21:39 +0100
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-29 16:15 -0500
                Re: What is a class? Schmidt <sss@online.de> - 2012-02-29 23:20 +0100
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-28 00:16 -0500
                Re: What is a class? Jim Mack <no-uce-ube@mdxi.com> - 2012-02-27 13:26 -0500
                Re: What is a class? "Stuart McCall" <smccall@myunrealbox.com> - 2012-02-27 19:33 +0000
                Re: What is a class? Jim Mack <no-uce-ube@mdxi.com> - 2012-02-27 15:50 -0500
                Re: What is a class? Helmut_Meukel <Helmut_Meukel@bn-hof.invalid> - 2012-02-26 11:02 +0100
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-26 14:23 -0500
                Re: What is a class? GS <gs@somewhere.net> - 2012-02-26 17:09 -0500
            Re: What is a class? ralph <nt_consulting64@yahoo.net> - 2012-02-25 22:21 -0600
              Re: What is a class? "Auric__" <not.my.real@email.address> - 2012-02-26 04:51 +0000
                Re: What is a class? ralph <nt_consulting64@yahoo.net> - 2012-02-25 23:10 -0600
        Re: What is a class? Peter Nolan <peter.nolan40@gmail.com> - 2012-02-26 04:11 -0800
          Re: What is a class? Helmut_Meukel <Helmut_Meukel@bn-hof.invalid> - 2012-02-26 16:37 +0100
          Re: What is a class? "Auric__" <not.my.real@email.address> - 2012-02-26 18:36 +0000
            Re: What is a class? ralph <nt_consulting64@yahoo.net> - 2012-02-26 14:11 -0600
            Re: What is a class? Peter Nolan <peter.nolan40@gmail.com> - 2012-02-27 03:11 -0800
              Re: What is a class? "Auric__" <not.my.real@email.address> - 2012-02-27 16:33 +0000
                Re: What is a class? Jim Mack <no-uce-ube@mdxi.com> - 2012-02-27 13:33 -0500
                Re: What is a class? Peter Nolan <peter.nolan40@gmail.com> - 2012-02-28 04:07 -0800
    Re: What is a class? Peter Nolan <peter.nolan40@gmail.com> - 2012-02-25 03:33 -0800
    Re: What is a class? Peter Nolan <peter.nolan40@gmail.com> - 2012-02-25 04:19 -0800
  Re: What is a class? "Ivar" <ivar.ekstromer000@ntlworld.com> - 2012-02-24 15:15 +0000
    Re: What is a class? GS <gs@somewhere.net> - 2012-02-24 14:52 -0500
      Re: What is a class? "Ivar" <ivar.ekstromer000@ntlworld.com> - 2012-02-24 23:10 +0000
        Re: What is a class? GS <gs@somewhere.net> - 2012-02-24 19:46 -0500
          Re: What is a class Way off Topic "Ivar" <ivar.ekstromer000@ntlworld.com> - 2012-02-25 02:20 +0000
            Re: What is a class Way off Topic GS <gs@somewhere.net> - 2012-02-25 16:57 -0500
        Re: What is a class? Helmut_Meukel <Helmut_Meukel@bn-hof.invalid> - 2012-02-25 11:36 +0100
    Re: What is a class? Peter Nolan <peter.nolan40@gmail.com> - 2012-02-25 03:35 -0800
  Re: What is a class? Jim Mack <no-uce-ube@mdxi.com> - 2012-02-24 15:23 -0500
    Re: What is a class? "Auric__" <not.my.real@email.address> - 2012-02-25 01:33 +0000
    Re: What is a class? Peter Nolan <peter.nolan40@gmail.com> - 2012-02-25 03:09 -0800
  Re: What is a class? "Mayayana" <mayayana@invalid.nospam> - 2012-02-24 20:05 -0500

csiph-web