Guest User

03.Форматиране на кода

a guest
Jan 7th, 2016
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. Форматиране на кода
  2. В C# при конструкции като if клаузата, след самата дума if има празно място и отварящата скоба е точно под първата буква на конструкцията. След отварящата скоба задължително има някакъв символ, т.е. няма празен ред или празно място)
  3. if (some condition)
  4. {
  5. …
  6. }
  7.  
  8. for (int k = 0; k < 10; k++)
  9. {
  10. …
  11. }
  12.  
  13. In Java, JavaScript
  14. if (some condition) {
  15. …
  16. }
  17.  
  18. there is exactly one empty line after method declaration
  19.  
  20. there is exactly one blank space when we make a comment:
  21. // some comment
  22.  
  23.  
  24. Always use curly brackets (for if-clauses, for loops, etc.)
  25.  
  26. When we write methods they look like:
  27. In C#:
  28. There is no blank space between the name of the method and the opening bracket
  29. private static uint CalcFactorial(uint num,_int someNumber)
  30. {
  31. …
  32. }
  33.  
  34. In JavaScript:
  35. function nameOfTheFunction(someVariable)_{
  36. …
  37. }
  38.  
  39. When we call methods:
  40. In C#:
  41. RegisterUser(“nakov”, “password”);
  42. - there is no blank space between the name of the method and the opening bracket
  43.  
  44. in JavaScript:
  45. someFunction(“nakov”, “password”);
  46.  
  47.  
  48. Use an empty line to separate logically related sequences of lines of code.
  49.  
  50.  
  51. Order of definitions in classes, interfaces, structures:
  52. 1.constants
  53. 2.delegates
  54. 3.inner types (enums, inner classes)
  55. 4.fields
  56. 5.constructors
  57. 6.properties
  58. 7.methods
  59.  
  60. static members
  61. none static members:
  62. public members
  63. protected members
  64. internal members(available to be used only in the current project)
  65. private members
  66.  
  67. public class Dog
  68. {
  69. // Constants(static members)
  70. public const string Species = “Canis Lupus Familiaris”;
  71.  
  72. // Instance variables
  73. private int age;
  74.  
  75. // Constructors
  76. public Dog(string name, int age)
  77. {
  78. this.Name = name;
  79. this.age = age;
  80. }
  81.  
  82. // Properties
  83. public string Name { get; set; }
  84.  
  85. // Methods
  86. public void Breathe()
  87. {
  88. }
  89. }
  90.  
  91.  
  92. After the body of a construction(if-clause, for loop, etc.) there should be an empty line
  93.  
  94.  
  95. If-clauses:
  96. In C#:
  97. if (matrix[x, y] == 0 ||
  98. matrix[x – 1, y] == 0||
  99. matrix[x – 1, y - 1] == 0||
  100. matrix[x – 1, y] == 0)
  101. {
  102. …
  103. }
  104.  
  105. In JavaScript(double tab):
  106. if (matrix[x, y] == 0 ||
  107. matrix[x – 1, y] == 0||
  108. matrix[x – 1, y - 1] == 0||
  109. matrix[x – 1, y] == 0) {
  110. …
  111. }
Advertisement
Add Comment
Please, Sign In to add comment