Debate: Public Fields and Naming Conventions

| by Marcie Jones Follow 0 Followers on Aug 11, 2006. Estimated reading time: 1 minute |

A note to our readers: You asked so we have developed a set of features that allow you to reduce the noise: you can get email and web notifications for topics you are interested in. Learn more about our new features.

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

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread


Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you