my dog learned polymorphism*
The moose likes Agile and Other Processes and the fly likes Clean Code: Best way, per Class, big companies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Agile and Other Processes
Bookmark "Clean Code: Best way, per Class, big companies" Watch "Clean Code: Best way, per Class, big companies" New topic
Author

Clean Code: Best way, per Class, big companies

G�za Czimeth
Greenhorn

Joined: Jan 28, 2008
Posts: 2
1. Is there more way to write clean code? Is there a best way?

2. Your method to clean code only applicable per class, or is the cleaning procedure changes if I look at/consider classes which uses the class what I want to clear? Do you define any order about which class or class group should be clean first? e.g.: first DAO's than jsp than Control classes (talking about MVC).

2.1 In general if I have a porject with many classes and I wan't to clean the code where/how should I start at all?

3. What do you think, does big companies ever start to clean there legacy code? I work for a multi and it is not even mentioned here to clean 'our' legacy code, and the fact is the code is very hard to read and maintain. I think small companies are more flexible to do 'these' kind of things. What do you think?
Ananth Chellathurai
Ranch Hand

Joined: Nov 21, 2007
Posts: 349

Hi,

Welcome to Java Ranch.
The first step I would do is to clean up all warnings I see in my editor. And then you may try using one of the tools like Findbugs, PMD, Checkstyle, Cobertura. Which will give you a huge list of problems in your application. Clean them up. I use findbugs which has a plugin available for eclipse.

Hope this helps your needs.

Regards
Ananth Chellathurai


Ananth Chellathurai [Walk on software]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
2.1) Clean the code that you have to touch anyway. That is, if you have to change some code, for example to fix a bug or to implement an enhancement, make sure that after you have touched it, it is *more* clean than before.

3) Companies don't clean code. Responsible software developers do. And not as a separate action from implementing code, but as an integrated part of every minute of their work. You don't even need to get permission to do it. Just start doing it. Now. Seriously.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Ananth Chellathurai:

The first step I would do is to clean up all warnings I see in my editor. And then you may try using one of the tools like Findbugs, PMD, Checkstyle, Cobertura. Which will give you a huge list of problems in your application. Clean them up. I use findbugs which has a plugin available for eclipse.


While those tools have some nicety to it, they can't tackle some of the worst problems with unclean code: badly named methods and identifiers, for example.
arulk pillai
Author
Ranch Hand

Joined: May 31, 2007
Posts: 3223
Before you start cleaning write a test case if one does not exist.


Java Interview Questions and Answers Blog | Amazon.com profile | Java Interview Books
Vijay Venkat
Ranch Hand

Joined: Aug 12, 2001
Posts: 52
Hi G�za Czimeth

1. You can read couple of books/sites to identify what is bad code.
2. This book "Clean Code" should serve that purpose +
3. Don't forget to read Refactoring: Improving the Design of Existing Code (http://www.refactoring.com/catalog/index.html) +
4. Other book is Code Complete 2 by Steve McConnell
5. Write tests before you make code clean. Not always possible at all situations. But getting to do that is the first step.
6. The most important is the courage to get started with it.

Thanks,
Vijay Venkataraman
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Clean Code: Best way, per Class, big companies