Tuesday, April 04, 2006

Checkstyle - Coding standards

Quality code in my opinion is an important step towards quality software.

I believe having a well-defined set of coding conventions is necessary. To produce code that is readable, reusable and maintainable, it is needed (among other things like having good programming habits) to follow some code writing conventions. I use Eclipse for my IDE. And with it, Checkstyle - the tool that helps write Java code that adheres to a coding standard.

There exist many coding standars. For personal use, I recommend the easiest form: to follow the Sun coding conventions. Of course, you may personalize it. This will help you in coding and your code, to have a standard format. In case of companies, they tend to have different coding standards: you have probably experienced a few, if you have worked already for a couple of different companies. As companies usually develop their own coding standards, sometimes very different from the Sun coding conventions, other times with minor alterations. This is good in either ways: code within a company needs to be maintained, reused, and improved. So this is a small assurance of better code. When a programmer or programmers have a well defined set of coding standards, they will think less about details such as code layout and variable naming conventions, spending more time on the real coding.

Some coding conventions that I find important:

  • Comments: all classes, methods, and variables should have
  • Naming conventions: constants should be in uppercase; variables, methods should have talkative names and should not be abbreviated
    (e.g.: private Map myHashMap;);
  • Declaration: all variables should be declared with visibility modifiers; each declaration should be on separate line

Checkstyle can check many aspects of your source code. You may want to give it try, as it now supports features like: checks for class design problems, duplicate code, and standards related to: Javadoc comments, naming conventions, import statements, white space, modifiers, blocks, etc.

If you already want to add it to your Eclipse IDE, you may find here some hints. As well, you are able to set various highlighting modes.


Technorati tags: Checkstyle, Eclipse, Java, tool, tutorial.

Saturday, January 07, 2006

Hermes

You may have wanted to peak into a queue or topic. Did you find a suitable tool for it? I have used Hermes, and I had a pleasant experience.


Hermes is a Swing application that allows you to interact with JMS providers. Hermes will work with any JMS enabled transport making it easy to browse or seach queues and topics, copy messages around and delete them. It fully integrates with JNDI letting you discover administered objects stored, create JMS sessions from the connection factories and use any destinations found. Many providers include a plugin that uses the native API to do non-JMS things like getting queue depths (and other statistics) or finding queue and topic names.

It offers some nice tutorials of setting it up with the JMS provider you are using. For example, check out the tutorial for setting up Hermes with JBoss 4.X. It can be used as well as a good example for JMS providers configured via JNDI.



Technorati tags: Hermes JMS, Swing, JNDI, tutorial, tools.

Wednesday, November 23, 2005

EMMA - Code Coverage

A free Java Code Coverage Tool

Recently I have used EMMA and I have been completely satisfied with the results it provided. Before I started working, I have also tried out the Borland code coverage tool from the Optimizeit enterprise suite, but the tools differ from each other, as well as the reports which are generated. I find the EMMA report easier to overview, and more user friendly. Plus it is free. I guess it can take a little time until you get familiar with it, but it is worth the effort.

"EMMA distinguishes itself from other tools by going after a unique feature combination: support for large-scale enterprise software development while keeping individual developer's work fast and iterative ... " as the "Borland Optimizeit Code Coverage gives developers the confidence that their code is ready to deploy when performance checks are run during development". (Sources: EMMA, Optimizeit.)

Here you can check out two sample coverage reports:
Both tools have the advantage that they can be integrated with Eclipse IDE. Though EMMA does not have a plugin for Eclipse, the way to use it from Eclipse is adding EMMA tasks to your ANT build. You can read the step by step instructions here. Like this you are enabled to run an application from ANT "so that coverage instrumentation is performed on-the-fly, as the classes are loaded by the JVM", and then the same process is repeated by breaking it into distinct instrumentation/execution/reporting steps. What I particularly like about EMMA is the option of separating instrumentation and execution (Offline mode). This is useful when there is a necessity of collecting and merging coverage data from multiple execution runs and multiple JVM processes.

Lance Finney has found EMMA to be a winner-tool: "Emma uses an interesting approach to defining coverage that often results in lines being only partially covered. For example, lines with ternary operators with only one branch executed will show as partially executed".

Technorati tags: code coverage, Emma code coverage, Ant.