Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #26996

Re: A little concept puzzle (involving refactoring)

From Daniel Pitts <newsgroup.nospam@virtualinfinity.net>
Newsgroups comp.lang.java.programmer
Subject Re: A little concept puzzle (involving refactoring)
References <refactor-20131217165545@ram.dialup.fu-berlin.de>
Message-ID <3wIsu.5892$543.1458@fx02.iad> (permalink)
Date 2013-12-19 12:18 -0800

Show all headers | View raw


On 12/17/13 8: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.«
>
Behavior and outcome are not the same thing. You're preconditions are 
different, and therefor your test is invalid.

  Math.random() explicitly uses 
http://docs.oracle.com/javase/7/docs/api/java/util/Random.html#Random(), 
which implicitly takes "time" as a precondition.

Back to comp.lang.java.programmer | Previous | Next | Find similar | Unroll thread


Thread

Re: A little concept puzzle (involving refactoring) Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2013-12-19 12:18 -0800

csiph-web