❔ How do I make these two codes less copy pasta?
Looking for a way to combine these two to more share code so I don't have to update each every time.
9 Replies
would it be too ugly to add a bool selector to one of the methods and have the other method call it with the flag set?
alternatively factor it into a separate method and pass in the "thing" or the array offset and a Func<Thing, Position> for the position source
Func
might be the way to go.Just pass a argument for +1
and call Undo() or Redo() from Undo() or redo()
thing.OldPosition
vs thing.NewPosition
hmm
You can change that to into a switch too
or if
that just moves the problem from 2 methods to 1 method with a bunch of switch statements.
yeah you're gonna have either a check or a virtual method call somewhere
func or interface will do the latter, which is going to be a bit slower than a check
you could also do a
x * thing.old + (1 - x) * thing.new
and pass in either a zero or a one, but I think the compiler should see this one through if you go with a checkJust went with an
Action
.Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.