Life sometimes hands you lemons
While I hope you never receive code this bad, we are going to walk through what is needed to turn even this into readable, maintainable, and fully tested code. The best part, the part you aren't going to believe, is that transforming this code is actually safe and fairly easy.
Getting started
In any code situation like this, the first thing we must do is remove the code in question from the environment where we have no control. In this case, we can't test the code if it is sitting in Program.main
. So, let's grab the whole thing and put it into a class named Mastermind
. We will have a single function named Play
that will run the game. This is considered a safe refactoring, because we are not changing any of the existing code, simply moving it somewhere else.
In the file Program.cs
:
class Program { static void Main(string[] args) { var game = new Mastermind(); game.Play(args); } }
In the file Mastermind.cs
:
class Mastermind { public void Play(string...