Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java refactor to Generics industry standards

There seems to be some debate over refactoring to utilize java generics within my current team. The question I have is what are the current industry standards in terms of refactoring older Java code to take advantage of some of these features? Of course by industry standards I am referring to best practices. A link to a book or a site with these listed will be awarded the answer vote as that is the least subjective way to handle this question.

like image 404
Woot4Moo Avatar asked Feb 27 '10 00:02

Woot4Moo


2 Answers

I don't think that blindly following what somebody else declares to be "best practice" or "industry standard" is ever a good idea. You're in the best position to decide whether changing your code is worthwhile or not.

The questions you need to answer are what benefits will you get from upgrading the old code, what will it cost, and what are the risks?

The main benefit is that you will have improved compile-time type checking, which should help to detect bugs in new code that uses the updated code. It may even highlight bugs in existing code. Code that uses generics, while sometimes quite verbose, is typically more readable as it is explicit about which types are valid in which contexts. You'll also no longer have to suppress/ignore compiler warnings.

The cost is the amount of time it will take to make and test the necessary changes to introduce generics. Any time you make code changes there is a chance that you might introduce bugs, so that's a risk. Do the benefits outweigh the costs? That depends on how much code you have, how it's being used and what other demands you have on your time.

like image 174
Dan Dyer Avatar answered Oct 02 '22 12:10

Dan Dyer


The papers from this MIT research group might provide you with some useful guidelines:

  • Refactoring Java Applications to Use Generic Libraries
    • Efficiently refactoring Java applications to use generic libraries
      Robert Fuhrer, Frank Tip, Julian Dolby, Adam Kiezun and Markus Keller
      ECOOP 2005 --- Object-Oriented Programming, 19th European Conference, (Glasgow, Scotland), July 25-29, 2005.
    • Refactoring techniques for migrating applications to generic Java container classes
      Frank Tip, Robert Fuhrer, Julian Dolby, and Adam Kiezun
      IBM T.J. Watson Research Center IBM Research Report RC 23238, (Yorktown Heights, NY, USA), June 2, 2004.
like image 42
polygenelubricants Avatar answered Oct 02 '22 11:10

polygenelubricants