mtbc: maze I (white-red)
[personal profile] mtbc
Sometimes I change a bunch of code, get my changes working, then tidy up my mess, even working from the resulting large diff to recreate a series of commits that capture simpler logical steps. In thinking about some code reorganization yesterday I noticed that it includes activities that could be amenable to automated analysis:

  • Recognizing clusters of state variables that are repeatedly affected with various inputs; perhaps that state can be broken out into a separate object and few methods may be needed to capture that mutation.

  • Relatedly, recognizing similar code and breaking it out into a helper function. Last week this included an optional bit of code I turned into an optional parameter for such a function.

  • Recognizing when a bunch of variables are read then written, then a bunch more are, with those later reads not depending on the previous writes: these could well be logically distinct blocks of code that at the least deserve separating with comments.

Broadly I have the sense that things are going well if my code size is reducing and the average amount of in-scope state is also reducing: then I am mostly left with having to name the subparts. Those measures are among my proxies for if each part of the code is more easily understood and easier to write tests for. I can imagine that there has probably been some active research into the question of automated code tidying to make it clearer though analyzing data dependency patterns, detecting similar code and characterizing its differences, etc. I wonder if it has got anywhere.

This was especially in my mind over the past couple of weeks as I have had to repeatedly refactor some Java code: the extensions and changes I wanted to make turned out not to at all fit well into how state was previously distributed across classes so some exploratory rearchitecting was required and that came with an intermediate step where I did not bother to write tidily until I saw that the new approach worked at all; only then did I spend the extra effort to try to find orderly patterns in the resulting code.

Profile

mtbc: photograph of me (Default)
Mark T. B. Carroll

June 2025

S M T W T F S
1 2 34567
8 9101112 1314
15161718192021
22232425262728
2930     

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 19th, 2025 04:59 am
Powered by Dreamwidth Studios
OSZAR »