Sunday, February 13, 2011

Which is recommended: "static public" or "public static"

Hi,

If you have a class member that is static and public. Would you write "static public" or "public static"? I know they are the same. But is there some recommendation / best practice for writing this?

  • I personally would go with public static because it's more important that it's public than that it's static.

    And check this: http://checkstyle.sourceforge.net/config_modifier.html

    As well as this: http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html (These two links are for Java, but the concept is the same)

    Short version: "public static" is recommended and is far more common.

    From Epaga
  • "public static" is far more common, so you might want to go with that just to increase readability for programmers who never stumbled upon "static public".

  • see this question

    If you download the Microsoft StyleCop Visual Studio addin, it can validate your source code against the rules Microsoft use. It likes the access modifier to come first.

    From Mark Heath
  • When nothing else matters, go with consistency. In this case the rest of the world uses public static, so I'd go with that too just to avoid unnecessary surprise in those reading your code.

0 comments:

Post a Comment