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?
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.
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
Joined: Jul 11, 2001
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.
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.