The use of modules (or not)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Morten Snedker

    #1

    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
  • Larry Lard

    #2
    Re: The use of modules (or not)


    Morten Snedker wrote:[color=blue]
    > 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?[/color]

    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?GlobalVari ablesAreBad> 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

    Comment

    • Cor Ligthert

      #3
      Re: The use of modules (or not)

      Morten,
      [color=blue]
      >
      > 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?
      >[/color]
      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
      memorymanagemen t, 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(myda tagrid.datasour ce,DataSet)

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

      I hope that this gives some ideas

      Cor


      Comment

      • Robin Tucker

        #4
        Re: The use of modules (or not)

        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_spammen ot_ATdbconsult. dk> wrote in message
        news:1epfb1p43l 68b73h5saohti3c 2208pqhc4@4ax.c om...[color=blue]
        > 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[/color]


        Comment

        • Chad Z. Hower aka Kudzu

          #5
          Re: The use of modules (or not)

          "Robin Tucker" <idontwanttobes pammedanymore@r eallyidont.com> wrote in
          news:d9900l$k7f $1$8300dec7@new s.demon.co.uk:[color=blue]
          > 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[/color]

          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/
          "Programmin g is an art form that fights back"

          Empower ASP.NET with IntraWeb

          Comment

          • David Anton

            #6
            RE: The use of modules (or not)

            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
            Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

            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:
            [color=blue]
            > 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
            >[/color]

            Comment

            • Robin Tucker

              #7
              Re: The use of modules (or not)

              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" <cpub@hower.org > wrote in message
              news:Xns967CAA6 545B96cpubhower org@127.0.0.1.. .[color=blue]
              > "Robin Tucker" <idontwanttobes pammedanymore@r eallyidont.com> wrote in
              > news:d9900l$k7f $1$8300dec7@new s.demon.co.uk:[color=green]
              >> 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[/color]
              >
              > 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/
              > "Programmin g is an art form that fights back"
              >
              > Empower ASP.NET with IntraWeb
              > http://www.atozed.com/IntraWeb/[/color]


              Comment

              • Herfried K. Wagner [MVP]

                #8
                Re: The use of modules (or not)

                "Morten Snedker" <morten_spammen ot_ATdbconsult. dk> schrieb:[color=blue]
                > I've read that modules in .Net are mainly for backwards compability.
                > Is this true?[/color]


                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/>

                Comment

                • Herfried K. Wagner [MVP]

                  #9
                  Re: The use of modules (or not)

                  "Morten Snedker" <morten_spammen ot_ATdbconsult. dk> schrieb:[color=blue]
                  > I've read that modules in .Net are mainly for backwards compability.
                  > Is this true?[/color]


                  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/>

                  Comment

                  • m.posseth

                    #10
                    Re: The use of modules (or not)

                    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]" <hirf-spam-me-here@gmx.at> wrote in message
                    news:OIao3kndFH A.3932@TK2MSFTN GP12.phx.gbl...[color=blue]
                    > "Morten Snedker" <morten_spammen ot_ATdbconsult. dk> schrieb:[color=green]
                    >> I've read that modules in .Net are mainly for backwards compability.
                    >> Is this true?[/color]
                    >
                    >
                    > 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/>[/color]


                    Comment

                    • Herfried K. Wagner [MVP]

                      #11
                      Re: The use of modules (or not)

                      "m.posseth" <michelp@nohaus ystems.nl> schrieb:[color=blue]
                      > 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 ?? :-)[/color]

                      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/>

                      Comment

                      • m.posseth

                        #12
                        Re: The use of modules (or not)

                        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]" <hirf-spam-me-here@gmx.at> wrote in message
                        news:OIao3kndFH A.3932@TK2MSFTN GP12.phx.gbl...[color=blue]
                        > "Morten Snedker" <morten_spammen ot_ATdbconsult. dk> schrieb:[color=green]
                        >> I've read that modules in .Net are mainly for backwards compability.
                        >> Is this true?[/color]
                        >
                        >
                        > 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/>[/color]


                        Comment

                        • Herfried K. Wagner [MVP]

                          #13
                          Re: The use of modules (or not)

                          "m.posseth" <michelp@nohaus ystems.nl> schrieb:[color=blue]
                          > 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 ?? :-)[/color]

                          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/>

                          Comment

                          Working...