Interface and overloaded functions in visual studio.NET

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

    Interface and overloaded functions in visual studio.NET

    If i have this Interface:

    Public Interface MyInterface
    Function test() As Boolean
    Function test(ByVal MyVar As String) As Boolean
    End Interface

    And then i make a

    Public Class MyOwnClass
    Implements MyInterface
    End Class

    When i hit [Enter] after the Implements MyInterface
    Visual Studio automatically creates

    Public Overloads Function test() As Boolean Implements MyInterface.tes t
    End Function

    Public Overloads Function test1(ByVal MyVar As String) As Boolean
    Implements MyInterface.tes t
    End Function

    These two functions for me...

    Why does it add the 1 on the overloaded function-name?
    Why doesn't it just make a test() and a test(ByVal Myvar As string)
    function?
    Is there a specific reason for this behaviour?


  • Armin Zingler

    #2
    Re: Interface and overloaded functions in visual studio.NET

    "sotto" <junk@sotto.inv alid> schrieb[color=blue]
    > If i have this Interface:
    >
    > Public Interface MyInterface
    > Function test() As Boolean
    > Function test(ByVal MyVar As String) As Boolean
    > End Interface
    >
    > And then i make a
    >
    > Public Class MyOwnClass
    > Implements MyInterface
    > End Class
    >
    > When i hit [Enter] after the Implements MyInterface
    > Visual Studio automatically creates
    >
    > Public Overloads Function test() As Boolean Implements
    > MyInterface.tes t End Function
    >
    > Public Overloads Function test1(ByVal MyVar As String) As Boolean
    > Implements MyInterface.tes t
    > End Function
    >
    > These two functions for me...
    >
    > Why does it add the 1 on the overloaded function-name?
    > Why doesn't it just make a test() and a test(ByVal Myvar As string)
    > function?
    > Is there a specific reason for this behaviour?[/color]

    If you've already got a procedure with the name "test", the IDE uses this
    kind of numbering. In this case, it wouldn't be necessary, so you're right.
    I'd post it again in microsoft.publi c.vsnet.ide.


    --
    Armin




    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Interface and overloaded functions in visual studio.NET

      * sotto <junk@sotto.inv alid> scripsit:[color=blue]
      > If i have this Interface:
      >
      > Public Interface MyInterface
      > Function test() As Boolean
      > Function test(ByVal MyVar As String) As Boolean
      > End Interface
      >
      > And then i make a
      >
      > Public Class MyOwnClass
      > Implements MyInterface
      > End Class
      >
      > When i hit [Enter] after the Implements MyInterface
      > Visual Studio automatically creates
      >
      > Public Overloads Function test() As Boolean Implements MyInterface.tes t
      > End Function
      >
      > Public Overloads Function test1(ByVal MyVar As String) As Boolean
      > Implements MyInterface.tes t
      >
      > End Function
      >
      > These two functions for me...
      >
      > Why does it add the 1 on the overloaded function-name?
      > Why doesn't it just make a test() and a test(ByVal Myvar As string)
      > function?
      >
      > Is there a specific reason for this behaviour?[/color]

      I currently don't have VS.NET 2003 here, but if it names it with an "1"
      at the end of the name it is maybe a bug.

      --
      Herfried K. Wagner [MVP]
      <http://www.mvps.org/dotnet>

      Comment

      • Trev Hunter

        #4
        Re: Interface and overloaded functions in visual studio.NET

        > I currently don't have VS.NET 2003 here, but if it[color=blue]
        > names it with an "1" at the end of the name it is maybe a bug.[/color]

        I use VS2003 and it does name overloaded interface methods with an number
        suffix.

        e.g.

        Test()
        Test1()
        Test2()

        etc.

        Trev.


        "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
        news:ezXrb1o3DH A.484@TK2MSFTNG P10.phx.gbl...[color=blue]
        > * sotto <junk@sotto.inv alid> scripsit:[color=green]
        > > If i have this Interface:
        > >
        > > Public Interface MyInterface
        > > Function test() As Boolean
        > > Function test(ByVal MyVar As String) As Boolean
        > > End Interface
        > >
        > > And then i make a
        > >
        > > Public Class MyOwnClass
        > > Implements MyInterface
        > > End Class
        > >
        > > When i hit [Enter] after the Implements MyInterface
        > > Visual Studio automatically creates
        > >
        > > Public Overloads Function test() As Boolean Implements MyInterface.tes t
        > > End Function
        > >
        > > Public Overloads Function test1(ByVal MyVar As String) As Boolean
        > > Implements MyInterface.tes t
        > >
        > > End Function
        > >
        > > These two functions for me...
        > >
        > > Why does it add the 1 on the overloaded function-name?
        > > Why doesn't it just make a test() and a test(ByVal Myvar As string)
        > > function?
        > >
        > > Is there a specific reason for this behaviour?[/color]
        >
        > I currently don't have VS.NET 2003 here, but if it names it with an "1"
        > at the end of the name it is maybe a bug.
        >
        > --
        > Herfried K. Wagner [MVP]
        > <http://www.mvps.org/dotnet>[/color]


        Comment

        • Philip Rieck

          #5
          Re: Interface and overloaded functions in visual studio.NET

          VS.net uses "proc", "proc1", "proc2" .... type naming when generating
          function names for you. If it generates "proc", but that name already
          exists, then it will try "proc1". If that exists, it will try "proc2", and
          so on...

          While the generator COULD use method overloads, overloading a method only
          makes sense if the functions are closely related. VS.NET really doesn't
          know if they're related or not, so it names them uniquely. This naming is
          applied in all cases, even when using the same name isn't an issue.


          "sotto" <junk@sotto.inv alid> wrote in message
          news:G9OOb.2937 $4Z3.61342813@h estia.telenet-ops.be...[color=blue]
          > If i have this Interface:
          >
          > Public Interface MyInterface
          > Function test() As Boolean
          > Function test(ByVal MyVar As String) As Boolean
          > End Interface
          >
          > And then i make a
          >
          > Public Class MyOwnClass
          > Implements MyInterface
          > End Class
          >
          > When i hit [Enter] after the Implements MyInterface
          > Visual Studio automatically creates
          >
          > Public Overloads Function test() As Boolean Implements MyInterface.tes t
          > End Function
          >
          > Public Overloads Function test1(ByVal MyVar As String) As Boolean
          > Implements MyInterface.tes t
          > End Function
          >
          > These two functions for me...
          >
          > Why does it add the 1 on the overloaded function-name?
          > Why doesn't it just make a test() and a test(ByVal Myvar As string)
          > function?
          > Is there a specific reason for this behaviour?
          >
          >[/color]


          Comment

          • Jay B. Harlow [MVP - Outlook]

            #6
            Re: Interface and overloaded functions in visual studio.NET

            Herfried,
            As Trev stated, it "numbers" the members when they are overloaded, I suspect
            for the reason Armin cited.

            The numbering partially makes senses when the class had a Test function with
            a different return type before I added the interface! I'm sure numbering is
            the "easy way" to implement it. ;-)

            However! more oft then not, I do not want the methods numbered, I either
            want implicitly or explicit interface implementation (to borrow the C#
            term).

            ' implicit interface implementation[color=blue][color=green]
            > > Public Function test() As Boolean Implements MyInterface.tes t
            > > End Function
            > >
            > > Public Function test(ByVal MyVar As String) As Boolean
            > > Implements MyInterface.tes t[/color][/color]


            Public Function test() As String
            End Function

            ' explicit interface implementation[color=blue][color=green]
            > > Private Function MyInterface_tes t() As Boolean Implements[/color][/color]
            MyInterface.tes t[color=blue][color=green]
            > > End Function
            > >
            > > Private Function MyInterface_tes t(ByVal MyVar As String) As Boolean
            > > Implements MyInterface.tes t[/color][/color]

            Also in this context the Overloads normally is not needed, I'm suspect its
            injected incase I am implementing the interface in a class that already has
            a Test method inherited from a base class.

            Just a thought
            Jay

            "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
            news:ezXrb1o3DH A.484@TK2MSFTNG P10.phx.gbl...[color=blue]
            > * sotto <junk@sotto.inv alid> scripsit:[color=green]
            > > If i have this Interface:
            > >
            > > Public Interface MyInterface
            > > Function test() As Boolean
            > > Function test(ByVal MyVar As String) As Boolean
            > > End Interface
            > >
            > > And then i make a
            > >
            > > Public Class MyOwnClass
            > > Implements MyInterface
            > > End Class
            > >
            > > When i hit [Enter] after the Implements MyInterface
            > > Visual Studio automatically creates
            > >
            > > Public Overloads Function test() As Boolean Implements MyInterface.tes t
            > > End Function
            > >
            > > Public Overloads Function test1(ByVal MyVar As String) As Boolean
            > > Implements MyInterface.tes t
            > >
            > > End Function
            > >
            > > These two functions for me...
            > >
            > > Why does it add the 1 on the overloaded function-name?
            > > Why doesn't it just make a test() and a test(ByVal Myvar As string)
            > > function?
            > >
            > > Is there a specific reason for this behaviour?[/color]
            >
            > I currently don't have VS.NET 2003 here, but if it names it with an "1"
            > at the end of the name it is maybe a bug.
            >
            > --
            > Herfried K. Wagner [MVP]
            > <http://www.mvps.org/dotnet>[/color]


            Comment

            • Herfried K. Wagner [MVP]

              #7
              Re: Interface and overloaded functions in visual studio.NET

              * "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> scripsit:[color=blue]
              > The numbering partially makes senses when the class had a Test function with
              > a different return type before I added the interface! I'm sure numbering is
              > the "easy way" to implement it. ;-)[/color]

              Seems to be a "quick and dirty" solution...

              ;-)
              [color=blue]
              > However! more oft then not, I do not want the methods numbered, I either
              > want implicitly or explicit interface implementation (to borrow the C#
              > term).[/color]

              I don't like numbered methods too.

              --
              Herfried K. Wagner [MVP]
              <http://www.mvps.org/dotnet>

              Comment

              • Jay B. Harlow [MVP - Outlook]

                #8
                Re: Interface and overloaded functions in visual studio.NET

                Herfried,
                Aren't "easy way" and "quick and dirty" synonyms?

                :-))

                Jay

                "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                news:buhnqa$hv1 il$1@ID-208219.news.uni-berlin.de...[color=blue]
                > * "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> scripsit:[color=green]
                > > The numbering partially makes senses when the class had a Test function[/color][/color]
                with[color=blue][color=green]
                > > a different return type before I added the interface! I'm sure numbering[/color][/color]
                is[color=blue][color=green]
                > > the "easy way" to implement it. ;-)[/color]
                >
                > Seems to be a "quick and dirty" solution...
                >
                > ;-)
                >[color=green]
                > > However! more oft then not, I do not want the methods numbered, I either
                > > want implicitly or explicit interface implementation (to borrow the C#
                > > term).[/color]
                >
                > I don't like numbered methods too.
                >
                > --
                > Herfried K. Wagner [MVP]
                > <http://www.mvps.org/dotnet>[/color]


                Comment

                • Cor

                  #9
                  Re: Interface and overloaded functions in visual studio.NET

                  Hi Jay B,

                  I hope you don't mind I answer also?
                  [color=blue]
                  > Aren't "easy way" and "quick and dirty" synonyms?[/color]

                  I think not, they are opposites in my eyes.

                  Keep it simple is not only a term I often use.

                  If you cannot "Keep it simple", the "quick and dirty" way is mostly the bad
                  solution.
                  (About that we do not have to argue).

                  Just a thought,

                  Cor


                  Comment

                  • Trev Hunter

                    #10
                    Re: Interface and overloaded functions in visual studio.NET

                    > Aren't "easy way" and "quick and dirty" synonyms?

                    "easy way", "quick and dirty" and "quick and beautiful" are in the eyes of
                    the beholder ;)


                    Comment

                    • Jay B. Harlow [MVP - Outlook]

                      #11
                      Re: Interface and overloaded functions in visual studio.NET

                      Cor,
                      What's that saying about if you have to explain a joke? :-|


                      Joking aside: I hope you realize that "easy way" is not necessary "keep it
                      simple", in the context I was using it "easy way" is the path of least
                      resistance, the quick way for the Microsoft employee. The "quick & ..."
                      way... At least from my perspective & understanding of compilers.

                      Also "keep it simple" for who the Microsoft employee or for the target
                      audience the non-Microsoft developer who uses VB.NET?

                      As Trev stated its in the "eye of the beholder", and I'm adding its a matter
                      of perspective. Either Microsoft the developer of the language or Us the
                      consumer of the language...

                      Think about, in some cases, how much effort you need to code, to get
                      something "real simple" for the user of your program. Or when you take the
                      easy programming route, how much work more work the user of your program
                      has.

                      Note I am not disagreeing you with, I am just trying to point out the
                      perspective I used in the statement.

                      Just a thought
                      Jay


                      "Cor" <non@non.com> wrote in message
                      news:%23fPpb7y3 DHA.1096@TK2MSF TNGP11.phx.gbl. ..[color=blue]
                      > Hi Jay B,
                      >
                      > I hope you don't mind I answer also?
                      >[color=green]
                      > > Aren't "easy way" and "quick and dirty" synonyms?[/color]
                      >
                      > I think not, they are opposites in my eyes.
                      >
                      > Keep it simple is not only a term I often use.
                      >
                      > If you cannot "Keep it simple", the "quick and dirty" way is mostly the[/color]
                      bad[color=blue]
                      > solution.
                      > (About that we do not have to argue).
                      >
                      > Just a thought,
                      >
                      > Cor
                      >
                      >[/color]


                      Comment

                      • Cor

                        #12
                        Re: Interface and overloaded functions in visual studio.NET

                        Hi Jay,

                        You know we agree, but I have seen to much solutions on the difficult way,
                        which did not add anything to what you are saying (and as you know I agree).

                        I thought, we both think the same in this matters, but I brought it in to
                        tell that the "difficult" way is not always the best solution.

                        Quick and dirty is in my opinion only allowed as a patch when there is
                        really nothing else, mostly it never changes and gives you trouble on then
                        next version of the OS or the compiler.

                        (Was a discussion also in this newsgroup when somebody said, never fix it if
                        is not broken, that I also not agreed, you have to do maintanance if the
                        economic cost of something has reached the break even point)

                        That is what I think about it.

                        To recapitulate the difficult way is not always the best way, quick and
                        dirty is always the worse way.

                        If you do not disagree, and I think so, no need to answer.

                        Cor


                        Comment

                        Working...