improving add parameter refactoring

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

improving add parameter refactoring

Stephane Ducasse-3
Hi john

I'm facing the following situation and I was wondering if a simple heuristic could not improve the situation (where edge cases will always be a problem).

I got a hierarchy of expressions implementing evaluate and I wanted to add a parameter (the binding). So Add Parameter worked but broke evaluate recursive methods. 
Here is a part of the book I'm writing


[[[ 
EConstant >> testEvaluate 
self assert:(EConstant new value: 5) evaluate equals: 5
]]] 

is transformed as follows: 
[[[
EConstant >> testEvaluate
self assert: ((EConstant new value: 5) evaluateWith: Dictionary new) equals: 5
]]]

Your tests should nearly all pass except the ones on variables. Why do they fail?
Because the refactoring transformed message sends ==evaluate== but ==evaluateWith: Dictionary new== and this even in methods ==evaluate==. 

[[[
EAddition >> evaluateWith: anObject
^ (right evaluateWith: Dictionary new) + (left evaluateWith: Dictionary new)
]]]

[[[
EAddition >> evaluateWith: anObject
^ (right evaluateWith: anObject) + (left evaluateWith: anObject)
]]]


And I was wondering if a good heuristic would be to change the parameter. 
Now I have the impression that the refactoring is done it two passes. 
So this is more tricky than it looks. 

Stef
Reply | Threaded
Open this post in threaded view
|

Re: improving add parameter refactoring

Denis Kudriashov
Hi.

Just to know, Eclipse does it right for recursions in java. It puts new argument in recursive call

2017-01-05 9:15 GMT+01:00 Stephane Ducasse <[hidden email]>:
Hi john

I'm facing the following situation and I was wondering if a simple heuristic could not improve the situation (where edge cases will always be a problem).

I got a hierarchy of expressions implementing evaluate and I wanted to add a parameter (the binding). So Add Parameter worked but broke evaluate recursive methods. 
Here is a part of the book I'm writing


[[[ 
EConstant >> testEvaluate 
self assert:(EConstant new value: 5) evaluate equals: 5
]]] 

is transformed as follows: 
[[[
EConstant >> testEvaluate
self assert: ((EConstant new value: 5) evaluateWith: Dictionary new) equals: 5
]]]

Your tests should nearly all pass except the ones on variables. Why do they fail?
Because the refactoring transformed message sends ==evaluate== but ==evaluateWith: Dictionary new== and this even in methods ==evaluate==. 

[[[
EAddition >> evaluateWith: anObject
^ (right evaluateWith: Dictionary new) + (left evaluateWith: Dictionary new)
]]]

[[[
EAddition >> evaluateWith: anObject
^ (right evaluateWith: anObject) + (left evaluateWith: anObject)
]]]


And I was wondering if a good heuristic would be to change the parameter. 
Now I have the impression that the refactoring is done it two passes. 
So this is more tricky than it looks. 

Stef