refactoring : Java Glossary

*0-9ABCDEFGHIJKLMNOPQRSTUVWXYZ (all)

refactoring refactoring
Cleaning up code, perhaps by moving a field from one class to another, pushing some code up or down a hierarchy. Most often it is the process of splitting out repetitive code to turn it into its own separate method. An automated tool such as a SCIDs to help you do might work like this:
  1. I have a method which has some code that I would like to pull out into its own method.
  2. I highlight the offending code.
  3. I select Extract Method from a popup menu
  4. The Refactoring Browser asks me to name the method and automatically creates it and inserts the highlighted code.
  5. In the current method, the highlighted code is replace by an invocation to the newly created method.

Ideally, in a perfectly written computer program, with a perfectly designed computer language, with a perfect SCID/ IDE, it should be possible to change any line/element of the program in isolation without having to make any supporting changes elsewhere. The program should still function in a reasonable way. For example, you should be able to change the allowable bounds on a field variable in one line of code (which might result in it internally being promoted from int to long), without having to manually adjust any other code. The basic principle is you should have to tell a computer any one fact, or decision in only one place. For example, you should have to tell a program which colour scheme to use in precisely one and only one place and by one place I mean one line of code. Real life computer languages and IDEs (Integrated Development Environments) put up huge roadblocks to getting anywhere close to perfection.

Java is a very refactoring-friendly language. You can change the type of a variable, add or remove a parameter to a method, Change something from static to instance or the reverse. Move code around. Split code up. Rename. You can do these things with a refactoring tool such as the one in IntelliJ, but even if it or you screw up or fail to complete the changes, as soon as you compile, the error mesages will warn you of other things you must change to be consistent. Pretty much, when you get a clean compile, your code will work.

IntelliJ

I use JetBrains IntelliJ IDEA as my IDE (Integrated Development Environment), which supports many canned refactorings with a few mouseclicks. Some of the most useful are: It is a whole new way of programming. By letting the computer handle the details of the transformations, you can rapidly rearrange code without breaking it. You tend then to hold yourself to an ever higher standard. It is a step on the road to a SCID (Source Code In Database) where you don’t transform its deep structure to view it in alternate ways.

Algebra

If you recall your grade 7 algebra, you learned to refactor. You learned to convert 7a + 7b to 7(a + b). You look for commonality then split it out so that it appears only once. This is the same thing you do to refactor Java. You look for common code. Then you split it out so there is no repetition of it. You can have two classes implement a common interface, or one class inherit from another or two classes inherit from a common base class, possibly abstract. You write the common code in using only the fields and methods of the common interface or class.

When in doubt, refactor.
~ Roedy (1948-02-04 age:70)

Books

book cover recommend book⇒Refactoring Workbookto book home
by William C. Wake 978-0-321-10929-3 paperback
publisher Addison-Wesley
published 2003-09-06
has exercises and real world examples. An emminently practical book.
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Refactoring: Improving the Design of Existing Codeto book home
by Martin Fowler, Kent Beck [Contributor], John Brant [Contributor], William Opdyke, Don Roberts 978-7-50831554-6 paperback
birth 1963 age:54 978-0-201-48567-7 hardcover
publisher Addison-Wesley B000OZ0N4Y kindle
published 1999-07-08
Discusses how reorganising code into standard patterns makes it easier to maintain. Highly recommended. Practical before and after examples of cleaning up stinking code.
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.
book cover recommend book⇒Code Complete: A Practical Handbook of Software Constructionto book home
by Steve McConnell 978-1-55615-484-3 paperback
publisher Microsoft 978-0-7356-3697-2 eBook
published 1993-05-14
Gives lots of practical advice on optimising. He talks mostly about C with examples in Fortran, Pascal, Basic and Ada. He doesn’t talk about Java. It didn’t exist when the book was written.
Australian flag abe books anz abe books.ca Canadian flag
German flag abe books.de amazon.ca Canadian flag
German flag amazon.de Chapters Indigo Canadian flag
Spanish flag amazon.es Chapters Indigo eBooks Canadian flag
Spanish flag iberlibro.com abe books.com American flag
French flag abe books.fr amazon.com American flag
French flag amazon.fr Barnes & Noble American flag
Italian flag abe books.it Nook at Barnes & Noble American flag
Italian flag amazon.it Kobo American flag
India flag junglee.com Google play American flag
UK flag abe books.co.uk O’Reilly Safari American flag
UK flag amazon.co.uk Powells American flag
UN flag other stores
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder.

This page is posted
on the web at:

http://mindprod.com/jgloss/refactoring.html

Optional Replicator mirror
of mindprod.com
on local hard disk J:

J:\mindprod\jgloss\refactoring.html
Canadian Mind Products
Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

IP:[65.110.21.43]
Your face IP:[44.222.149.13]
You are visitor number