"virtual public" vs "public virtual"

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

    "virtual public" vs "public virtual"

    Syntax seems to say "modifiers is modifiers" and either is valid, but
    Google searches seem to show that "public virtual" is more common.

    Is there any sort of (semi) official convention?

    --

    programmer, author http://www.midnightbeach.com
    and father http://www.midnightbeach.com/hs
  • fbhcah

    #2
    RE: "virtua l public" vs "public virtual"

    The generally followed convention is:

    <access specifier><over ride/virtual/abstract...><re turn-type><Method name> (<params>)

    This convention is what I had seen almost always which may be considered as official :). But nevertheless, some ppl (though very rare) do use the other one too.

    Regards,
    fbhcah

    Comment

    • Andreas Huber

      #3
      Re: &quot;virtua l public&quot; vs &quot;public virtual&quot;

      Jon Shemitz wrote:[color=blue]
      > Syntax seems to say "modifiers is modifiers" and either is valid, but
      > Google searches seem to show that "public virtual" is more common.
      >
      > Is there any sort of (semi) official convention?[/color]

      I guess there isn't. However, many C#ers are coming from C++ where you had
      to split the interface into public, protected and private *sections*:

      class X
      {
      public:
      void F();
      void Y();
      protected:
      void Z();
      private:
      int x;
      };

      So having the access specifier first is more natural, to people coming from
      C++, that is...

      Regards,

      Andreas

      P.S. I'm unsure whether Java has any restrictions here...

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: &quot;virtua l public&quot; vs &quot;public virtual&quot;

        Andreas Huber <ah2003@gmx.net > wrote:[color=blue]
        > P.S. I'm unsure whether Java has any restrictions here...[/color]

        Nope. So long as the return type is immediately before the method name,
        the rest is fine.

        The conventions are the same though.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Michael S

          #5
          Re: &quot;virtua l public&quot; vs &quot;public virtual&quot;


          "Andreas Huber" <ah2003@gmx.net > wrote in message
          news:403b0738$1 _2@news.bluewin .ch...[color=blue]
          > Jon Shemitz wrote:
          > So having the access specifier first is more natural, to people coming[/color]
          from[color=blue]
          > C++, that is...
          >
          > Regards,
          >
          > Andreas
          >
          > P.S. I'm unsure whether Java has any restrictions here...[/color]

          Java does not have any such restrictions (except virtual is not a keyword as
          everything is virtual in Java).

          However, as Java, Delphi, Visual Basic and just about every language there
          is have as convention of specifying scope before modifiers and I would hate
          to see 'virtual public' being used. For me, it simply looks wrong.

          Programmers looking for modifiers will scan the second word first, why
          confuse them. =)

          - Michael S



          Comment

          Working...