DFRefactor modernizes DataFlex source code. It reads your existing source code, finds code that should be written differently in a newer DataFlex version, or that the newer version no longer accepts, and rewrites it. The changes are made automatically, in many files at a time, and they can be undone.

It is written entirely in DataFlex, and is distributed as freeware under an MIT license.


What it is for

Old DataFlex code continues to compile for a very long time. That is a strength of the language, but it also causes a problem: a workspace can contain code that was replaced two or three releases ago and still compile without any messages.

When you move the workspace to a newer DataFlex version, such code ends up in one of three situations:

  • It no longer compiles. Calls and commands that earlier releases accepted have been removed, and the compiler reports an error for each of them. These errors block the migration: until all of them are fixed, the program cannot be compiled or run. This is usually most of the work in a version move, and DFRefactor does this work for you: it links each error to the function that fixes it and shows all of them in one list, so that you do not have to find them one compile at a time.
  • It compiles, but with warnings. The code is still accepted, but the compiler recommends writing it differently. A warning in this release often becomes an error in the next one.
  • It compiles without any messages. The code is obsolete, but the compiler does not report it. Compiling will never point you to it, which is why DFRefactor also scans the source code directly.

DFRefactor finds all three kinds. This turns the move to a current DataFlex version into a series of small steps that you review, instead of one long manual job where the compiler only shows you the next problem.

DFRefactor does not restructure your application, rename your objects or make design decisions. Every change it makes is one that a careful developer would make by hand, and it is made in the same way everywhere.


The programs

DFRefactor is the program you work with. The other programs are helper programs:

  • DFRefactor — the application. Everything in this help refers to it.
  • TestBench — a tool for developing and testing your own refactoring functions. It also contains the JSON Export/Import feature for sharing them. Only needed if you write your own functions; see Welcome to DFRefactor.
  • UnitTests — runs the unit tests for DFRefactor's function library. It is included so that you can run the tests yourself. It is not needed for refactoring.
  • DUFUpdateProgram — updates DFRefactor's database. DFRefactor starts it automatically when its tables need to be updated; you never start it yourself.


Two ways of working

On the Start Center you choose how to work, and you can switch at any time:

  • Guided refactor — DFRefactor decides what to run. One Check compiles your program and scans the source code. It then shows one list of findings, sorted by how serious they are, with the errors that stop the compile at the top. You approve a plan, and the plan is run.
  • Manual refactor — you decide. You select the folders and the functions, and run them. No compile is needed. This works best when you already know what you want to change, for example one cleanup pass, one function on one folder, or a new run after you have edited code by hand.

Both ways use the same refactoring engine; they are not separate programs. See How to use the Program.


How it finds work

DFRefactor uses two separate methods to find code that needs changing, because neither method finds everything:

  • Compile and analyze — DFRefactor compiles your program with the compiler of the DataFlex version you are moving to. It then links each error and warning to the refactoring function that fixes it. This finds the code that the compiler reports; when you move to a new version, these are mostly errors.
  • Analyze Source — scans your source code directly for obsolete commands, functions and classes. This finds obsolete code that still compiles without any messages, which compiling would never show.

A guided Check uses both methods and combines the results in one list. Each round is recorded, so you can see the number of findings go down from one round to the next — see Modernization Progress.


Nothing is changed without your approval

  • The findings are turned into a plan that you review before any file is changed. The plan shows which functions will run, the setting of each function, and every file that each function will change.
  • Read Only runs everything and reports what would have been changed, without changing any files.
  • Before a run changes a file, the file is copied to a DFRefactor Backup folder in the workspace's home folder. Compare Source shows the differences, and Revert restores the original files. See Program Settings for how long backups are kept.


Which DataFlex versions

DFRefactor officially supports the two most recent major DataFlex releases — currently DataFlex 25 and 26. Older releases may work, but are not supported.

This applies to the version you are moving to. The workspace you open can be much older. You select the compiler of the version you are moving to, and that version decides which refactoring functions your workspace needs, and which of its code is no longer valid.


Unattended use

The complete configuration (workspace, folders, file filter and selected functions) can be exported to an ini-file and run from the command line without user interaction. This makes it possible to use DFRefactor in a build script or a CI job. See Command-Line Usage.


A note on Editor functions

Functions of type Editor — One File (EditorReIndent, EditorNormalizeCase) use the Scintilla editor control, which is an OCX and must be visible to work. When a run includes one of these functions, DFRefactor shows the editor view automatically, so the editor comes to the front during the run.


For a step-by-step walkthrough see How to use the Program; for what each function does, Refactoring Functions; and for how the engine works, How It All Works.