473,327 Members | 1,930 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,327 software developers and data experts.

The use of modules (or not)

I've read that modules in .Net are mainly for backwards compability.
Is this true?

If I have variables I want to be exposed to all classes (regular
classes, forms etc), I'd find it natural to put these in a module and
dimension them Public.

Or is the proper way to do it differently?
Regards /Snedker
Nov 21 '05 #1
12 1262

Morten Snedker wrote:
I've read that modules in .Net are mainly for backwards compability.
Is this true?

If I have variables I want to be exposed to all classes (regular
classes, forms etc), I'd find it natural to put these in a module and
dimension them Public.

Or is the proper way to do it differently?


In general, and especially in object-oriented programming, global
variables such as you describe are frowned upon by commentators on
programming practice (see
<http://c2.com/cgi/wiki?GlobalVariablesAreBad> for discussion with
links). Any time you want to create a global variable, you should ask
yourself: is there really no already-existing object that this new
variable rightly 'belongs' to? Should it not rather be a Shared member
of some class that represents the 'main' component of your application?

--
Larry Lard
Replies to group please

Nov 21 '05 #2
Morten,

If I have variables I want to be exposed to all classes (regular
classes, forms etc), I'd find it natural to put these in a module and
dimension them Public.

Or is the proper way to do it differently?

I would not do that. Every object is destructed every time that a procedure
goes out of scope in which it is constructed.

That procedure can be on every level. Even inside an if statement. By
keeping it as far much as possible at the procedure you have the nicest
memorymanagement, while it is as well very describtive when somebody else
is reading your programs back. (Nothing more worse than a value that is
globaly created on a whatever place).

Most what you use in your program are objects. I see seldom a reason to have
something global. (Try more and more as well to avoid shared classes. Try to
instance almost everything).

See by instance this sample.

You have somewhre created a dataset and binded that to a datagrid. That
datagrid using the designer is globaly on your form.

Therefore the reference to your dataset is.

dim ds as DataSet = directcast(mydatagrid.datasource,DataSet)

You can now use the dataset as if it was globaly created.

I hope that this gives some ideas

Cor
Nov 21 '05 #3
If you really want to use globals, google for the singleton pattern. There
is absolutely nothing wrong with "global" variables in this context, as long
as they are managed properly and you protect the implementation sufficiently
from changes. They are essential in many circumstances (I use them for my
"cache manager" in the software I am currently using) - and yes, you can
define your singleton class in a module for global access.
"Morten Snedker" <morten_spammenot_ATdbconsult.dk> wrote in message
news:1e********************************@4ax.com...
I've read that modules in .Net are mainly for backwards compability.
Is this true?

If I have variables I want to be exposed to all classes (regular
classes, forms etc), I'd find it natural to put these in a module and
dimension them Public.

Or is the proper way to do it differently?
Regards /Snedker

Nov 21 '05 #4
"Robin Tucker" <id*************************@reallyidont.com> wrote in
news:d9*******************@news.demon.co.uk:
If you really want to use globals, google for the singleton pattern.
There is absolutely nothing wrong with "global" variables in this
context, as long as they are managed properly and you protect the


You dont need a singleton to make globals. Its really easy. Declare a new class, and add some
public static (shared in VB) fields, thats it.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/
Nov 21 '05 #5
There's freedom in programming - there are many 'proper' ways to do
something. That said - module are not very OO - but you may or may not care
about that.

A module is just a shorthand way of declaring an internal (Friend)
not-inheritable, non-instantiatable class with only shared members. Many
would find the latter acceptable, but not a module - go figure.

David Anton
www.tangiblesoftwaresolutions.com
Home of:
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter

"Morten Snedker" wrote:
I've read that modules in .Net are mainly for backwards compability.
Is this true?

If I have variables I want to be exposed to all classes (regular
classes, forms etc), I'd find it natural to put these in a module and
dimension them Public.

Or is the proper way to do it differently?
Regards /Snedker

Nov 21 '05 #6
Yes thats true - and of course if you are using the singleton pattern, your
singleton object can be the only instance. Many times you might want to use
the class elsewhere in non-global situations.

"Chad Z. Hower aka Kudzu" <cp**@hower.org> wrote in message
news:Xn**************************@127.0.0.1...
"Robin Tucker" <id*************************@reallyidont.com> wrote in
news:d9*******************@news.demon.co.uk:
If you really want to use globals, google for the singleton pattern.
There is absolutely nothing wrong with "global" variables in this
context, as long as they are managed properly and you protect the


You dont need a singleton to make globals. Its really easy. Declare a new
class, and add some
public static (shared in VB) fields, thats it.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Empower ASP.NET with IntraWeb
http://www.atozed.com/IntraWeb/

Nov 21 '05 #7
"Morten Snedker" <morten_spammenot_ATdbconsult.dk> schrieb:
I've read that modules in .Net are mainly for backwards compability.
Is this true?

I don't agree with this statement. Sure, the existance of modules has
historical reasons. VB.NET is a first-class OO language, but it's even
more. It supports other programming paradigms too, which is a great benefit
that makes the programming language very versatile. Note that the "A" in
"BASIC" stands for "all-purpose". A pure OO language will hardly ever be an
all-purpose programming language because OO is not the best solution for all
problems.

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

Nov 21 '05 #8
"Morten Snedker" <morten_spammenot_ATdbconsult.dk> schrieb:
I've read that modules in .Net are mainly for backwards compability.
Is this true?

I don't agree with this statement. Sure, the existance of modules has
historical reasons. VB.NET is a first-class OO language, but it's even
more. It supports other programming paradigms too, which is a great benefit
that makes the programming language very versatile. Note that the "A" in
"BASIC" stands for "all-purpose". A pure OO language will hardly ever be an
all-purpose programming language because OO is not the best solution for all
problems.

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

Nov 21 '05 #9
Well Herfried does this mean that you think as David Anton and me ??

<quote from david >
A module is just a shorthand way of declaring an internal (Friend)
not-inheritable, non-instantiatable class with only shared members. Many
would find the latter acceptable, but not a module - go figure.
</quote from david>

wich is a perfect statement on how i feel regarding this mather do you
concur in this ?? :-)



"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
"Morten Snedker" <morten_spammenot_ATdbconsult.dk> schrieb:
I've read that modules in .Net are mainly for backwards compability.
Is this true?

I don't agree with this statement. Sure, the existance of modules has
historical reasons. VB.NET is a first-class OO language, but it's even
more. It supports other programming paradigms too, which is a great
benefit that makes the programming language very versatile. Note that the
"A" in "BASIC" stands for "all-purpose". A pure OO language will hardly
ever be an all-purpose programming language because OO is not the best
solution for all problems.

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

Nov 21 '05 #10
"m.posseth" <mi*****@nohausystems.nl> schrieb:
Well Herfried does this mean that you think as David Anton and me ??

<quote from david >
A module is just a shorthand way of declaring an internal (Friend)
not-inheritable, non-instantiatable class with only shared members. Many
would find the latter acceptable, but not a module - go figure.
</quote from david>

wich is a perfect statement on how i feel regarding this mather do you
concur in this ?? :-)


I agree. It's sad that discussions about modules are often discussions
about terms, not technical features.

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

Nov 21 '05 #11
Well Herfried does this mean that you think as David Anton and me ??

<quote from david >
A module is just a shorthand way of declaring an internal (Friend)
not-inheritable, non-instantiatable class with only shared members. Many
would find the latter acceptable, but not a module - go figure.
</quote from david>

wich is a perfect statement on how i feel regarding this mather do you
concur in this ?? :-)



"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
"Morten Snedker" <morten_spammenot_ATdbconsult.dk> schrieb:
I've read that modules in .Net are mainly for backwards compability.
Is this true?

I don't agree with this statement. Sure, the existance of modules has
historical reasons. VB.NET is a first-class OO language, but it's even
more. It supports other programming paradigms too, which is a great
benefit that makes the programming language very versatile. Note that the
"A" in "BASIC" stands for "all-purpose". A pure OO language will hardly
ever be an all-purpose programming language because OO is not the best
solution for all problems.

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

Nov 21 '05 #12
"m.posseth" <mi*****@nohausystems.nl> schrieb:
Well Herfried does this mean that you think as David Anton and me ??

<quote from david >
A module is just a shorthand way of declaring an internal (Friend)
not-inheritable, non-instantiatable class with only shared members. Many
would find the latter acceptable, but not a module - go figure.
</quote from david>

wich is a perfect statement on how i feel regarding this mather do you
concur in this ?? :-)


I agree. It's sad that discussions about modules are often discussions
about terms, not technical features.

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

Nov 21 '05 #13

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

Similar topics

11
by: uid09012_ti | last post by:
Hi, i get the following error message when i use py2exe on my application: The following modules appear to be missing I've installed PyXML-0.8.4.win32-py2.4.exe. My version of python is...
1
by: Carl Bolstad | last post by:
I'm writing a C# class library, to be registered as COM and used as an extension to a commercial application called ArcMap. This approach has worked great for a long time, until... ...
2
by: Marre | last post by:
Hi all! I´m using c# and asp.net to do an application. I want to do this application in modules. A customer should be able to buy the modules he/she are intrested of. What are the right way...
28
by: doug.bromley | last post by:
Why is the ElementTree API not a part of the Python core? I've recently been developing a script for accessing the Miva API only to find all the core API's provided by Python for parsing XML is...
0
by: Daniel Nogradi | last post by:
Is there something analogous to __getattr__ for modules? I know how to create a class that has attributes from a list and nothing else by overloading __getattr__ and making sure that the...
2
by: BigJohn | last post by:
I upgraded my ASP.Net 2003 solution to 2005 with very few problems. I have one issue left which I cannot seem to correct. In 2003 I had a VB Module with global functions referenced by my 25 ASPX...
9
by: abcd | last post by:
I have the following directory structure setup... c:\alpha\Person.py ------------------ class Person(IPerson): def __init__(self): print "Alpha person here" c:\beta\Person.py...
1
Thekid
by: Thekid | last post by:
I keep getting an error message that says these modules aren't found: import irc_parse import irc_config I have them but don't understand why I'm getting the error.
3
by: Roy Tong | last post by:
I maintain a shared database on Access 97. I've just tried converting a test copy of the database to 2003 and it appeared to work OK. That is I got no error messages. However then I look at my...
1
by: joe234 | last post by:
Help@ How would I get modules to link to other pages in my website, html pages also. tried creating another folder in modules not sure of the correct code to get the html.php i create to link...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.