platform-core-home/documents/coding_conventions.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download) (as text)

1 : dj 1.1
2 :     <h1 align="center">Eclipse Platform/Core Coding Conventions</h1>
3 :     <p align="left">Here are some of the Coding Conventions that we use as a team.
4 :     Common code makes it easier for everyone to read and understand.</p>
5 :     <h3>Code Formatter:</h3>
6 :     <ul>
7 :     <li>set line length to be something large (like 800)</li>
8 : dj 1.2 <li>turn off formatting for comments</li>
9 : dj 1.1 <li> use the rest of the default settings</li>
10 :     </ul>
11 :     <h3>Organize imports:</h3>
12 :     <ul>
13 :     <li> number of imports needed for *: 3</li>
14 :     <li> remove all entries in list so we don't use the grouping feature</li>
15 :     <li> its all about space...extra blank lines make it hard to read code when
16 :     you have a small editor window</li>
17 :     </ul>
18 :     <h3>Copyright:</h3>
19 :     <ul>
20 :     <li> make sure the code has the correct copyright.</li>
21 :     <li>if the code was written in 2003, don't have 2000,2003 in the copyright</li>
22 :     <li>the copyright can be found on the <a href="http://www.eclipse.org/eclipse/eclipse-charter.html%20">Eclipse
23 :     Project Charter</a> page.</li>
24 :     </ul>
25 :     <h3>Code Comments:</h3>
26 :     <ul>
27 :     <li> comments are a good thing.</li>
28 :     <li> comment all &quot;unobvious&quot; things (e.g. don't comment setters/getters)</li>
29 :     </ul>
30 :     <h3>General: (use the tool!)</h3>
31 :     <ul>
32 :     <li>Turn on all the compiler prefs including unused temps, synthetic accessor
33 :     methods, unused imports, unused parameters, non-NLS'd strings, etc etc</li>
34 :     <li> NLS your strings. Look at the Policy class.</li>
35 :     <li> Compiler tasks. We have 3 that we use as a team (TODO, FIXME, XXX) Do not
36 :     add your own as this is unecessary and requires everyone on the team to change
37 :     their compiler settings in order to see these tasks.</li>
38 :     <li> All classes MUST have a copyright notice.</li>
39 :     <li> data type size initialization -&gt; use meaningful values if possible,
40 :     not things like: new HashSet(65)</li>
41 :     <li> Use interfaces when declaring variable types and in method signatures unless
42 :     it is necessary to use implementing class</li>
43 :     <li> use accessor methods, don't access variables on other classes directly</li>
44 :     <li> in general, we use the &quot;true&quot; case of an &quot;if&quot; clause
45 :     at the beginning. we also use it to exit a method early. If the whole method
46 :     is inside an &quot;if (!foo) {}&quot; then just say &quot;if (foo) return&quot;.</li>
47 :     <li> ignored exceptions must have a comment saying that they are being ignored
48 :     on purpose (compiler warning)</li>
49 :     <li> the lines where we create new CoreExceptions and throw them can become
50 :     quite long. We usually declare the String message on the line previous to
51 :     make it easier to read.</li>
52 :     <li> check for null if null could be returned (table look-ups, etc)</li>
53 :     <li> should use IPath for path logic rather than Strings and concatination</li>
54 :     <li> IPaths are your friend. Replace &quot;new File(location.toOSString())&quot;
55 :     with location.toFile();</li>
56 :     <li> Don't catch Exception unless you have to. Try to catch specific exceptions.</li>
57 :     <li> Don't wrap the whole method in a try {} catch {} block. This makes it hard
58 :     to generate specific error messages</li>
59 :     <li> if you have nested readers/streams you should only have to call #close()
60 :     on the outside one and all wrapped streams should be closed automatically
61 :     (note: you may have to call #flush() first)</li>
62 :     <li> Ensure all file I/O is buffered.</li>
63 :     <li> When sharing code with others, ensure that all the code released to the
64 :     repository at least compiles. </li>
65 :     <li> Policy.bind() has multiple methods, one of which accepts a single string
66 :     as an arg so you don't have to call Policy.bind(&quot;message.key&quot;, new
67 :     String[] { &quot;text&quot; });</li>
68 :     </ul>
69 :     <h3>NLS'ing your code: messages.properties</h3>
70 :     <ul>
71 :     <li> all sentences which are displayed to the user must end with a period</li>
72 :     <li> include parameters if possible</li>
73 :     <li> remove unused messages</li>
74 :     <li> make sure if the message accepts a parameter then you pass one in</li>
75 :     </ul>
76 :     <p>&nbsp;</p>