Advertisement
Guest User

02.Именуване на идентификатори в кода

a guest
Jan 7th, 2016
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. Именуване на идентификатори в кода
  2. Always use English for naming identifiers
  3. Трябва да избягваме съкращаването на наименуванията
  4.  
  5. Трябва да пишем имената на променливите достатъчно описателно, дори и да са сравнително дълги
  6. Wrong: dtbgRegExPtrn
  7. Correct: dateTimeBulgarianRegExPattern
  8.  
  9. Дали даден идентификатор е достатъчно показен за това какво прави конкретната променлива, клас и т.н. се определя от контекста, в който се намира променливата, класа и т.н. Т.е. :
  10. Correct:
  11. Generate() in the class LabyrinthGenerator
  12. Find(string fileName) in the class FileFinder
  13. Wrong:
  14. Generate() in the class Program
  15. Find(string name) in the class Program
  16.  
  17. Types in C# (classes, enumerations, interfaces):
  18. Correct: RecursiveFactorialCalculator, IEnumerable, Color, XmlDocument
  19. Wrong: recursiveFactorialCalculator, RECURSIVE_FACTORIAL_CALCULATOR
  20. Use the following format:
  21. - [Noun]
  22. - [Adjective] + [Noun]
  23. Examples:
  24. Student, FileSystem, CheckBox, Constants
  25. Correct: class called ReportGenerator
  26. Wrong: class called GenerateReport
  27.  
  28. If there are a lot of constants (10 or more) they should be placed in a separate class
  29.  
  30. Interfaces (In C#):
  31. - I + [Verb] + ‘able’
  32. - I + [Noun]
  33. - I + [Adjective] + [Noun]
  34. Examples:
  35. IEnumerable, IList, ICommandExecutor
  36.  
  37. Enums:
  38. In C#:
  39. enum Color { Red, Blue, White }
  40.  
  41. In JavaScript:
  42. enum Color { RED, BLUE, WHITE }
  43.  
  44. Special classes:
  45. Attribiutes:
  46. Wrong: WebService
  47. Correct: WebServiceAttribute
  48.  
  49. Collection classes:
  50. Wrong: ListOfStrings, Strings
  51. Correct: StringsCollection
  52.  
  53. Delegate classes:
  54. Example: DownloadFineshedDelegate
  55.  
  56. Namespaces:
  57. Correct: Microsoft.WinControls.GridView
  58. Wrong: Microsoft_WinControlsGridView
  59.  
  60. Naming files in JavaScript:
  61. - There are “-“ between different words
  62. Correct: jquery-1.8.2.min.js, widgets.js
  63. Wrong: jQuery_classes.js, Widgets.js, MyAjax.Library.js
  64.  
  65. Types’ names can be as long as we decide
  66.  
  67. When we have to name a group of things:
  68. Correct: accounts, customers
  69. Wrong: accountsList, customersList
  70.  
  71. Method names should consist of:
  72. - [Verb]
  73. - [Verb] + [Noun]
  74. - [Verb] + [Adjective] + [Noun]
  75.  
  76. Boolean variables should be postive:
  77. Correct: isPrime, customerFound, hasPendingPayment
  78.  
  79. At the end of counter variables there should be “Count”
  80. Examples: ticketsCount, customersCount
  81.  
  82. State – there should be “State” at the end of the variable
  83.  
  84. Naming temporary variables:
  85. Correct: oldValue
  86. Wrong: temp
  87.  
  88. Naming constants:
  89. In C# - in PascalCase
  90. In JavaScript – in UPPER_CASE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement