It occurred to me that there must be a general process by which a
programmer refactors code.

Was wondering if it has ever been attempted to codify this process.

Take this program for example ...

http://re-factor.blogspot.com/2013/04/move.html

: usage ( -- )
    "Usage: move source ... target" print ;

: move-to-dir ( args -- )
    dup last file-info directory?
    [ unclip-last move-files-into ] [ drop usage ] if ;

: move-to-file ( args -- )
    dup last file-info directory?
    [ move-to-dir ] [ first2 move-file ] if ;

: run-move ( -- )
    command-line get dup length {
        { [ dup 2 > ] [ drop move-to-dir  ] }
        { [ dup 2 = ] [ drop move-to-file ] }
        [ 2drop usage ]
    } cond ;

We could factor out ''last file-info directory?'' into a word ...

: usage ( -- )
    "Usage: move source ... target" print ;

: target-is-directory? ( args -- ? )
    last file-info directory?

: move-to-dir ( args -- )
    dup target-is-directory?
    [ unclip-last move-files-into ] [ drop usage ] if ;

: move-to-file ( args -- )
    dup target-is-directory?
    [ move-to-dir ] [ first2 move-file ] if ;

: run-move ( -- )
    command-line get dup length {
        { [ dup 2 > ] [ drop move-to-dir  ] }
        { [ dup 2 = ] [ drop move-to-file ] }
        [ 2drop usage ]
    } cond ;

If refactoring of code may be obvious to a human, it might also be done by
an algorithm.

Or is this similar to something that already exists in the optimizing
compiler?

 - Leonard
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to