On the dangers of automated refactoring

Curry Kenworthy curry at pair.com
Thu Apr 15 17:32:42 EDT 2021


Andre:

 > I like verbose code that is full of comments.

Ah yes, comments are good! But comments do not make code verbose.
Terse code can be heavily commented, and vice versa.
Commenting is not closely related to my issue, nor perhaps to yours.

Me:

 > But there's an even bigger danger than the one already described:
 > If a script needs many repeated changes to fix a single problem,
 > usually that's because the code was not well-organized and modular.

Among all truly gigantic scripts that perform simple tasks,
usually you find habits of repetitive typing/pasting the same code.

For example, some people like to write out iterations themselves,
rather than using a repeat loop! It's like doing all the leg work.
"Hey Mr. Computer, let me do that for you!" But it creates problems.

Other people take a block of code or a handler for a task, copy it,
paste it, and make a few modifications again for a similar task.
And again. And again. Until there are dozens of similar blocks.

That works great until a problem shows up in one of the blocks.
After fixing it, congrats; only 49 other similar blocks to evaluate!

Each may require the same fix, or a slightly different fix, or none;
because each repeated code block or handler is a unique variation.
This turns what should be a tiny change into a mammoth undertaking. :)

Those are the habits that come back to haunt people later.
They are easy to avoid with good habits, harder to fix down the road!
That's why I'm careful to frequently warn about keeping code modular.

 > Trying a "rename symbol” kind of procedure that acts on the
 > whole script, might end up renaming the wrong variables.

I agree; it's a problem. Each portion of a script should be handled
with caution, with awareness of context, and with backups in place.
Keyhole surgery, first do no harm, are my approach to operating on code.

Good topic! Back to work....

Best wishes,

Curry Kenworthy

Custom Software Development
"Better Methods, Better Results"
LiveCode Training and Consulting
http://livecodeconsulting.com/




More information about the use-livecode mailing list