|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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 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 -- Show quoteHide quote--Eric Cathell, MCSA "Brett" <no@spam.com> wrote in message news:OhCqHdcQFHA.3544@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 > "ECathell" <ecathell@nospam.mountaire.com> wrote in message I believe you mean "Modules are easy ways..." :)news:eRZaUhcQFHA.204@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 > > Mythran Brett wrote:
> I've seen few examples on the usefulness of a module. Why use a Because you have global entitites that don't meaningfully belong to anymodule > instead of a class? 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. > Module Module1> If I put a method into Module1, how is it called from other classes? Public Sub MySub() '... End Sub End Module then from anywhere in the app: MySub -- Larry Lard Replies to group please "Brett" <no@spam.com> schrieb: In addition to the other replies, you will find previous discussions on this > 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? 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/> 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. -- Show quoteHide quote--- 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:OhCqHdcQFHA.3544@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 > Nick,
"Nick Malik [Microsoft]" <nickmalik@hotmail.nospam.com> schrieb: I think this strongly depends on what type of application you are > In most cases, an object composed of static methods (Module in VB > parlance) is an very strong indicator of very weak design. 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/> Hi Herfried,
"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message A fair statement. I realize that my characterization was over-reaching. news:e654LCeQFHA.3336@TK2MSFTNGP10.phx.gbl... > Nick, > > "Nick Malik [Microsoft]" <nickmalik@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: When I re-read it, I want to rewrite it. > Reusable libraries, large applications/systems, or small tools which help Also a fair statement. On the other hand, I wouldn't normally perform a > you to get your job done. For the latter design has a very low prioritiy > because code won't be reused and rarely extended. code review on a "one-off tool" :-) > /Designing/ such a small tool won't be worth the effort and modules are a I find that I cannot disagree with a single statement you made.> great accelerator when developing such applications. 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 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 Hello Cor,
> We don't agree < May I ask who else you are speaking for?>When a theoretical question is placed. Than the answer has to be I respond with all due respect, Cor. However, I find that I disagree.>theoretical. As you probably know, I've been posting responses on Usenet groups for about the last decade. I do this because I want to help people. I believe we share this motivation. I've had my share of online arguments, but I don't find them valuable anymore. These days, my approach to these boards is simple: "Humbly share, then inform, and finally encourage." My philosophy doesn't include the rule of "theory has to be answered with theory." > That you with a relative unimportant program (there are more reasons) will I'm not sure I understood you. Here's is what I think you are stating. > 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. Please correct me. You feel that I would try a good theoretical approach and fail. Upon this failure, I would recommend a simple solution. You are saying that I would benefit from skipping that first step. Did I understand you correctly? I did not intend to imply that I would take a theoretical approach and fail! My friend, I can make a good OO program out of *any*simple but useful application. (A completely trivial application would look the same as either an OO or a Structured Programming app, so it would be hard to tell the difference. It would still be a good OO program.) Other folks may not be as comfortable with the OO approach as I am. For those individuals, my rules would not be helpful. 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. 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. On that basis, I will emphatically reject code that uses classes composed entirely of static methods or VB.Net modules unless they meet the criteria I explained in an earlier post because this violates the standards of my team. Everyone knows the standards before they write the code. This is not theoretical. This is entirely practical. > In addition, when you review an application than it is a program that has I beleve that we are saying the same thing, and that I made this point in my > to be checked on good theoretical implementation, when that is not > important you would not review it. earlier post. I do not review every snippet of code on a project, especially code written as a small tool, or something that is not fundamentally important to the delivery of the application. I have better things to do, as so do the smart and talented individuals I have the good fortune to work with. I am surrounded by intelligent people. I am very very lucky. While my original statement was more visceral than it should have been, I stand by my practice of _avoiding_ "global functions" in every application that I write and challenging it in every application that I am fortunate enough to inspect. -- --- 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. -- Nick,
> Maybe wrong. However, when I write that I disagree with the one I write too, >> We don't agree < >> May I ask who else you are speaking for? > > 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 I hope not and that comes back in the end of your last message. I wrote my >>theoretical. > > I respond with all due respect, Cor. However, I find that I disagree. > 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. :-)) Cordoh
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. :-) CorNick,
"Nick Malik [Microsoft]" <nickmalik@hotmail.nospam.com> schrieb: I don't disagree with what you are saying. The intention of my post was to > 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. 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 You are working in a development company, I think :-). However, there are > enforce the coding standards of my team. 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/> Herfried,
> I don't disagree with what you are saying. The intention of my post was That we (you and me) agree about 100%. Nice text.> 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. > Cor 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 Cor,
"Cor Ligthert" <notmyfirstn***@planet.nl> schrieb: That's why I put a ":-)" next to the "I think" ;-))).> 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. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> VB3 must have been difficult for you then!
Show quoteHide quote "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:OhCqHdcQFHA.3544@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 > > > > >
sql Server not found
What does this mean? (nested abstracts...) What happens to debugger here? Writing a little app to modify a file Existsing of File 2d array question... forecolor of button ??? Installing VS.NET 2005 Beta 1 shell command in windows service doesn't execute Checking the window state of a running process. |
|||||||||||||||||||||||