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.
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)
recommend book⇒Refactoring Workbook | ||||
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. | ||||
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder. |
recommend book⇒Refactoring: Improving the Design of Existing Code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder. |
recommend book⇒Code Complete: A Practical Handbook of Software Construction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Greyed out stores probably do not have the item in stock. Try looking for it with a bookfinder. |
This page is posted |
http://mindprod.com/jgloss/refactoring.html | |
Optional Replicator mirror
|
J:\mindprod\jgloss\refactoring.html | |
Please read the feedback from other visitors,
or send your own feedback about the site. Contact Roedy. Please feel free to link to this page without explicit permission. | ||
Canadian
Mind
Products
IP:[65.110.21.43] Your face IP:[3.141.19.249] |
| |
Feedback |
You are visitor number | |