Show last authors
1 This list a series of best practices in order to make the applications more maintainable and easy to understand.
2
3
4
5 = Naming conventions =
6
7 == Prefixes in bundles ==
8
9 2 to 5 letters. abbreviation of your organization. All lower case.
10
11 Ex: rq, sys, cap, ...
12
13 Rationale: short since you will have to type it. almost unique to avoid conflict with another organization code in case both are deployed on the same platform. Lower case to ease the parsing (extract the prefix until the first capital which is the name of the property or entity.
14
15 == Entity names ==
16
17 No dot, no dash. Underscore discouraged. Start by an Upper case.
18
19 Rationale: Upper case for passing of the full name. Entity name will be visible in scripts (Javascript), therefore dots, dashes will case problems.
20
21
22 Ex: Switch
23
24 == Property names ==
25
26 No dot, no dash. Start by an Upper case
27
28 Rationale: same as Entity name
29
30 == User action names ==
31
32 User actions should NOT include special characters and start by a lower case. Camel case is ok. It should be a verb.
33
34 Example:
35
36 edit
37
38 Rationale: used in URL (browser) which is usually lower case. (Not sure why tough)
39
40
41
42 == Operations names ==
43
44 User actions should NOT include special characters: no dots or dashes and start by an upper case. Camel case is ok. It should be a verb.
45
46 Example:
47
48 Save
49
50 Rationale: distinguish from user actions. Consistent with SOAP naming.
51
52
53
54 = JavaScript Best practices =
55
56
57 Javascript best practices are designed to make the code easier to maintain, more readable and less error prone.
58
59
60 == Formatting and indentation level ==
61
62 By default 4 spaces.
63
64
65 == Statement termination ==
66
67 In javascript, lines may be terminated by a new line or a semi column. We recommend the semi column for consistency with Java.
68
69 Ex:
70
71 {{code language="javascript"}}
72 var name = "toto"
73 function titi() {
74 return toto
75 }
76 {{/code}}
77
78
79 or :
80 {{code language="javascript"}}
81 var name = "toto";
82 function titi() {
83 return toto;
84 }
85 {{/code}}
86
87
88 == Strings ==
89
90 in javascript, you may use a single quote or a double quote for strings:
91
92 {{code language="javascript"}}
93 var a = 'toto';
94 {{/code}}
95
96 or
97
98 {{code language="javascript"}}
99 var a = "toto";
100 {{/code}}
101
102
103 We recommend using double quotes for consistency with Java (and c#)
104
105
106 == Numbers ==
107
108 double:
109
110 {{code language="javascript"}}
111 var price = 10.0
112 {{/code}}
113
114
115 integer:
116
117 {{code language="javascript"}}
118 var quantity = 10;
119 {{/code}}
120
121
122 bad as hell : do not use a leading 0. In javascript it means octal (base 8). Therefore 010 == 8
123
124 {{code language="javascript"}}
125 var quantity = 010;
126 {{/code}}
127
128
129 == Arrays ==
130
131 Do not forget the rather elegant notation in javascript:
132
133 {{code language="javascript"}}
134 var arr = ["first", "second", "third"];
135 {{/code}}
136
137
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 9.11.5 - Documentation