Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26970
| Date | 2013-12-17 12:41 -0500 |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: A little concept puzzle (involving refactoring) |
| References | <refactor-20131217165545@ram.dialup.fu-berlin.de> <52b08b1e$0$299$14726298@news.sunsite.dk> |
| Message-ID | <52b08cd1$0$299$14726298@news.sunsite.dk> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
On 12/17/2013 12:34 PM, Arne Vajhøj wrote:
> On 12/17/2013 11:16 AM, Stefan Ram wrote:
>> Here is a little puzzle about the definition of concepts:
>>
>> /The behavior/ of a program I call what can be observed
>> from the outside by running the program.
>>
>> /A refactor/ I call a modification of the source code of
>> a program that does not change the behavior of the program.
>>
>> Now, let's test these concepts!
>>
>> public class Main
>> { public static void main( final java.lang.String[] args )
>> { final double value = java.lang.Math.random();
>> java.lang.System.out.println( value ); }}
>>
>> 0.8262472065326088
>>
>> Now apply the modification
>> »renameLocalVariable("value","number")«:
>>
>> public class Main
>> { public static void main( final java.lang.String[] args )
>> { final double number = java.lang.Math.random();
>> java.lang.System.out.println( number ); }}
>>
>> 0.4774192830734339
>>
>> The behavior has changed - so that was not a refactor!
>>
>> Should we see it this way or modify our definitions?
>>
>> PS: Here's a quotation from the book »Refactoring« by Martin
>> Fowler at al.:
>>
>> »Refactoring is the process of changing a software
>> system in such a way that it does not alter the external
>> behavior of the code yet improves its internal structure.«
>
> You did not change the behavior of the program.
>
> Behavior is really:
> output = behavior(input)
>
> You changed the input (the default seed of Random) and got
> a different output.
>
> The behavior is the same as you would get the same output
> with the same input.
This leads to the point that if you want to write unit testable
code, then you should use the constructors that takes the seed
as argument to enable you to unit test that your refactoring
did not change behavior.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: A little concept puzzle (involving refactoring) Arne Vajhøj <arne@vajhoej.dk> - 2013-12-17 12:34 -0500 Re: A little concept puzzle (involving refactoring) Arne Vajhøj <arne@vajhoej.dk> - 2013-12-17 12:41 -0500
csiph-web