代码改变世界

Use proper Naming Conventions

  杨延成  阅读(439)  评论(0编辑  收藏  举报
You should prefer proper naming conventions for consistency of your code. It is very easy to maintain the code if used consistent naming all over the solution. Here are some naming conventions which generally followed by .Net developers:

* Always use Camel case (A word with the first letter lowercase, and the first letter of each subsequent word-part capitalized) while declaring variables.
* Use Pascal (A word with the first letter capitalized, and the first letter of each subsequent word-part capitalized) naming format while declaring Properties.
* Avoid all uppercase or lowercase names for properties, variables or method names. Use all uppercase when declaring const variables.
* Never use a name begins with numeric character.
* Always prefer meaningful name for your class, property, method etc. This will be very useful for you to maintain the code in future. For example, “P” will not give proper meaning for a class. You will find it difficult to know about the class. But if you use “Person”, you will easily understand by it.
* Never build different name varied by capitalization. It is a very bad practice. It will not be useful while developing code, as you will not know what is “person” class and what is “Person” class!!! But from the above scenario, it can be very easily understandable that “person” is an instance variable of “Person” class.
* Don’t use the same name used in .Net Framework. People who are new to your code have a very difficulty to understand it easily.
* Avoid adding prefixes or suffixes for your identifiers. Though in some guidelines they use “m_” and in some other they use “_” as the prefix of variable declaration. I think it is not that much useful. But, it depends on your organizational coding practices. This point is contradictory based on various organization and there is no strict guidance on it.
* Always use “I” as prefix for Interfaces. This is a common practice for declaring interfaces.
* Always add “Exception” as suffix for your custom exception class. It will give better visibility to your exception class.
* Never prefix or suffix the class name to it’s property names. It will unnecessary increase the property name. If “Firstname” is a property of “Person” class, you can easily identify it from that class directly. No need to write “PersonFirstname” or “FirstnameOfPerson”.
* Prefix “Is”, “Has” or “Can” for boolean properties like “IsVisible”, “HasChildren”, “CanExecute”. These gives proper meaning to the properties.
* Don’t add prefix for your controls, instead write proper name to identify the control.
编辑推荐:
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· [AI/GPT/综述] AI Agent的设计模式综述
历史上的今天:
2010-03-05 实现静态页面累加访问量的三种方式(3)
2010-03-05 实现静态页面累加访问量的三种方式(2)
点击右上角即可分享
微信分享提示