OK. Say my current algo is:

1
2
3
4
5
6
7
function func_a() {
// 100 lines of code
}
if (a==0) {
// call func_a
a();
}


Now, I want to introduce another variable 'b' which will be contributing for calling of another function func_b as like
1
2
3
4
5
6
7
function func_b() {
// 100 lines of code
}
if (b == 0) {
// call func_b
b();
}


OK. Now the point is these 100 lines of code between two functions i.e. func_a and func_b, is almost same. Almost 90 lines are same as like:

1
2
3
4
5
function a() {
// Some 80 odd lines
// 10 lines are different now.
// Same 10 lines
}


I hope it is clear until now. Question is:
Is there any way to share this code between two functions. I can think of three options as of now:
1) Forget everything and live with it.
2) Pass some param.
3) Do something with function pointers.

I do not want to implement option no. 2 since it is possible that later I will introduce another param. How can function pointers or something else work here?

Anyone up for challenge?


- Hemant