-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCoding Style.rtf
executable file
·212 lines (154 loc) · 6.22 KB
/
Coding Style.rtf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
{\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf390
\cocoascreenfonts1{\fonttbl\f0\fswiss\fcharset0 Helvetica;\f1\fnil\fcharset0 Monaco;}
{\colortbl;\red255\green255\blue255;\red0\green134\blue2;\red195\green0\blue0;}
\paperw12240\paperh15840\vieww18380\viewh12620\viewkind0
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\qc
\f0\fs36 \cf0 Coding Rules\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
\fs24 \cf0 \
\fs28 Cocoa coding style for the naming.\
\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\pardirnatural
\f1\fs20 \cf0 variableNaming
\f0\fs28 variable should use capitalization on all word expect the first and never '_' ie\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\pardirnatural
\b\fs24 \cf2 RIGHT\
\f1\b0\fs18 \cf0 BOOL isFirstTimeReading;\
int age;\
\f0\fs24 \
\b \cf3 WRONG\
\f1\b0\fs18 \cf0 BOOL is_first_time_reading;\
int Age;\
int isFirstTimeReading_ever;\
\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\pardirnatural
\f0\fs28 \cf0 Objective-C Instance variable must be prefixed with _\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\pardirnatural
\b\fs24 \cf2 RIGHT\
\f1\b0\fs18 \cf0 @interface Object \{\
BOOL _isFirstTimeReading;\
int _age;\
\}\
\f0\fs24 \
\b \cf3 WRONG\
\f1\b0\fs18 \cf0 @interface Object \{\
BOOL isFirstTimeReading;\
int age;\
\}
\f0\fs28 \
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
\fs24 \cf0 \
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\pardirnatural
\f1\fs20 \cf0 Pointer *
\f0\fs28 must be preceded with a space and with no space after ie\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\pardirnatural
\b\fs24 \cf2 RIGHT\
\f1\b0\fs18 \cf0 void *pointer;\
\f0\fs24 \
\b \cf3 WRONG\
\f1\b0\fs18 \cf0 void * pointer;\
void* pointer;\
void*pointer;\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
\f0\fs24 \cf0 \
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\pardirnatural
\f1\fs20 \cf0 if
\f0\fs28 ,
\f1\fs18 switch
\f0\fs28 , and other keyword that are not function but takes parameter should have a space before ()\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\pardirnatural
\b\fs24 \cf2 RIGHT\
\f1\b0\fs18 \cf0 if (a) \{\
...\
\}\
function();\
\f0\fs24 \
\b \cf3 WRONG\
\f1\b0\fs18 \cf0 if( a )\
if ( a )\
if(a)\
function ();\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
\f0\fs24 \cf0 \
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\pardirnatural
\f1\fs18 \cf0 \{\}
\f0\fs28 usage\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li540\pardirnatural
\b\fs24 \cf2 RIGHT\
\f1\b0\fs18 \cf0 if (a) \{\
...\
\}\
while (a) \{\
...\
\}\
void function()\
\{\
...\
\}\
- (void)functionWithParameter:(BOOL)parameter\
\{\
...\
\}\
\f0\b\fs24 \cf3 WRONG
\b0 \cf0 \
\f1\fs18 - (void)function \{\
...\
\}\
if (a)\
\{\
...\
\}\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural
\f0\fs24 \cf0 \
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\pardirnatural
\fs28 \cf0 Prefer early
\f1\fs18 return
\f0\fs28 ie:\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\pardirnatural
\b\fs24 \cf2 PREFER\
\f1\b0\fs18 \cf0 if (!a)\
return;\
\f0\fs24 \
\b \cf3 OVER\
\f1\b0\fs18 \cf0 if (a) \{\
...\
...\
\}\
\f0\fs24 \
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\pardirnatural
\fs28 \cf0 Objective C code - Don't call multiply the same method\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li540\pardirnatural
\b\fs24 \cf2 RIGHT\
\f1\b0\fs18 \cf0 NSWindow *window = [self window];\
NSRect frame = [window frame];\
frame.origin.x = 0;\
[window setFrame:frame display:NO];\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\pardirnatural
\f0\b\fs24 \cf3 WRONG\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li540\pardirnatural
\f1\b0\fs18 \cf0 NSRect frame = [[self window] frame];\
frame.origin.x = 0;\
[[self window] setFrame:frame display:NO];\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\pardirnatural
\f0\fs28 \cf0 objectAtIndex is gone - keep it like this\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li540\pardirnatural
\b\fs24 \cf2 RIGHT\
\f1\b0\fs18 \cf0 NSArray *array;\
\'85filled with lots of stuff\
id object = array[index];\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\pardirnatural
\f0\b\fs24 \cf3 WRONG\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li540\pardirnatural
\f1\b0\fs18 \cf0 NSArray *array;\
\'85filled with lots of stuff\
id object = [array objectAtIndex:index];\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\sl480\slmult1\pardirnatural
\f0\fs28 \cf0 NSArray literals improve readability - use them\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li540\pardirnatural
\b\fs24 \cf2 RIGHT\
\f1\b0\fs18 \cf0 NSArray *array = @[obj1, obj2, obj3];\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\fi540\pardirnatural
\f0\b\fs24 \cf3 WRONG\
\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\li540\pardirnatural
\f1\b0\fs18 \cf0 NSArray *array = [NSArray arrayWithObjects: obj1, obj2, obj3, nil];\
}