6 in a program, src-code is consisted by lots of symbol word. some of them
\r
7 are fixed, and called reserved-words. some of them is a chars beyound a-z and
\r
8 A-Z and 0-9 and _, called operation-char. some of them are normal word for
\r
9 programming element, variables, functions, types, macros, and so on.
\r
10 this doc is used to describe the guide for the third part above.
\r
11 a clear and better name is helpfull in program coding and reading. name is
\r
12 a interface between different program, and different developers.
\r
14 there is a tool to descript words charactors, it is regular-expression. it
\r
15 can be used to describe the name in program.
\r
17 a word consisted by a format, can express more informations.
\r
18 eg: a variable name called 'i32TempValue', can be dispatched by those info:
\r
20 @ i, integer, the type of this variable.
\r
21 @ 32, bit lenth, the size of this variable.
\r
22 @ Temp, short name of 'temperature'. with a four char short name to express a
\r
24 @ Value, the word it self.
\r
26 name style defines format like the above example. it's helpfull for a
\r
27 developer to known the meaning of a variable.
\r
29 in current world, there is more coding-style in various program guide. this
\r
30 doc is a general doc for name style.
\r
32 name style is used for program element, and also used for file name.
\r
39 those conception are used for general text.
\r
41 @ char-encoding-set: a charactor is described as a binary code in computer
\r
42 system. the traditional char-encoding-set is asdii, and the popular one is
\r
43 utf-8. a program src-code use ascii as normal. if a compiler support multi-
\r
44 bytes encoding, such as utf-8, normally it is used for string data in
\r
45 program. the code it self is writen by ascii in most of program language.
\r
46 @ char/charactor: one charactor in various char-encoding-set. it's one byte
\r
47 size data in ascii, and it's two bytes size data in GBK, and it's two or
\r
48 three bytes size data in utf-8.
\r
49 @ word: it is consisted by a-z or A-Z or 0-9. in reg-expr, the char in the word
\r
50 has a name called 'alnum'.
\r
51 @ words: it is consisted by several word. if it is used for language txt, it's
\r
53 @ opr-char: operation char, signatures. it is a char beyound word in ascii.
\r
54 there is a name in reg-expr for it, it called 'punct'.
\r
56 general name for chars:
\r
58 @ upper-char: the char of A-Z.
\r
59 @ lower-char: the char of a-z.
\r
61 and those conception are used for programming.
\r
63 @ var-name/vname: variable name is a word for program variable or function
\r
64 name. it is consisted by word or '_', the first char of a word can not be
\r
66 @ symbol/symbol-word: it's an alias for variable or function name. the
\r
67 importance of this name is pay attension on export or import in a program.
\r
68 @ reserved-word/key-word: the fixed name used in code for a type of program
\r
70 @ lexuary: a rule used to consist a word.
\r
71 @ grammar: a rule used to orgnize different word with a txt syntax.
\r
73 general reg-expr. it is used in reg-expr, and it is also a suitable name
\r
76 [:alpha:]: equal to [a-zA-Z]
\r
77 [:lower:]: equal to [a-z]
\r
78 [:upper:]: equal to [A-Z]
\r
79 [:digit:]: equal to [0-9]
\r
80 [:alnum:]: equal to [a-zA-Z0-9]
\r
81 [:blank:]: matching ' '(blank), '\t'(table char)
\r
82 [:space:]: matching ' '(blank), '\t'(table char), '\n'(newline), '\f'(),
\r
83 '\v'(vertical table char), '\r'(return char).
\r
84 [:cntrl:]: control char. it is started from 000 to 037 and 177 (DEL) in ascii
\r
86 [:print:]: equal to [:alnum:] and [:punct:] and ' '(blank).
\r
87 [:graph:]: equal to [:alnum:] and [:punct:].
\r
88 [:punct:]: it is: "`! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { |
\r
90 [:xdigit:]: chars for hex word. include 0-9 or A-F or a-f.
\r
94 # Popular Name Style
\r
95 =====================
\r
97 different developer has different code style. but in a orgnization, or in
\r
98 a company, the name-style guide doc is needed by developers.
\r
101 @ GeneralStyle: a newer use single char or a single word to name the variable
\r
102 in normal. it's easy and readable in src-code. but there is a limitation in
\r
103 one word name to express the meaning of variable or function.
\r
104 @ GNUStyle: join different word with '_', the word can be full name string, or
\r
105 a short name string. it's an improvement of GeneralStyle.
\r
106 @ MFCStyle: widlly used coding-style, and to be a traditional one. many
\r
107 c/cpp developers started from this one.
\r
108 it uses a short or full word name string combination, and the first char of
\r
109 every word is a upper-char, others is lower-char. it has a type prefix for
\r
110 variables or types by short word name.
\r
111 short word name can save the char space in storage. but sometimes, it is
\r
112 a bit hard to read the meaning of variable. i think it is usefull for low-
\r
113 level programming, because of less ram space cost.
\r
114 @ JavaStyle: it's a bit different with MFCStyle. the first word in name string
\r
115 is started with lower-char. this featrue is compative with one word name.
\r
116 the name of variable is consisted without type prefix, except the type name
\r
119 here enum the example of different coding-style for c/cpp.
\r
120 GeneralStyle example:
\r
127 // replace code here.
\r
128 printf("value is : %d\n", value);
\r
133 the name is very short, it's helpfull for code-reading, but weakness for
\r
134 expression of meanings.
\r
135 others express a name with multi-word, maybe with a type prefix.
\r
136 it is not very nice for reading, if the lenth of name string is too long.
\r
141 int i, j, value_for_test;
\r
143 int example_function ()
\r
145 // replace code here.
\r
146 printf("value is : %d\n", value_for_test);
\r
155 int i, j, i32ValueForTest;
\r
159 // replace code here.
\r
160 printf("value is : %d\n", i32ValueForTest);
\r
169 int i, j, valueForTest;
\r
171 int exampleFunction ()
\r
173 // replace code here.
\r
174 printf("value is : %d\n", valueForTest);
\r
180 those examples are simplly to show general difference between them. see
\r
181 the corresponding documents for them to known them deeply.
\r
185 # subject in name style
\r
186 =======================
\r
188 a name style can be seperated by several parts. every part is a subject.
\r
190 @ short name or full name.
\r
191 a short name is a string that cost less space, it is helpfull for low-level
\r
194 @ started with upper-char or join with '_'.
\r
195 the type of those two style can express the meaning of a name more better,
\r
196 rather than a single word name.
\r
197 it is good for code reading when the name is too long.
\r
198 the after one cost a bit more char space in memory.
\r
200 @ started with lower-char for first word or not.
\r
201 by using lower-char for first word, it can be compative with GeneralStyle.
\r
202 if the name is one word string, it's equal to GeneralStyle.
\r
205 it's usefull for low-level programming, because developer use more basical
\r
206 type variables in code, and it is helpfull to name a variable with type prefix.
\r
207 but in application programming, the developer face to many self-defined
\r
208 type, or class type. the type prefix of a variable is normally a class-type
\r
209 prefix, or other type-defined prefix.
\r
212 how to get a readable short name?
\r
213 in MFCStyle, the short name is consisted by 2~6 chars. the char of a word
\r
214 is the '¸¨Òô' char, or the first N char(4 char in traditional), so that it can
\r
215 be recognized more better.
\r
216 in other condition, the name is described by several word, or a sentence,
\r
217 the first char of this sentence also can be used for namming.
\r
225 name style is used in those condition.
\r
227 @ program language element name. variables, functions, macros, types, and so
\r
230 @ src code pkg file.
\r
231 @ binary install pkg file.
\r
234 if it is used for programming element, read the charpter of 'Name Style For
\r
235 devrules'. if it is used for file name, read the charpter of 'Name Style for
\r
240 # Name Style For devspec
\r
241 =========================
\r
243 the style of name style is based on 'MFCStyle' for devspec. because it is
\r
244 used for low-level system programming in most. the style used for application
\r
245 developing is in extend document.
\r
246 the default name-style is GeneralStyle. it's easy for comprehansion. but
\r
247 the interface(var/func) of a module, must use MFCStyle, and with extend specyfic below.
\r
249 the helpfull features by MFCStyle are:
\r
251 @ using short name to save memory space, and easy to read.
\r
252 @ using type prefix to known the type of symbol string.
\r
253 @ it defined a lot of type prefix for variable. such as c(char), i(int),
\r
254 u(unsigned int), l(long), f(float), sz(string), lp(long pointer), v(void).
\r
255 @ it uses 'C' for class type name as a type prefix. no prefix for others such
\r
256 as macro, enum, struct, union.
\r
257 @ macro and enum define.
\r
258 use full upper-char with short name combination, and join word with '_'.
\r
259 append 'M_' prefix for macro, and 'EM_' for enum type.
\r
260 if the macro is defined as a macro-function, the name of it is same as
\r
262 @ struct and union define
\r
263 all struct is defined as a typedef for global accessing. the default name
\r
264 style is familiar with macro. using full upper-case with short name combination
\r
265 and join with '_'. append 'ST_' prefix for struct, and 'UN_' for union, if it
\r
267 the struct-type defined in struct is another name, which is different from
\r
268 type name. use a '__tag_' prefix before type name.
\r
269 define a pointer type with 'P' prefix of the type. eg:
\r
272 struct __tag_ST_TYPE_EXAMPLE {
\r
274 } ST_TYPE_EXAMPLE, *PST_TYPE_EXAMPLE;
\r
280 the difference from MFCStyle is:
\r
282 @ use General Style for simple function feature implement.
\r
283 @ type prefix extend: st(struct type), un(union type), em(enum).
\r
284 @ size of type extend: 8/16/32/64.
\r
285 @ type prefix for type name. is not only for class name, it uses type prefix
\r
286 for macro, enum, struct, union.
\r
294 @ single char variable
\r
295 the normal single char variable is:
\r
296 # i, j, k, they are the default general purpose name.
\r
297 # i, j, k; m, n, l; x, y, z; they are used for array index variable, or loop
\r
298 increasing variable.
\r
299 # some variable is the short name of physical-unit or physical-value-name. eg:
\r
300 v(speed), t(time/temperature), s(distance).
\r
302 @ single word variable or function
\r
303 it's the first choosen of local variable in functions. and the function
\r
304 name for traditional module.
\r
305 for example: traditional module of CStack, has many functions which is
\r
306 single word name. push(), pop(), and so on. it's easy to use rather than
\r
307 Multi-word. it has traditional operating function with a traditional name.
\r
316 # syntax for file name
\r
317 ======================
\r
319 see the charpter of 'pkg-file-name-format'.
\r
321 file name style is used for those files:
\r
324 it's the similar with function name. it's consisted by upper-char started
\r
325 word combination. and a type prefix such as C(Class), T(Type), M(Module).
\r
327 @ unit test src code file.
\r
328 the name of src code file, has a '_test' suffix after module name, and
\r
329 before extend file name.
\r
330 eg: CStack.c is a src-code file for CStack module, and the test src file
\r
331 for it is CStack_test.c.
\r
333 @ src code and binary install pkg file.
\r
334 it's a file name syntax, not file name style.
\r
335 the syntax of pkg file name is :
\r
336 '<pkg-name>_[<pkg-type>-]<version>-<date>-<chksum>.<ext-name>'
\r
338 # pkg-name, main content. a pkg-name
\r
339 # pkg-type, if it is a src pkg, append 'src' after pkg-name for src-pkg, leave
\r
340 it blank for binary-install-pkg, and 'res' for resource-install-pkg.
\r
341 # version, a version code with three level version id.
\r
342 # date, pkg archive date.
\r
343 # chksum, 16bit hex summary of file content. it's used for file modification
\r
344 checking. or use 16bit hex summary of file sha1 value.
\r
345 # ext-name, use tar.gz/tar.bz2/tar.xz for src-pkg, use 'etz' for install-pkg.
\r
359 ÔÚ³ÌÐòÖУ¬ÐèÒª¶Ô±äÁ¿¡¢º¯Êý¡¢ºê¶¨Òå¡¢ÎļþÃû½øÐÐÃüÃû¡£ÎªÁËʹÃû³Æ¿ÉÒÔÖ±¹ÛµÄ±íʾº¬Ò壬ÇÒÔÚʹÓÃÖмæ¹ËÊäÈëµÄ±ã½ÝÐÔ£¬ºÍ´úÂëµÄÃÀ¹Û£¬
\r
360 ¶ÔÃû³Æ×Ö·û´®µÄÃüÃûÒÔijÖÖ·ç¸ñºÍ¹æÔò½øÐÐÃüÃû£¬½«Õâ¸ö³Æ֮Ϊ³ÌÐòµÄÃüÃû¹æÔò/ÃüÃû·ç¸ñ
\r
363 ʹÓô¿Ð¡Ð´»òMFCStyleµÄ´úÂë·ç¸ñ¡£
\r
365 Ò»¸öÃû³Æ×Ö·û´®Óв»Í¬µÄµ¥´Ê»ò×Ö·û×é³É¡£
\r
366 @ ÒÔµ¥´ÊÁ¬½ÓÃüÃû£¬Öм䲻´ø¿Õ¸ñ£¬Ê××Öĸ´óдÓÃÓÚÎĵµÖеÄÃèÊö£¬³ÌÐòµÄ±äÁ¿ºÍº¯ÊýÊ××ÖĸСд¡£
\r
367 @ ÒÔµ¥´ÊµÄËõдÁ¬½Ó£¬ËõдΪ2-5¸ö×Öĸ£¬Ê××Öĸ´óд¡£
\r
368 @ ʹÓõ¥´Ê¡¢Óï¾ä×éºÏµÄÊ××Öĸ×éºÏ£¬±íʾһ¸ö¹¦ÄÜÃû³ÆµÄËõд¡£
\r
369 @ ÒÔµ¥´Ê¡¢Óï¾ä×éºÏµÄÊ××Öĸ×éºÏ£¬Ä©Î²»òÆðʼµÄµ¥´Ê²»ÊǷdz£³¤Ê±£¬ÒÔÍêÕûµÄµ¥´ÊÃüÃû£¬±È½ÏÈÝÒ×Á˽ⵥ´ÊµÄº¬Òå¡£eg£ºbuild-pkglist£¬
\r
370 ËõдΪbpl£¬»òbuildpl£¬ÒÔÏÔʾbuildÕâ¸ö¹¦Äܵĺ¬Òå¡£
\r
374 @ ³ÌÐòÎļþÃû£ºÒÔ¶à¸ö´óд×Öĸ¿ªÍ·µÄµ¥´Ê±íʾ£¬Öм䲻¼Ó¿Õ¸ñ¡¢Ï»®ÏßµÈ×Ö·û¡£
\r
375 @ ÀàÐÍÃû³Æ£º´óд×Öĸ¿ªÍ·µÄµ¥´Ê×éºÏ£¬²¢Ìí¼ÓÀàÐÍpfx¡£¶ÔÓÚtypedef structºÍtypedef enumµÄÀàÐͶ¨Ò壬ʹÓú궨Òå·ç¸ñµÄ´óд×Öĸ¼ÓÏ»®Ïß×éºÏ¡£
\r
376 @ ±äÁ¿Ãû³Æ£ºµ¥¸öСд×Öĸ£¬»ò´¿Ð¡Ð´×ÖĸµÄµ¥¸öµ¥´Ê£¬»ò´óд×Öĸ¿ªÍ·µÄµ¥´Ê×éºÏ+ÀàÐÍpfx¡£¶ÔÓÚÀàÐÍpfx£¬ÓÃÓÚ±íʾ±äÁ¿ÀàÐ͵Äͬʱ£¬Çø·ÖÓÚº¯Êý¡£
\r
377 @ ºê¶¨ÒåºÍö¾Ù/½á¹¹ÌåÀàÐÍÃüÃû£º´¿´óдµ¥´Ê×éºÏ£¬²¢ÒÔÏ»®ÏßÁ¬½Óµ¥´Ê¡£ºê¶¨ÒåÒÔM_Ϊpfx£¬½á¹¹ÌåÒÔST_Ϊpfx£¬Ã¶¾ÙÀàÐÍÒÔEM_Ϊpfx£¬ÁªºÏÀàÐÍ
\r
380 ¶ÔÓÚÃüÃûµÄ·½·¨£¬Í¨³£½¨ÒéÐÔµÄÕâôʹÓãº
\r
381 @ ʹÓõ¥¸ö×Ö·ûµÄÁÙʱ±äÁ¿£¬i¡¢j¡¢x¡¢y¡¢z¡¢m¡¢n¡¢k¡¢lµÈ£¬ÓÃÓÚindex¡£ÆäËüµ¥¸ö×ÖĸµÄ±äÁ¿ÃüÃûÓÃÓÚÒ»¸öº¯ÊýÄÚµ¥¸öobjµÄ±íʾ¡£
\r
382 @ 2¡«3¸ö×Ö·ûµÄËõд£¬»òÒ»¸öµ¥´Ê£¬ÓÃÓÚÒ»¸öº¯ÊýÄÚµ¥¸öobjµÄ±íʾ¡£
\r
383 @ ÔÚº¯ÊýÖÐʹÓõıäÁ¿¶ÔÏó½Ï¶à£¬»ò±äÁ¿¶ÔÏó²»³£Óûò²»Í¨Óã¬ÐèʹÓÃÍêÕûµÄÃû³Æ×Ö·û´®£¬Ê¹±äÁ¿µÄº¬Òå±È½ÏÖ±¹Û¡£
\r
384 @ ³ÉÔ±±äÁ¿£¬ÓÈÆäÊÇpublicʹÓõģ¬Ê¹ÓÃMFCStyle£¬ÇÒÌí¼ÓÀàÐÍpfx¡£
\r
385 @ ³ÉÔ±º¯ÊýÒÔµ¥¸öµ¥´Ê±íʾµÄ£¬Ê¹Óô¿Ð¡Ð´Ãû³Æ£¬»ò´óдÆðʼµÄ×Ö·û´®ÃüÃû£¬¸ù¾ÝʹÓÃÏ°¹ß¶ø¶¨¡£ÀýÈçÒ»¸ö¶ÓÁÐQueueÊÇͨÓÃÀàÐÍ£¬ÔÚ¶¨Òå³É±äÁ¿Ê¹ÓÃ
\r
386 ʱºÜ¶àʱºò¿ÉÄÜʹÓõ¥¸öСд×Öĸ£¬»ò´¿Ð¡Ð´µ¥´Ê£¬ËùÒÔµ¥¸öµ¥´ÊµÄ³ÉÔ±º¯ÊýʹÓô¿Ð¡Ð´£¬ÇÒ¾¡Á¿Ê¹Óõ¥¸öµ¥´Ê±íʾһ¸ö³ÉÔ±º¯Êý¡£
\r
387 @ ¾Ö²¿±äÁ¿Í¨³£Ê¹Óõ¥¸öСд×Öĸ£¬´¿Ð¡Ð´Ëõд»ò´¿Ð¡Ð´µ¥´Ê£¬ÒÔʹ´úÂë¿´ÉÏÈ¥¾¡Á¿¼ò½à¡£
\r
388 @ ¶ÔÓÚpublicµÄÈ«¾Ö±äÁ¿£¬Ê¹Óôóд×Öĸ¿ªÍ·µÄµ¥´Ê×éºÏ£¬²¢´øÀàÐÍpfx¡£
\r
389 @ ¶ÔÓÚ¾Ö²¿±äÁ¿Öв»³£ÓõıäÁ¿ÀàÐÍ»ò±äÁ¿ÄÚÈÝ£¬ÐèÒªÒÔ¶à¸öµ¥´Ê±íʾµÄ£¬²Î¿¼publicµÄÈ«¾Ö±äÁ¿µÄÃüÃû¡£
\r
391 GNUStyleµÄ±äÁ¿ÃüÃû£¬ÔÚ²ÎÊýÅäÖÃÎļþÖÐʹÓá£Ò»¸öÈ«¾ÖµÄ»·¾³±äÁ¿£¬Ê¹ÓÃgnuµÄstyle±È½ÏºÏÊÊ¡£
\r
395 # ÔÚsrcµÄ¿ªÊ¼²¿·Ö¶¨Ò壬ÔÚÖ®ºóʹÓ᣷DZäÁ¿¶¨ÒåÇøÓò¶¨ÒåµÄ±äÁ¿£¬Í¨³£²»ÕâôʹÓ㬻òÓÃÓÚµ÷ÊԵȡ£
\r
396 # ±äÁ¿¶¨ÒåÇøÓò²Î¿¼code-sample
\r
397 # ±äÁ¿ÒÔÏÔʽµÄ±äÁ¿¶¨Ò壬²»¶¨ÒåÒþʽµÄ±äÁ¿ÉùÃ÷¡£
\r