Question

What are the naming conventions that you use while coding?

Was it helpful?

Solution

I hope we will not discuss prefixes for field names and brace styles here :)

Here is my bible for .NET:

alt text

Also MSDN gives solid guidelines.

Another useful source is MS Internal Coding Guidelines

OTHER TIPS

Here's a list of general naming conventions from MSDN.

I tend to just go-with-the-flow, however. Whatever standards are currently in place, it's usually easiest to just go with them and maybe slowly shift it over time. It's not really practical to just come into a project with your own idea of "standards" and try to implement them.

It doesn't REALLY matter what standards are used, imo -- just that there are some and people know what they are.

I use a combination of Hungarian, camel case, and other rules I come up with in the beginning of a project. Like right now:

  • Methods are upper case (DoThis)
  • variables are camel case (thisThing)
  • page level variables are prefaced with _ (_thisWorksEverywhere)
  • regions are all lower case (#region foreign properties)
  • Properties and Objects are uppercase (Object.Property)
  • Foreign properties are prefaced by _ (Object._ForeignGroups)
  • Controls are Hungarian to an extent, like (txtTextBox) and (rptRepeater). I'm not too strict as to what's customary because "Watermark" can be wm or wk or whatever, as long as they all match each other accross my application.

...etc. Some things are standard, others are up to interpretation, but the most important thing is consistency across your application.

Hungarian notation can be used. I don't bother myself, but I give various things (variables, controls, etc.) sensible names.

For example, I use a Hungarian-style prefix for control names such as txt for TextBoxes, btn for Buttons, pic for PictureBoxes, lbl for Labels, etc. That helps to easily identify what a control is.

For function names I try and use sensible explanatory names, but nothing with any particular rules. For variable names again I just use explanatory names but nothing special.

To add on to the answer from @Aku authors of the Framework Design Guidelines have published on online digest version of their guidelines, with an emphasis on naming convetions.

Framework Design Guidelines Digest v2

Download here

Consistency is key. Depending on the size of your development team, using a consistent and documented convetion will make it easier to pick up someone elses code and for others to pick up your own code.

Folks, please don't post answers like "I like __field" or "I like m__field". It's a very personal and subjective question without a single answers.

If you have any guidlines it's already a big win. Worse thing in dev team is a lack of common conventions.

It would be nice if would try to describe some benefits of given guideline.
For example:

prefixing fields with underscore can improve auto-completion with intellisense

Pick one at be consistent. Changing name styles leads to confusion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top