Differences

This shows you the differences between two versions of the page.

Link to this comparison view

documentation:1.2:development:codestyle [2017/01/30 17:10] (current)
Line 1: Line 1:
 +====== How to make beautiful code in LSC? ======
  
 +This page describes some tips to make comprehensive code into LSC sources.
 +
 +A code style formatter profile is available for Eclipse, see instructions to use it at [[#​eclipse|the bottom of this page]].
 +
 +===== Indentation:​ tabulation or space? =====
 +
 +For indenting your code, configure your IDE to **only use the tabulation character** instead of spaces (some IDE simulates tabulation with spaces).
 +
 +==== Example ====
 +
 +<code java>
 +/**
 + * Indentation
 + */
 +class Example {
 +
 + int[] myArray = { 1, 2, 3, 4, 5, 6 };
 + int theInt = 1;
 + String someString = "​Hello";​
 + double aDouble = 3.0;
 +
 + void foo(int a, int b, int c, int d, int e, int f) {
 + switch (a) {
 + case 0:
 + Other.doFoo();​
 + break;
 + default:
 + Other.doBaz();​
 + }
 + }
 +
 + void bar(List v) {
 + for (int i = 0; i < 10; i++) {
 + v.add(new Integer(i));​
 + }
 + }
 +}
 +</​code>​
 +
 +This codestyle should be applied on all structures: if, while, for, try/catch, etc.
 +
 +===== Eclipse =====
 +
 +The lsc-sample repository contains a profile for code style formatting for LSC, in [[http://​tools.lsc-project.org/​repositories/​changes/​lsc/​lsc-sample/​trunk/​misc/​eclipse-code-style-formatting-profile.xml|misc/​eclipse-code-style-formatting-profile.xml]].
 +
 +To use this in Eclipse:
 +  - In the menu, go to ''​Window > Preferences''​
 +  - Unfold ''​Java > Code Style''​ and click on ''​Formatter''​
 +  - Click on ''​Import...''​ and open the file mentioned above
 +  - Press ''​OK''​
 +
 +**Tip:** You can apply this profile to any existing code by selecting it and using the menu item ''​Source > Format''​ or pressing ''​Shift+Ctrl+F''​.