473,378 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Why use a module instead of class?

I've seen few examples on the usefulness of a module. Why use a module
instead of a class?

If I put a method into Module1, how is it called from other classes?

Thanks,
Brett
Nov 21 '05 #1
15 1573
Methods are easy ways of making shared assemblies. All public procedures are
intrinsically Shared. The module can not be instantiated. So you would call
it simply as module.method
--
--Eric Cathell, MCSA
"Brett" <no@spam.com> wrote in message
news:Oh**************@TK2MSFTNGP12.phx.gbl...
I've seen few examples on the usefulness of a module. Why use a module
instead of a class?

If I put a method into Module1, how is it called from other classes?

Thanks,
Brett

Nov 21 '05 #2

Brett wrote:
I've seen few examples on the usefulness of a module. Why use a module instead of a class?
Because you have global entitites that don't meaningfully belong to any
class. Class instance members are for <things> that have something to
do with a particular object; Class shared members are for <things> that
have something to do with a class in general; Module members are for
global <things> (where a <thing> is a variable, a function, whatever).

OOP purists will decry the use of Modules, and indeed global <things>,
but they have their place.

If I put a method into Module1, how is it called from other classes?


Module Module1

Public Sub MySub()
'...
End Sub

End Module

then from anywhere in the app:

MySub
--
Larry Lard
Replies to group please

Nov 21 '05 #3
"Brett" <no@spam.com> schrieb:
I've seen few examples on the usefulness of a module. Why use a module
instead of a class?

If I put a method into Module1, how is it called from other classes?


In addition to the other replies, you will find previous discussions on this
topic here:

<URL:http://groups.google.com/groups?q=dotnet.languages+vb+modules+class>

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

Nov 21 '05 #4
Hi Brett,

If I was doing a code review on your code, and you had as much as a single
module in your code, I'd ask you to justify it. To date, very few have
succeeded in justifying one of these, and most have had to rewrite.

(In C#: a class containing only static methods would qualify the same way).

To date, I've seen valid use for "modules" only when similar, in concept, to
the System.Math class, where an external source of well-understood
algorithms is the foundation for the mechanism.

(I do not use the original Data Access Application Block either, for the
same reason).

In most cases, an object composed of static methods (Module in VB parlance)
is an very strong indicator of very weak design.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Brett" <no@spam.com> wrote in message
news:Oh**************@TK2MSFTNGP12.phx.gbl...
I've seen few examples on the usefulness of a module. Why use a module
instead of a class?

If I put a method into Module1, how is it called from other classes?

Thanks,
Brett

Nov 21 '05 #5
Nick,

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> schrieb:
In most cases, an object composed of static methods (Module in VB
parlance) is an very strong indicator of very weak design.


I think this strongly depends on what type of application you are
developing: Reusable libraries, large applications/systems, or small tools
which help you to get your job done. For the latter design has a very low
prioritiy because code won't be reused and rarely extended. /Designing/
such a small tool won't be worth the effort and modules are a great
accelerator when developing such applications.

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

Nov 21 '05 #6

"ECathell" <ec******@nospam.mountaire.com> wrote in message
news:eR*************@TK2MSFTNGP15.phx.gbl...
Methods are easy ways of making shared assemblies. All public procedures
are intrinsically Shared. The module can not be instantiated. So you would
call it simply as module.method


I believe you mean "Modules are easy ways..." :)

Mythran

Nov 21 '05 #7
VB3 must have been difficult for you then!

"Nick Malik [Microsoft]" wrote:
Hi Brett,

If I was doing a code review on your code, and you had as much as a single
module in your code, I'd ask you to justify it. To date, very few have
succeeded in justifying one of these, and most have had to rewrite.

(In C#: a class containing only static methods would qualify the same way).

To date, I've seen valid use for "modules" only when similar, in concept, to
the System.Math class, where an external source of well-understood
algorithms is the foundation for the mechanism.

(I do not use the original Data Access Application Block either, for the
same reason).

In most cases, an object composed of static methods (Module in VB parlance)
is an very strong indicator of very weak design.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Brett" <no@spam.com> wrote in message
news:Oh**************@TK2MSFTNGP12.phx.gbl...
I've seen few examples on the usefulness of a module. Why use a module
instead of a class?

If I put a method into Module1, how is it called from other classes?

Thanks,
Brett


Nov 21 '05 #8
Hi Herfried,

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:e6**************@TK2MSFTNGP10.phx.gbl...
Nick,

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> schrieb:
In most cases, an object composed of static methods (Module in VB
parlance) is an very strong indicator of very weak design.
I think this strongly depends on what type of application you are
developing:


A fair statement. I realize that my characterization was over-reaching.
When I re-read it, I want to rewrite it.
Reusable libraries, large applications/systems, or small tools which help
you to get your job done. For the latter design has a very low prioritiy
because code won't be reused and rarely extended.
Also a fair statement. On the other hand, I wouldn't normally perform a
code review on a "one-off tool" :-)

/Designing/ such a small tool won't be worth the effort and modules are a
great accelerator when developing such applications.


I find that I cannot disagree with a single statement you made.

My response was over-reaching, as I said. It was a visceral response,
perhaps. I would defend the "rule of thumb" that a well designed system of
objects is usually better off if classes composed entirely of static methods
can be avoided. I'd consider it good practice to avoid this type of object,
regardless of system size. However, you are also correct: it is frequently
better to set aside such rules when creating small apps that will not be
extended.

Thank you for your response.
--- Nick
Nov 21 '05 #9
Nick,

We don't agree about this last message from you. When a theoretical question
is placed. Than the answer has to be theoretical.

That you with a relative unimportant program (there are more reasons) will
go earlier to a simple sollution, when you don't succeed in a good
theoretical approach, is obvious.

However no reason to take that as the first approach.

In addition, when you review an application than it is a program that has to
be checked on good theoretical implementation, when that is not important
you would not review it.

Just my thought,

Cor
Nov 21 '05 #10
Nick,
We don't agree <
May I ask who else you are speaking for?


Maybe wrong. However, when I write that I disagree with the one I write too,
than I use "we", because "we" have not the same opinion. (Although I can
use for the same "I don't agree with you").
When a theoretical question is placed. Than the answer has to be
theoretical.


I respond with all due respect, Cor. However, I find that I disagree.


I hope not and that comes back in the end of your last message. I wrote my
previous message because I was fully agreeing with your first message in
this thread. Therefore, I was disapproved that you corrected that in a way
that it "seemed" if that one was not right.

Maybe it was not right to place the message in the way I did, however I had
fun when I wrote it in that way, because I expected such a reaction as this
from you. In fact do we full agree (Sorry, do I full agree with you).

I thought I could do that because we share almost forever the same method of
helping. Do not make it to theoretical, just help on the level that is good
for the one who asks a question. As in your nice sentence: "Humbly share,
then inform, and finally encourage."

Here was the question of the OP "Why use a module instead of a class"

This needs in my opinion a little bit other approach. In addition, you first
answer was very correct in my opinion and needed not any further
explanation.

However, I was disapproved because you made it at least for me sound in
another way when you answered Herfried.

I hope we agree (That you do agree with me) again and thinking it over that
you did obviously express not quot the part "about this message", did you
probably answer me in the same style as I was doing.

:-))

Cor

Nov 21 '05 #11
doh

disapproved has to be disappointed

Please don't read it in the way it is now, this is a very often by me made
error by the way when I am writing.

:-)

Cor
Nov 21 '05 #12
Nick,

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> schrieb:
It is my personal practice to approach *all* applications this way. I
don't have any desire to dump my practices on others. I share my
experiences. I encourage others to try them. But I am not offended if
another person does not agree. Even when that person is a respected MVP,
as Herfried is. I hope that he is not offended either.
I don't disagree with what you are saying. The intention of my post was to
point out that there are people who don't have the knowledge we have and
don't need this level of knowledge to get their work done. It's a legitimate
interest of them to be able to write small, not-reusable tools without
needing to worry about OO too much. To make a concluding remark, I believe
that even if people like you and me don't make use of modules, others will
do.
When I am in a position of managing a code base (as I am in my work), I
enforce the coding standards of my team.


You are working in a development company, I think :-). However, there are
many users who are not developers but need to write smaller applications
simply in order to get their work done. I agree with you that in larger
teams coding standards play a crucial role, especially if a high quality of
the code is a requirement.

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

Nov 21 '05 #13
Herfried,
I don't disagree with what you are saying. The intention of my post was
to point out that there are people who don't have the knowledge we have
and don't need this level of knowledge to get their work done. It's a
legitimate interest of them to be able to write small, not-reusable tools
without needing to worry about OO too much. To make a concluding remark,
I believe that even if people like you and me don't make use of modules,
others will do.

That we (you and me) agree about 100%. Nice text.

Cor
Nov 21 '05 #14
Herfried,

LOL
You are working in a development company, I think :-).


Nick is working at Microsoft for about almost an half year now. That is a
development company, you are right. :-)).

He has it in his signature.

Cor
Nov 21 '05 #15
Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
LOL
You are working in a development company, I think :-).


Nick is working at Microsoft for about almost an half year now. That is a
development company, you are right. :-)).

He has it in his signature.


That's why I put a ":-)" next to the "I think" ;-))).

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

Nov 21 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Peter Åstrand | last post by:
There's a new PEP available: PEP 324: popen5 - New POSIX process module A copy is included below. Comments are appreciated. ---- PEP: 324 Title: popen5 - New POSIX process module
5
by: dody suria wijaya | last post by:
I found this problem when trying to split a module into two. Here's an example: ============== #Module a (a.py): from b import * class Main: pass ============== ==============
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
25
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30...
42
by: WindAndWaves | last post by:
Dear All Can you tell me why you use a class module??? Thank you Nicolaas ---
3
by: Phillip Ian | last post by:
Just a quick architecture question. I'm just looking for discussion, not a flame war, please. In the past, I've tended to use a public module for my data layer functions. Something like: ...
3
by: Zachary Pincus | last post by:
Hi folks, I'm sure this has come up before, but the search terms I've been using are so non-specific that I can't get any traction on Google. Here's my question: I have written a subclass of...
10
by: Bonzol | last post by:
vb.net Hey there, could someone just tell me what the differnce is between classes and modules and when each one would be used compared to the other? Any help would be great Thanx in...
32
by: Matias Jansson | last post by:
I come from a background of Java and C# where it is common practise to have one class per file in the file/project structure. As I have understood it, it is more common practice to have many...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.