Guest User

Untitled

a guest
Aug 14th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. # Semi colons ;
  2. Don't use them or always use them.
  3.  
  4. Example:
  5. ```
  6. # Good
  7. name = gets.chomp
  8. puts("hi #{name}")
  9.  
  10. # Also good
  11. name = gets.chomp;
  12. puts("hi #{name}");
  13.  
  14. # Bad uses sometimes but not always or never
  15. name = gets.chomp
  16. puts("hi #{name}");
  17. ```
  18.  
  19. # Variables
  20. ## Names
  21. Must be in the underscore_lowercase format.
  22.  
  23. Example:
  24. ```
  25. name = "paul"
  26. ```
  27.  
  28.  
  29. ## Operators
  30. Must have a space on both sides of the operator always.
  31.  
  32. Example:
  33. ```
  34. # Good
  35. paul_is_cool = true
  36.  
  37. # Bad
  38. paul_is_not_cool =false
  39. paul_is_not_cool=false
  40. paul_is_not_cool= false
  41.  
  42. # Good
  43. ten = 5 + 5
  44.  
  45. # Bad
  46. ten = 5+ 5
  47. ```
  48.  
  49. # functions
  50. ## Names
  51. Function names should use underscore_lowercase.
  52.  
  53. Examples:
  54. ```
  55. def return_paul
  56. return "paul"
  57. end
  58. ```
  59.  
  60. ## Parentheses (round brackets)
  61. ### Calls
  62. Use parentheses whenever there is more one or more arguments. Or always use it.
  63.  
  64. Examples:
  65. ```
  66. # Good
  67. puts("Hi my name is paul") # needed
  68. name = gets.chomp # not needed no arguments
  69.  
  70. puts("Hi my name is paul")
  71. name = gets.chomp()
  72.  
  73. # Bad
  74. # inconsistent
  75. name = get.chomp()
  76. last_name = gets.chomp
  77.  
  78. # Missing parentheses
  79. puts "Hi my name is paul"
  80.  
  81. ```
  82.  
  83. No spaces between ( and the first argument.
  84. No spaces between ) and the last argument.
  85.  
  86.  
  87. Examples:
  88. ```
  89. # Good
  90. puts("paul is so cool")
  91.  
  92. # Bad
  93. puts( "paul is not cool" )
  94. ```
  95.  
  96. ### Definitions
  97. Add parentheses if there is one or more arguments.
  98.  
  99. Example:
  100. ```
  101. def sum (a, b) # needed
  102. return a + b
  103. end
  104.  
  105. def return_paul # no brackets needed
  106. return "paul"
  107. end
  108. ```
  109.  
  110. ## Return
  111. The return keyword must always be used if a function returns a value.
  112.  
  113. Example:
  114. ```
  115. # Good
  116. def return_paul
  117. return "Paul"
  118. end
  119.  
  120. # Good becuase the function doesn't need to return anything
  121. def print_paul
  122. puts("Paul")
  123. end
  124.  
  125. # Bad
  126. # missing return
  127. def return_paul
  128. "paul"
  129. end
  130. ```
  131.  
  132. # If
  133. Don't use Parentheses or use them not both.
  134.  
  135. Example:
  136. ```
  137. # Good
  138. if name === "paul"
  139. puts("Woah you are so cool")
  140. end
  141.  
  142. if course == "BA-CS"
  143. puts("Good choice")
  144. end
  145.  
  146. # Good
  147. if (name === "paul")
  148. puts("Woah you are so cool")
  149. end
  150.  
  151. if (course == "BA-CS")
  152. puts("Good choice")
  153. end
  154.  
  155. #Bad becuase inconsistent
  156. if (name === "paul")
  157. puts("Woah you are so cool")
  158. end
  159.  
  160. if course == "BA-CS"
  161. puts("Good choice")
  162. end
  163. ```
  164.  
  165. Always have a space between if and the condition.
  166.  
  167. Example:
  168. ```
  169. # Good
  170. if (name === "paul")
  171. puts("Woah you are so cool")
  172. end
  173.  
  174. # Bad
  175. if(name === "paul")
  176. puts("Woah you are so cool")
  177. end
  178. ```
  179.  
  180. # Case
  181. Each when should be the same level of indentation as case
  182.  
  183. Example:
  184. ```
  185. # Good
  186. case name
  187. when "paul"
  188. puts("Old name");
  189. when "andrew"
  190. puts("Okay name");
  191. when "john"
  192. puts("Great name");
  193. else
  194. puts("bad name");
  195. end
  196.  
  197. # Bad
  198. case name
  199. when "paul"
  200. puts("Old name");
  201. when "andrew"
  202. puts("Okay name");
  203. when "john"
  204. puts("Great name");
  205. else
  206. puts("bad name");
  207. end
  208.  
  209. case name
  210. when "paul"
  211. puts("Old name");
  212. when "andrew"
  213. puts("Okay name");
  214. when "john"
  215. puts("Great name");
  216. else
  217. puts("bad name");
  218. end
  219.  
  220.  
  221. ```
  222.  
  223. # Loops
  224.  
  225. ## While
  226. Same condition rules as if.
  227.  
  228. Example:
  229. ```
  230. while i <= 50 do
  231. puts("value of i is #{i}");
  232. i += 1;
  233. end
  234. ```
  235.  
  236. ## For
  237.  
  238. Example:
  239. ```
  240. for i in 1..50 do
  241. puts("value of i is #{i}");
  242. end
  243. ```
  244.  
  245. # Indentation
  246. Everything between the end and what the end is ending must be indented
  247.  
  248. Examples:
  249. ```
  250. # Good
  251. def its_paul
  252. puts("REALLY?")
  253. end
  254.  
  255. def main
  256. name = "paul"
  257.  
  258. if name === "paul"
  259. its_paul
  260. end
  261. end
  262.  
  263. # BAD
  264. def its_paul
  265. puts("REALLY?")
  266. end
  267.  
  268. def main
  269. name = "paul"
  270.  
  271. if name === "paul"
  272. its_paul
  273. end
  274. end
  275.  
  276. # Also BAD
  277.  
  278. def its_paul
  279. puts("REALLY?")
  280. end
  281.  
  282. def main
  283. name = "paul"
  284.  
  285. if name === "paul"
  286. its_paul
  287. end
  288. end
  289.  
  290. # Also BAD
  291.  
  292. def its_paul
  293. puts("REALLY?")
  294. end
  295.  
  296. def main
  297. name = "paul"
  298.  
  299. if name === "paul"
  300. its_paul
  301. end
  302. end
  303.  
  304.  
  305. ```
Add Comment
Please, Sign In to add comment