"virtual public" vs "public virtual"

  • Thread starter Thread starter Jon Shemitz
  • Start date Start date
J

Jon Shemitz

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?
 
The generally followed convention is:

<access specifier><override/virtual/abstract...><return-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
 
Jon said:
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?

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...
 
Andreas Huber said:
P.S. I'm unsure whether Java has any restrictions here...

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

The conventions are the same though.
 
Andreas Huber said:
Jon Shemitz wrote:
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...

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
 
Back
Top