Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News Debate: Public Fields and Naming Conventions

Debate: Public Fields and Naming Conventions

Jeff Atwood's blog post earlier this week has stirred up debate in the .NET community on properties vs. public fields and naming conventions for .NET.  After first suggesting to use public variables in place of properties, Jeff retracted this suggestion since changing a public variable to a property at a later time is an interface-breaking change in .NET.  Databinding to public fields is not possible, though properties can be databound.  It was also pointed out that in other languages such as Python, converting a field to a property is not a breaking change.  Still other languages schew public fields entirely, allowing only properties, often with a simpler syntax.  The following was proposed for .NET properties without get and set logic:

public property string Name;

Also debated was the use of case (C# only) to distinguish properties from their corresponding private variables.  The Microsoft Internal Coding Guidelines suggest:

  • Do not use Hungarian notation
  • Do not use a prefix for member variables (_, m_, s_, etc.). If you want to distinguish between local and member variables you should use “this.” in C# and “Me.” in VB.NET.
  • Do use camelCasing for member variables
  • Do use camelCasing for parameters
  • Do use camelCasing for local variables
  • Do use PascalCasing for function, property, event, and class names
  • Do prefix interfaces names with “I”
  • Do not prefix enums, classes, or delegates with any letter
Jeff Atwood suggests that it "is borderline irresponsible programming" to distinguish between variables by case only.  Plus, that is not an option for VB.NET developers.

Finally, constants declared in SCREAMING_CAPS were renounced, though many posters noted that they find that constants created in this style stand out easily from variables that can be modified.  The Microsoft guidelines do not specifically weigh in on the issue of constant declarations, but examples in the .NET framework include constants declared with Pascal casing.

Rate this Article