开发者

Acceptable naming conventions for .NET applications [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect a开发者_Go百科nswers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

I am an old school programmer with a rich background in C and C++. I was never one for Microsoft, I used to use Turbo C and Borland C++.

I always used descriptive variables names, often fairly long names, and Hungarian notation.

I have forced myself to get away from Hungarian notation, but still have little remnants lingering in my naming. Please tell me if the following would be considered good naming.

    // Variables
    bool fResult;           // Boolen used for return value
    String strLastName;     // A persons last name 
    List<String> listNames; // A list of names
    int nIndex;             // An index

I notice Microsoft likes really generic names, like e and obj. This just doesn't feel right to me.

Also, for class variables I have adopted the underscore prefix for the name, _strLastName, for example.


The majority of c# code I see generally follows these conventions:

member variable:

private string _firstName;

property:

public string FirstName {get;set;}

function and method argument:

public string WelcomeMessage(string firstName)

class:

public class Repository

interface:

public interface IRespository

local variable in a function:

var firstName = "Jahova";

However as pointed out above - it doesn't matter too much - as long as everyone agrees and you don't end up with 10 different styles in 1 code base...

Also, for what it's worth, MS guidance on use of Hungarian notation:

Do not use Hungarian notation.

http://msdn.microsoft.com/en-us/library/ms229045.aspx


To be honest, coding conventions are unique to each person, team, or organization. So, if you're working alone, then just find something you're comfortable with and stick with it.

If you're working in a team, then you and the other members of your team should agree on the coding conventions that you use.

If you work in a larger organization, then chances are that there are coding conventions that will be imposed upon you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜