Skip to content

Instantly share code, notes, and snippets.

@mausch
Created April 11, 2014 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mausch/10442035 to your computer and use it in GitHub Desktop.
Save mausch/10442035 to your computer and use it in GitHub Desktop.
class MyOld5700LoCBusinessClass { // actually 5715 lines
bool flag1, flag2, ..., flag15;
string message1, message2, ... message15;
// more instance variables
void Method1() {...}
...
void Method30() {...}
void Method31() {
// 1000 lines of code mutating many instance variables and reading others. Grossly simplified here to illustrate the concept.
flag4 = true;
flag6 = false;
message4 = "hello";
if (flag5) message5 = "byebye";
}
// more methods
}
Refactor Method31 to:
static void Method31(bool flag5, out bool flag4, out bool flag6, out string message4, ref string message5) {
flag4 = true;
flag6 = false;
message4 = "hello";
if (flag5) message5 = "byebye";
}
void Method31() {
Method31(flag5: flag5, flag4: out flag4, flag6: out flag6, message4: out message4, message5: ref message5);
}
Now I can tell more precisely which instance variables Method31 uses and how (read/write)
@vasily-kirichenko
Copy link

Huh. I see. It seems you have to deal with a really awful codebase :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment