This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Refactoring: need help in finding bad smells

 
Goran Silic
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need help finding bed smells in 3 java classes. I'm at a beginner level of refactoring and I've really have problem spotting bed smells. If someone could point them out to me I'll be most appreciated. Thanks...
Because the JavaRanch won't let me for some reason to attach files in .zip, .rar, .txt, .java, .docx etc I have to put my code here:

Here's the code for Background.java:



Here's the code for Cad.java:





Here's the code for Table.java:

 
Ryan McGuire
Ranch Hand
Posts: 1055
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What smells the worst to you?
 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you provide a high level overview of the design. It will make it easier to understand what a class does if we know what the class is suppossed to be

Actually, I would say a bad smell #1:- Missing class level doc. Ideally you should be able to describe what the class represents in couple of lines, and that description should go in class level javadoc. At the very best, lack of javadocs indicates laziness on the part of the developer, and at the worst, it could mean that the developer doesn't think of classes as representation of real entities.
 
Junilu Lacar
Bartender
Pie
Posts: 7306
45
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some ways you can start developing a sensitivity to code smells:
  • Try writing a unit test for your code
  • Try adding some functionality
  • Try modifying the current functionality
  • Try explaining what the code does

  • If you find it hard to do one or more of these things, there's probably something that needs to be refactored. I'm kind iffy on the "No documentation is a smell" thing suggested by Jayesh because I believe that code should be self-documenting. OTOH, there are some cases where I do find that some high-level comments can be very helpful indeed in giving the reader an understanding of the intent of the code and the thought process of the authors when they wrote the code and made the design decisions that they made.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic