Refactoring - School of Informatics - University of Edinburgh
Recommend Documents
(If the view overlapped, then standard stereo auto-calibration can be used.) This paper shows that the problem is solveable. Distant moving features.
Learning in a State of Confusion: Perceptual Aliasing in Grid World. Navigation by ..... the top right hand corner (indicated by an asterisk). An agent in this world ...
Transferring Impedance Control Strategies via Apprenticeship ... a key ingredient, we use apprenticeship learning to model the optimisation criteria underlying ...
(modulo equality) in the initial program state, we must throw away those states that don't contain the object. (2) Observe: Make an arbitrary observation. The user ...
S. I. T. Y. O. F. E. DI N B U. R. G. H. School of Informatics, University of Edinburgh ...... In David Touretzky, editor, Advances in Neural Information Processing ...
and can be found at: http://www.dai.ed.ac.uk/homes/rbf/publications.html. ... General shape knowledge can allow recovery even when data is very noisy, sparse ...
on-line and for free, a web-based system with access to relevant cases in digital ..... The builders of Split Up found that rule-based reasoning was only of limited ..... The complete text of the Family Law (Scotland) 1985 is available in the system.
March 2004 http://www.informatics.ed.ac.uk/ ... 1This work forms part of the Hydra project, funded by the EU Information Society Technologies (Future and.
Mar 31, 2009 - functionality; an example being the Motion Builder plug-in, developed by Paul. McEwan ... Moreover, this application utilised a custom scoring.
Ph.D. in Informatics, The University of Edinburgh, 2004 ...... MIT Press, 1995. ... âConstraint Diagram Reasoningâ unpublished paper, available online at the.
20 Jan 2011 ... Cryptography II: Hash Functions. Computer Security Lecture 4. David Aspinall.
School of Informatics. University of Edinburgh. 20th January ...
For example, the following is a valid Prolog program containing. 3 clauses (1 per
... All Prolog clauses are terms finishing with a full stop symbol. Prolog clauses ...
We introduce the arrow calculus, a metalanguage for manipulating Hughes's
arrows ... Arrows are classically defined by extending lambda calculus with three
...
Institute of Perception, Action and Behaviour ... (If the view overlapped, then standard stereo auto-calibration ... Mechanical structures could probably en-.
of the modellers in building a model, verifying and validating it, and finding and ... A good business model also helps software engineers to come to a better ...
Strict General Setting for Building Decision Procedures into Theorem. Provers by. Predrag Janicic, Alan Bundy. Informatics Research Report EDI-INF-RR-0097.
Jul 18, 2000 - figure 1, was a 2.4 metre square bounded by wooden black walls 100 mm high. A central gray line dowel divided the pitch in two parts.
Feb 29, 2000 - Joanna Tomasik-Krawczyk, Jane Hillston. Informatics Research Report ...... a stop at a service station when going from the rank to the market.
We describe the development of a Java bytecode optimisation algorithm by the methodology of ..... against the spirit of extraction where, ideally, the computa-.
A recent article (Jennings, 2001) argues that the agent paradigm is a good way of .... enforcement mechanisms for mobility policies, domain registration policies, ...
W. Marco Schorlemmer1, Stephen Potter1, David Robertson1, and Derek Sleeman2. 1 Centre for Intelligent ..... N. Carreiro and D. Gelernter. Linda in context.
http://www.informatics.ed.ac.uk/ ... {helmutc,rbf}@dai.ed.ac.uk, [email protected]. Abstract ..... [14] C. Robertson, R.B. Fisher, N. Werghi, and A. Ashbrook. Fitting of ...
Refactoring - School of Informatics - University of Edinburgh
Refactoring. Refactoring is the process of re-organizing and re-writing code so ...
There are many examples; for a catalogue from Martin Fowler's original book ...
Refactoring Paul Jackson School of Informatics University of Edinburgh
Refactoring definition Refactoring (noun) is a change made to the internal structure of software to make it I
easier to understand, and
I
cheaper to modify
without changing its observable behaviour Refactor (verb) to restructure software by applying a series of refactorings without changing its observable behaviour Fowler, Refactoring, 2000 Refactoring (noun) also used to refer to the general activity
2 / 15
Why refactor?
I
Improves design of software I
I
As code evolves its structure naturally decays
Makes software easier to understand I
Both code you write and code others write
I
Helps you find bugs
I
Helps you program faster I
Poor design slows you down
3 / 15
When to refactor? Refactoring was once seen as a kind of maintenance. . . I
You’ve inherited legacy code that’s a mess.
I
A new feature is required that necessitates a change in the architecture.
But can also be an integral part of the development process Agile methodologies (e.g. XP) advocate continual refactoring (XP maxim: “Refactor mercilessly”).
4 / 15
What does refactoring do? A refactoring is a small transformation which preserves correctness. There are many examples. For a catalogue of over 90 assembled by Martin Fowler, see http://refactoring.com/catalog/. A sample: I
Add Parameter
I
Change Bidirectional Association to Unidirectional
to final boolean isMacOs = platform.toUpperCase().indexOf("MAC") > -1; final boolean isIEBrowser = browser.toUpperCase().indexOf("IE") > -1; final boolean wasResized = resize > 0; if (isMacOs && isIEBrowser && wasInitialized() && wasResized) { // do something } 6 / 15
Replace Conditional with Polymorphism I Change
double getSpeed() { switch (_type) { case EUROPEAN: return getBaseSpeed(); case AFRICAN: return getBaseSpeed() - getLoadFactor() * _numberOfCoconuts; case NORWEGIAN_BLUE: return (_isNailed) ? 0 : getBaseSpeed(_voltage); } throw new RuntimeException ("Should be unreachable"); }
7 / 15
Replace Conditional with Polymorphism II to
8 / 15
Eclipse Refactoring
Eclipse has a built-in refactoring tool (on the Refactor menu).
Many of its refactoring operation can be grouped in three broad classes . . .
9 / 15
Eclipse Refactoring I: Renaming and physical reorganization A variety of simple changes. For example: I
Rename Java elements (classes, fields, methods, local variables) I I
I
On class rename, import directives updated On field rename, getter and setter methods also renamed
Move classes between packages
Eclipse applies these changes semantically I
Much better than syntactic search-and-replace
10 / 15
Eclipse Refactoring II: Modifying class relationships
Heavier weight changes. Less used, but seriously useful when they are used. E.g. I
Move methods or fields up and down a class inheritance hierarchy.
I
Extract an interface from a class
I
Turn an anonymous class into a nested class
11 / 15
Eclipse Refactoring III: Intra-class refactorings
The bread-and-butter of refactoring: rearranging code within a class to improve readability etc. E.g. I
Extract Method: pull method code block into new method. I I
Good for shortening method or making block reusable Also can extract local variables and constants
I
Encapsulating fields in accessor methods.
I
Change the type of a method parameter or return value
12 / 15
Safe refactoring
How do you know refactoring hasn’t changed/broken something? Perhaps somebody has proved that a refactoring operation is safe. More realistically: test, refactor, test This works better the more tests you have: ideally, unit tests for every class.
13 / 15
Bad smells in code
I
Duplicated code
I
Long method
I
Large class
I
Long parameter list
I
Lazy class
I
Long message chains
Smell documentation explains how to recognise them and what refactorings can help.
14 / 15
Reading Required: The article ‘Refactoring for everyone’ at http://www.ibm.com/developerworks/opensource/ library/os-ecref/. Aim to remember: what refactoring is, and a few examples, not the details of the refactorings discussed here. Suggested: Look at the Reference - Refactor Actions section of the Eclipse Java development user guide for full information on Eclipse’s current capabilities. Suggested: Browse around Fowler’s page at http://refactoring.com/. Some of his book Refactoring is available on Google Books e.g., details of some of the refactorings in the catalogue. Suggested: Search code smells. One catalogue can be found at http://wiki.c2.com/?CodeSmell. 15 / 15