VI    Bad Style – the Style Guidance Module

Style is important in programming and writing 'bad' code (code that doesn't work correctly, is hard to read, is hard to maintain, etc.) either costs you marks, time or your nerves.

KenyaEclipse contains a Style guidance module that picks up common mistakes (everybody does it at least once) and helps you to correct them.

Consider the following code snippet:

void printBoolean(boolean b) {
  if( b == true ) {
    println("true");
  } else {
    println("false");
  }
}

Even if we don't know what b is, we can say that the expression '(b == true)' is exactly the same as the expression 'b'.

KenyaEclipse will detect this kind of thing for you and help you do the boolean reduction.

Style Warning in the Problem View

You can see that the style warnings show up in exactly the same way as compile errors do. However, while KenyaEclipse does not offer assistance with compile errors, there is assistance for stilistic mistakes, such as this one. You can trigger the assistant by clicking on the warning annotation or by using the Edit menu item and selecting Quick Fix.

Style Resolution Popup window

If an automatic solution is available, you will be presented with alternatives for solving the problem at hand and a comprehensive explanation as to why the fix should be applied (shows up after about a second). You can confirm by using enter or double clicking on the (a) solution you wish to apply. To cancel the dialog, use ESC.

Editor view after applying the resolution

After applying the solution, the document is marked as 'dirty', the warning has disappeared and the change ruler contains the change, as if you had done it yourself.

All changes applied by the StyleChecker are un- and re-doable using the normal undo/redo actions.

Configuring the module

The StyleChecker is separately configurable for each file. By right clicking on the file in question (in the Kenya Explorer) and choosing Properties, you can reach the configuration page.

Style Guidance Module Property page

This page allows you to enable or disable style checking altogether or to enable or disable individual checks. If, for example, you disable the 'Check for overcomplicated Booleans', you will notice that the warning in our previous bit of code soon disappears (next time the code is compiled).