Module Oddity


R

Rex the Strange

Hello all,

Traditionally I'm a Delphi and VB6 programmer and have recently started
working with VB.NET (which, I might add, I love, but that's beside the
point). Anyway, I was trying to make a catch-all library of routines
which I use commonly (I have one in Delphi and I was porting some of
the routines to VB.NET).

I was delighted to find out about modules - I love that a language
doesn't tie you to making everything an object - in my opinion oop is
good, but it isn't the be-all-to-end-all of programming as some people
might have you believe: not everything in programming (or the world for
that matter) is an object. Some things are processes. Ideal programming
is a combination of the two.

But I digress.

Anyway, I thought I'd make a class library - I called it stdlib (which
is the name I always use: short for "standard library") and inside it I
put two modules: constants and procedures.

Here's the oddity. When I include them into a new file, using the
Imports statement, I find that I type:

Imports stdlib.

And when I hit the dot (.) a popup dropdown list appears showing me all
of the elements contained in stdlib. Fair enough, but I see "constants"
which I can then specify and I see "procedures" which I can specify but
I also see all of the constants defined in "constants" and all of the
procedures defined in "procedures."

What's even more weird is that although I can see these in the list if
I just define

Imports stdlib

with no qualifier and try to use those constants and procedures I get
unknown element errors when attempting to compile. Why even show them
if I can't use them at that level? What other options do I have? I
could make a static class except that that could promote stupidity in
attempting to make instances of that class. I've tried defining a
namespace which has the effect I want except that I can only put types
in them, no constants or subroutines.

Any thoughts?
 
Ad

Advertisements

A

aaron.kempf

Rex;

that was the most well-spoken remarks-- about loving modules-- LoL

you're going to make me chuckle for a long time on that one; I've been
trying to explain this to some friends for the longest time and they
'just dont get it'

I love it man.. PLEASE keep speaking the truth; I think that OOP is a
load of hogwash; all it does is slow down development and slow down
execution

I've heard that 80% of vb6 developers 'never built a single class'
and I agree with that diagnosis.

and it pisses me off that Microsoft is jamming OOP down our throats;
they're trying to sell us on features that we don't want or need.

I enjoy code re-use -- I'm a big fat lazy programmer-- so I use modules
almost exclusively

-Aaron
 
R

RobinS

When you want to use one of the module's entries, try
prefixing it with "stdlib".

x = stdlib.myfunction

BTW, modules seem to have gone out of fashion, and
most people use classes now.

Robin S.
 
P

Phill W.

Rex said:
I was delighted to find out about modules - I love that a language
doesn't tie you to making everything an object

Guess What? Under the covers, Modules are Classes; they're just
Attribute'd in such a way that everything you put into one is implicitly
made "Shared" ... ;-)
in my opinion oop is good, but it isn't the be-all-to-end-all of
programming as some people might have you believe:
Agreed.

Anyway, I thought I'd make a class library - I called it stdlib (which
is the name I always use: short for "standard library") and inside it I
put two modules: constants and procedures.

You don't actually need the enclosing Class. Compare these:

Class stdlib
Module Constants
Module Procedures
End Class

Namespace ?.?.stdlib
Module Constants
Module Procedures
End Namespace
Here's the oddity. When I include them into a new file, using the
Imports statement, I find that I type:

Imports stdlib.

And when I hit the dot (.) a popup dropdown list appears showing me all
of the elements contained in stdlib.

Is this is the same Project in which you define stdlib?
If so, examine the Root namespace Project Property.

In all likelihood, this is set to "stdlib" and ,if it is, remove it!!

I've /never/ found a Good Reason to use this property and /lots/ of Good
Reasons to get rid of it, not least of which being that it messes up all
the References, prefixing them with, in your case, "stdlib."!

HTH,
Phill W.
 
H

Herfried K. Wagner [MVP]

Rex the Strange said:
I was delighted to find out about modules - I love that a language
doesn't tie you to making everything an object - in my opinion oop is
good, but it isn't the be-all-to-end-all of programming as some people
might have you believe: not everything in programming (or the world for
that matter) is an object. Some things are processes. Ideal programming
is a combination of the two.

But I digress.

Anyway, I thought I'd make a class library - I called it stdlib (which
is the name I always use: short for "standard library") and inside it I
put two modules: constants and procedures.

Here's the oddity. When I include them into a new file, using the
Imports statement, I find that I type:

Imports stdlib.

And when I hit the dot (.) a popup dropdown list appears showing me all
of the elements contained in stdlib. Fair enough, but I see "constants"
which I can then specify and I see "procedures" which I can specify but
I also see all of the constants defined in "constants" and all of the
procedures defined in "procedures."

As all modules are imported automatically, all members defined in modules
can be used without qualifying them with the module name or namespace
containing the module. This behavior is by design.

To group types, use namespaces.
To group methods, use modules.
To represent entities, use classes.
 
R

Rex the Strange

Interesting comments from all of you. I realize that modules are
classes under the covers (it's in the documentation that it is
essentially a class comprised entirely of static methods). It seems
people go both ways on the oop debate.

But really, there should be no debate. Do what works for you.

rts.
 
Ad

Advertisements

A

aaron.kempf

robin

guess what you're full of crap

80% of vb developers have never written a class

-Aaron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top