Dear Manchester Software Consultant,
..... I find when I'm writing code that my functions end up being longer than is easily manageable. Now I am approaching the task of building from scratch a project which is much larger than anything I have taken on before. Could you give me some advice on how I might approach this?
Generally speaking you make functions smaller by taking pieces of those functions and isolating them off... as functions!
I see looking at the code sample you sent me, that what you have done by separating out your function “check_object” as a separate function is a perfect example of this.
However, the key thing I notice from what you've told me is that you appear to be coding without having a plan for the design of your application.
What you need here is not lessons in C# - what you need is a plan.
It’s a mistake to think that coding is the significant aspect of programming. That is like thinking brick-laying is the significant aspect of house building. Obviously you need brick-laying, and you want it to be as good as possible, but ultimately it’s not very important.
What is much more important is the positioning of walls, where you put doors and corridors, how many rooms and how they connect.
Coding is similarly not very important! Yes, you can do it better, and you can do it worse, but as long as your coding walls stay standing what is much more significant is the design of your program building.
I would recommend that before you do any more coding, make a plan of all your classes, and the properties and methods, (variables and functions) they are going to have.
Write this down!
So for each class specify what its variables and functions are.
For each class level variable, specify what its datatype is going to be and the range of values it should take.
Then for each function you should specify what parameters it takes the data types of these, and what the return type is and write a description of what the function does.
Once you have this you have your whole application already figured out, before you write a single more line of code.
When you have the plan in place, draw some schematics of how these classes interact with each other.
With the plan and schematics in place you can see whether there is a better way to do any of what you are meaning to achieve, without having to re-write lots of code.
You may want to re-write the plan 2 or 3 times before you even start coding. Changing the plan is much easier than changing the code.
That’s why you make a plan!