static/instance refactoring.

I have a quite large project with thousands of static methods.  Almost
every method got passed a standard parameter among other things.  I
decided to make them instance methods, and make this parameter an
instance variable of a base class common to nearly everything.

It turned out this refactoring was much messier and time consuming
that I expected.

Perhaps I should have used regexes to find it and remove it as a parm
off every method definition and call, then work backward to add them
back in where needed.  Is there an easy way to do a bulk cleanup like
this?

In the process, I noticed a bug in the IntelliJ change signature
refactor. It often totally scrambles parameter lists, seemingly
randomly removing characters.  It gets confused most often when there
is stray Javadoc for a parm that no longer exists.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Capitalism has spurred the competition that makes CPUs faster and
faster each year, but the focus on money makes software manufacturers
do some peculiar things like deliberately leaving bugs and deficiencies
in the software so they can soak the customers for upgrades later.
Whether software is easy to use, or never loses data, when the company
has a near monopoly, is almost irrelevant to profits, and therefore
ignored. The manufacturer focuses on cheap gimicks like dancing paper
clips to dazzle naive first-time buyers. The needs of existing
experienced users are almost irrelevant. I see software rental as the
best remedy.

3 comments

Hello Roedy,

Have you used the "Convert to instance method" refactoring for this purpose,
or something else?

I have a quite large project with thousands of static methods.  Almost
every method got passed a standard parameter among other things.  I
decided to make them instance methods, and make this parameter an
instance variable of a base class common to nearly everything.

It turned out this refactoring was much messier and time consuming
that I expected.

Perhaps I should have used regexes to find it and remove it as a parm
off every method definition and call, then work backward to add them
back in where needed.  Is there an easy way to do a bulk cleanup like
this?

In the process, I noticed a bug in the IntelliJ change signature
refactor. It often totally scrambles parameter lists, seemingly
randomly removing characters.  It gets confused most often when there
is stray Javadoc for a parm that no longer exists.


--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0

On Wed, 2 Nov 2011 15:15:38 +0000 (UTC), Dmitry Jemerov
<yole@jetbrains.com> wrote, quoted or indirectly quoted someone who
said :

>
>Have you used the "Convert to instance method" refactoring for this purpose,
>or something else?

There are so many methods. This is pretty tedious.  I was thinking
about something for bulk changes.

Basically the idea is a variable might be accessed statically, as an
instance or as a final parameter propagated around.  It would nice if
some way to flip between the three, even if the generated code did not
quite compile.  The flip affects many methods simultaneously.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Capitalism has spurred the competition that makes CPUs faster and
faster each year, but the focus on money makes software manufacturers
do some peculiar things like deliberately leaving bugs and deficiencies
in the software so they can soak the customers for upgrades later.
Whether software is easy to use, or never loses data, when the company
has a near monopoly, is almost irrelevant to profits, and therefore
ignored. The manufacturer focuses on cheap gimicks like dancing paper
clips to dazzle naive first-time buyers. The needs of existing
experienced users are almost irrelevant. I see software rental as the
best remedy.

0

On Wed, 2 Nov 2011 15:15:38 +0000 (UTC), Dmitry Jemerov
<yole@jetbrains.com> wrote, quoted or indirectly quoted someone who
said :

>
>Have you used the "Convert to instance method" refactoring for this purpose,
>or something else?

There are so many methods. This is pretty tedious.  I was thinking
about something for bulk changes.

Basically the idea is a variable might be accessed statically, as an
instance or as a final parameter propagated around.  It would nice if
some way to flip between the three, even if the generated code did not
quite compile.  The flip affects many methods simultaneously.
--
Roedy Green Canadian Mind Products
http://mindprod.com
Capitalism has spurred the competition that makes CPUs faster and
faster each year, but the focus on money makes software manufacturers
do some peculiar things like deliberately leaving bugs and deficiencies
in the software so they can soak the customers for upgrades later.
Whether software is easy to use, or never loses data, when the company
has a near monopoly, is almost irrelevant to profits, and therefore
ignored. The manufacturer focuses on cheap gimicks like dancing paper
clips to dazzle naive first-time buyers. The needs of existing
experienced users are almost irrelevant. I see software rental as the
best remedy.

0

Please sign in to leave a comment.