Coding Style.rtf 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. {\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf540
  2. {\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 Monaco;}
  3. {\colortbl;\red255\green255\blue255;\red0\green134\blue2;\red195\green0\blue0;}
  4. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\qc\pardirnatural
  5. \f0\fs36 \cf0 Coding Rules\
  6. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
  7. \fs24 \cf0 \
  8. \fs28 Cocoa coding style for the naming.\
  9. \
  10. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\ql\qnatural\pardirnatural
  11. \f1\fs20 \cf0 variableNaming
  12. \f0\fs28 variable should use capitalization on all word expect the first and never '_' ie\
  13. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\ql\qnatural\pardirnatural
  14. \b\fs24 \cf2 RIGHT\
  15. \f1\b0\fs18 \cf0 BOOL isFirstTimeReading;\
  16. int age;\
  17. \f0\fs24 \
  18. \b \cf3 WRONG\
  19. \f1\b0\fs18 \cf0 BOOL is_first_time_reading;\
  20. int Age;\
  21. int isFirstTimeReading_ever;\
  22. \
  23. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\ql\qnatural\pardirnatural
  24. \f0\fs28 \cf0 Objective-C Instance variable must be prefixed with _\
  25. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\ql\qnatural\pardirnatural
  26. \b\fs24 \cf2 RIGHT\
  27. \f1\b0\fs18 \cf0 @interface Object \{\
  28. BOOL _isFirstTimeReading;\
  29. int _age;\
  30. \}\
  31. \f0\fs24 \
  32. \b \cf3 WRONG\
  33. \f1\b0\fs18 \cf0 @interface Object \{\
  34. BOOL isFirstTimeReading;\
  35. int age;\
  36. \}
  37. \f0\fs28 \
  38. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
  39. \fs24 \cf0 \
  40. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\ql\qnatural\pardirnatural
  41. \f1\fs20 \cf0 Pointer *
  42. \f0\fs28 must be preceded with a space and with no space after ie\
  43. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\ql\qnatural\pardirnatural
  44. \b\fs24 \cf2 RIGHT\
  45. \f1\b0\fs18 \cf0 void *pointer;\
  46. \f0\fs24 \
  47. \b \cf3 WRONG\
  48. \f1\b0\fs18 \cf0 void * pointer;\
  49. void* pointer;\
  50. void*pointer;\
  51. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
  52. \f0\fs24 \cf0 \
  53. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\ql\qnatural\pardirnatural
  54. \f1\fs20 \cf0 if
  55. \f0\fs28 ,
  56. \f1\fs18 switch
  57. \f0\fs28 , and other keyword that are not function but takes parameter should have a space before ()\
  58. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\ql\qnatural\pardirnatural
  59. \b\fs24 \cf2 RIGHT\
  60. \f1\b0\fs18 \cf0 if (a) \{\
  61. ...\
  62. \}\
  63. function();\
  64. \f0\fs24 \
  65. \b \cf3 WRONG\
  66. \f1\b0\fs18 \cf0 if( a )\
  67. if ( a )\
  68. if(a)\
  69. function ();\
  70. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
  71. \f0\fs24 \cf0 \
  72. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\ql\qnatural\pardirnatural
  73. \f1\fs18 \cf0 \{\}
  74. \f0\fs28 usage\
  75. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li540\ql\qnatural\pardirnatural
  76. \b\fs24 \cf2 RIGHT\
  77. \f1\b0\fs18 \cf0 if (a) \{\
  78. ...\
  79. \}\
  80. while (a) \{\
  81. ...\
  82. \}\
  83. void function()\
  84. \{\
  85. ...\
  86. \}\
  87. - (void)functionWithParameter:(BOOL)parameter\
  88. \{\
  89. ...\
  90. \}\
  91. \f0\b\fs24 \cf3 WRONG
  92. \b0 \cf0 \
  93. \f1\fs18 - (void)function \{\
  94. ...\
  95. \}\
  96. if (a)\
  97. \{\
  98. ...\
  99. \}\
  100. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural
  101. \f0\fs24 \cf0 \
  102. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\ql\qnatural\pardirnatural
  103. \fs28 \cf0 Prefer early
  104. \f1\fs18 return
  105. \f0\fs28 ie:\
  106. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\ql\qnatural\pardirnatural
  107. \b\fs24 \cf2 PREFER\
  108. \f1\b0\fs18 \cf0 if (!a)\
  109. return;\
  110. \f0\fs24 \
  111. \b \cf3 OVER\
  112. \f1\b0\fs18 \cf0 if (a) \{\
  113. ...\
  114. ...\
  115. \}\
  116. \f0\fs24 \
  117. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\ql\qnatural\pardirnatural
  118. \fs28 \cf0 Objective C code - Don't call multiply the same method\
  119. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li540\ql\qnatural\pardirnatural
  120. \b\fs24 \cf2 RIGHT\
  121. \f1\b0\fs18 \cf0 NSWindow *window = [self window];\
  122. NSRect frame = [window frame];\
  123. frame.origin.x = 0;\
  124. [window setFrame:frame display:NO];\
  125. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\ql\qnatural\pardirnatural
  126. \f0\b\fs24 \cf3 WRONG\
  127. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li540\ql\qnatural\pardirnatural
  128. \f1\b0\fs18 \cf0 NSRect frame = [[self window] frame];\
  129. frame.origin.x = 0;\
  130. [[self window] setFrame:frame display:NO];\
  131. \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\ql\qnatural\pardirnatural
  132. \f0\fs24 \cf0 \
  133. }