PC Review


Reply
Thread Tools Rate Thread

Classes vs. Modules

 
 
Zytan
Guest
Posts: n/a
 
      9th Feb 2007
I've read the docs on this, but one thing was left unclear. It seems
as though a Module does not have to be fully qualified. Is this the
case? I have source that apparently shows this.

Are modules left-over from VB6, and not much used anymore? It seems
that it is better to require Imports or use fully qualified names for
functions in other classes/modules, but a Module doesn't require this,
cluttering the global namespace. It seems using a class with shared
functions/subs is better.

Any recommendations?

Zytan

 
Reply With Quote
 
 
 
 
lord.zoltar@gmail.com
Guest
Posts: n/a
 
      9th Feb 2007
On Feb 9, 3:15 pm, "Zytan" <zytanlith...@yahoo.com> wrote:
> I've read the docs on this, but one thing was left unclear. It seems
> as though a Module does not have to be fully qualified. Is this the
> case? I have source that apparently shows this.
>
> Are modules left-over from VB6, and not much used anymore? It seems
> that it is better to require Imports or use fully qualified names for
> functions in other classes/modules, but a Module doesn't require this,
> cluttering the global namespace. It seems using a class with shared
> functions/subs is better.
>
> Any recommendations?
>
> Zytan


I still sometimes use modules for global variables and functions... I
think it was mentioned a while ago in this group (search for it, I'm
not sure) that Modules actually get compiled into static classes with
shared static members and functions...

 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      9th Feb 2007
"Zytan" <(E-Mail Removed)> schrieb
> I've read the docs on this, but one thing was left unclear. It
> seems as though a Module does not have to be fully qualified. Is
> this the case? I have source that apparently shows this.
>
> Are modules left-over from VB6, and not much used anymore? It seems
> that it is better to require Imports or use fully qualified names
> for functions in other classes/modules, but a Module doesn't require
> this, cluttering the global namespace. It seems using a class with
> shared functions/subs is better.
>
> Any recommendations?


It's been discussed about 1 mio times, so please search this group first.
http://groups.google.com/groups/sear...ject%3Amodule*


Armin

 
Reply With Quote
 
Zytan
Guest
Posts: n/a
 
      9th Feb 2007
> I still sometimes use modules for global variables and functions... I
> think it was mentioned a while ago in this group (search for it, I'm
> not sure) that Modules actually get compiled into static classes with
> shared static members and functions...


Ok. That's interesting.

I try to avoid global vars like the plague, as do most, so I cannot
see why anyone would still want to use this. If you're gonna have a
'global var', it seems better to at least be in a class, where you
confine it to a certain location.

Zytan

 
Reply With Quote
 
Zytan
Guest
Posts: n/a
 
      9th Feb 2007
> It's been discussed about 1 mio times, so please search this group first.http://groups.google.com/groups/sear...3Amicrosoft.pu...
>
> Armin


Will do. I'm surprised a generic google search didn't return these
results, it usually does at the bottom of the first page of results.
Maybe it's the personalized results stopping it.

Zytan

 
Reply With Quote
 
Zytan
Guest
Posts: n/a
 
      9th Feb 2007
> Any recommendations?

>From an MVP (Cor):

http://groups.google.com/group/micro...fa6556bc656471
"There is never a reason to use a module execpt if you have that
already in
your VB6 converted program."

Exactly what I thought. Good enough.

Zytan

 
Reply With Quote
 
lord.zoltar@gmail.com
Guest
Posts: n/a
 
      9th Feb 2007
On Feb 9, 4:17 pm, "Zytan" <zytanlith...@yahoo.com> wrote:
> > I still sometimes use modules for global variables and functions... I
> > think it was mentioned a while ago in this group (search for it, I'm
> > not sure) that Modules actually get compiled into static classes with
> > shared static members and functions...

>
> Ok. That's interesting.
>
> I try to avoid global vars like the plague, as do most, so I cannot
> see why anyone would still want to use this. If you're gonna have a
> 'global var', it seems better to at least be in a class, where you
> confine it to a certain location.
>
> Zytan


I know... I don't like globals either, but they do creep up
occasionally... I rarely have need for more than one or two. I used
modules a bit more when porting an old VB6 project. It was just easier
to leave stuff in them as long as it compiled. those parts are slowly
being re-written.
I also like Modules for situations like the Math class. I never need
to create an instance of Math, I just need functions like sine,
cosine, and constants, like Pi.

 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      9th Feb 2007
"Zytan" <(E-Mail Removed)> schrieb:
>> Any recommendations?

>
>>From an MVP (Cor):

> http://groups.google.com/group/micro...fa6556bc656471
> "There is never a reason to use a module execpt if you have that
> already in
> your VB6 converted program."
>
> Exactly what I thought. Good enough.


Well, I have to disagree.

Personally, I do /not/ use modules to store variables and program state. I
use modules only in very few cases: The project's main entry point is
placed in a module 'Program'. In addition, common functions are placed in
modules if their use makes sense throughout the project, similar to
"Microsoft.VisualBasic.dll" and its modules. In this case modules are used
to structure a huge set of functions, but make them easily accessible in
IntelliSense everywhere.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

 
Reply With Quote
 
Scott M.
Guest
Posts: n/a
 
      9th Feb 2007
I don't know if I agree with that. A module can be used as a starting point
for your application along with a Sub Main. This can be helpful in
directing the flow of the application startup.


"Zytan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> Any recommendations?

>
>>From an MVP (Cor):

> http://groups.google.com/group/micro...fa6556bc656471
> "There is never a reason to use a module execpt if you have that
> already in
> your VB6 converted program."
>
> Exactly what I thought. Good enough.
>
> Zytan
>



 
Reply With Quote
 
Zytan
Guest
Posts: n/a
 
      9th Feb 2007
> I know... I don't like globals either, but they do creep up
> occasionally... I rarely have need for more than one or two. I used
> modules a bit more when porting an old VB6 project. It was just easier
> to leave stuff in them as long as it compiled. those parts are slowly
> being re-written.


Yeah, understood. I agree. For VB6, it's best to leave as is, until
you have time to rewrite. But, this isn't a good starting point to
judge how new code should be (and I don't think this is what you are
trying to say, so I think we agree).

> I also like Modules for situations like the Math class. I never need
> to create an instance of Math, I just need functions like sine,
> cosine, and constants, like Pi.


Yes, exactly. This is precisely what I want. But... it appears you
can just call these function without requiring Math.Pi, but just by
saying Pi. I don't like this. (Maybe I am wrong about this? But,
that's what the docs imply and source code examples I've seen imply.)

Zytan

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using classes vs. modules Andy B. Microsoft VB .NET 216 11th Mar 2009 07:44 PM
Concept ? about Modules vs Classes Bruce D Microsoft VB .NET 8 28th Feb 2005 05:03 AM
Classes vs modules Chris Nebinger Microsoft Access Getting Started 6 7th May 2004 02:48 AM
Printing from classes and modules =?Utf-8?B?SmFtZXMgUHJvY3Rvcg==?= Microsoft VB .NET 4 20th Feb 2004 03:21 PM
Shared classes or modules? Rob Teixeira [MVP] Microsoft VB .NET 5 7th Feb 2004 06:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:22 AM.