4 ms·
Anecdata: Years ago, I refactored some code written by an inexperienced programmer. It was a multiple-thousand-line Perl CGI script where everything was on the
by majewsky 8y ago
Anecdata: Years ago, I refactored some code written by an inexperienced programmer. It was a multiple-thousand-line Perl CGI script where everything was on the top scope, i.e. there were not really any functions (except for a few one-liners). When this was called out by the lead architect, he improved the script by splitting everything into two functions:
($a, $b, $c, $d, ..., $x, $y, $z) = GetData();
PrintResult($a, $b, $c, $d, ..., $x, $y, $z);
The variables actually had reasonable names, but there were at least 20 of them. He just splitted the code at some random point and all variables that needed to be used in the second half became return values and arguments, respectively.
- lmm 8y agoI'd argue that even that can be a small step in the right direction if there were more than 20 variables at the start - at least now you have an upper bound on how much state from the top half of the code can be being used in the bottom half of the code.
- dagw 8y agoHe just splitted the code at some random point and all variables that needed to be used in the second half became return values and arguments, respectively. I've done basically the same. It's as good a place as any to start getting a handle on the problem, as long as you don't leave it there.