Nice work, as you said "bad code", maybe I could share some of my work experience. Might help a bit to make your code more readable and better to maintain:
When I come back to home, will check it in mono if it works (eventually contribute in it for linux server functionality).
Uhhhh.... code moding xD
- One class, one functionality. I recommend moving https://cryolite.s-ul.eu/gc6Xs6YC.png from Data.cs (same for Osu.cs) into another class files. It is issue often made by programmers and mentioned in S.O.L.I.D. principles of C# programming.
- Logging:
Performance wise your solution isn't good, I could recommend something like:
This doesn't need to be disposed.
- Don't set variable type for constructor if its not needed, instead use "var" keyword. Compiler will automatically add type depends on output.
For example:
Instead of
Random rand = new Random();
use
var rand = new Random();
- Resources should be either manually disposed or used within "using" statement (which take care of disposing automatically) + closed (Data.cs,Line:19 StreamReader is not closed, nor disposed).
- Usage of arrays is last thing to do. NET. gives enough tools to avoid them (IEnumerable, List, Manually created Linked list, Dictionary etc)
- In the future consider making a XML/JSON/Text config file where user could put his API key instead of hard coding it.
- You can return values directly without implementing additional variable at some points.
- Naming, naming and one more time naming - use one solid convention which you follow for whole project. Using undertable in normal variables in same time with method props is a big no no. Pascal casing for methods, camel casing for variables, if you are new to programming, I could recommend sticking with globally used naming convention.
That is all to make this code looking way better. Wish it helps you maintain future projects, with time you will gain a lot of experience where you will notice that something can be made easier.
Have fun, coding is life, you will like it if you sit more and code every day.
- Logging:
Performance wise your solution isn't good, I could recommend something like:
var logText = new StringBuilder();
logText.Append($"{variable}");
File.AppendAllText(logFilePath, logText.ToString());
logText.Clear();
This doesn't need to be disposed.
- Don't set variable type for constructor if its not needed, instead use "var" keyword. Compiler will automatically add type depends on output.
For example:
Instead of
Random rand = new Random();
use
var rand = new Random();
- Resources should be either manually disposed or used within "using" statement (which take care of disposing automatically) + closed (Data.cs,Line:19 StreamReader is not closed, nor disposed).
- Usage of arrays is last thing to do. NET. gives enough tools to avoid them (IEnumerable, List, Manually created Linked list, Dictionary etc)
- In the future consider making a XML/JSON/Text config file where user could put his API key instead of hard coding it.
- You can return values directly without implementing additional variable at some points.
- Naming, naming and one more time naming - use one solid convention which you follow for whole project. Using undertable in normal variables in same time with method props is a big no no. Pascal casing for methods, camel casing for variables, if you are new to programming, I could recommend sticking with globally used naming convention.
That is all to make this code looking way better. Wish it helps you maintain future projects, with time you will gain a lot of experience where you will notice that something can be made easier.
Have fun, coding is life, you will like it if you sit more and code every day.
When I come back to home, will check it in mono if it works (eventually contribute in it for linux server functionality).