[fpc-devel] OO rewrite - technical questions

Aleksa Todorovic alexione at gmail.com
Mon Jul 19 12:48:51 CEST 2010

On Mon, Jul 19, 2010 at 12:29, Hans-Peter Diettrich
<DrDiettrich1 at aol.com> wrote:
> The directive list contains records with the name and other attributes of
> every directive, and with a reference to the directive handler procedure.
> These handler procedures need further information, that currently resides in
> global variables. In an OO approach these variables become class members, so
> that an additional reference to a concrete object is required in the
> directive handlers.
> In so far "class procedure" doesn't help, if you meant that, because Self in
> a class procedure is the class type, not a class instance.
> It's also useless to create new classes, because the handlers need access to
> the elements in a concrete parser/scanner class (instance).

Why don't you separate refactoring in several steps:

1) First, you replace all global variables with class members, and as
much as you can (global) procedures with class methods. You also add
one global Parser (or whatever you call it) variable, and replace
those "problematic" procedures with wrappers. Something like:

function f(...)
  Result := Parser._f(...)

This will result is nicer commit. You can even put wrappers just in
front of wrapped methods (in the above example, function TParser._f
would go just after function f). You'll probably need to add
underscore or some other character at the beginning of wrapped names
so you can still reference f from TParser methods.

2) After this, you should have parser which is still fully functional,
but uses only one global variable - Parser - in wrapping functions. At
that moment, you can analyze further refactoring (promoting Parser to
parameter of wrapping functions, or some other solution), and even
test them without having to deal with huge commits.

Just an idea...

More information about the fpc-devel mailing list