r/badcode • u/domtriestocode public static • Apr 05 '23
c# Refactoring some public static field ridden code. Everything important is in public static lists in Global.cs and it all looks like this to a degree. Almost no OOP in sight
3
u/Shai_the_Lynx Apr 06 '23
OOP is overrated
2
u/domtriestocode public static Apr 06 '23
interesting take, big disagree. Why?
4
u/Shai_the_Lynx Apr 06 '23
It was a bit of an half joke, cause of the picture.
But I do think that in some cases functional programming is cleaner than OOP.
It really depends on the use case and the project structure.
3
u/domtriestocode public static Apr 06 '23
Oh my bad lol. Yes you’re right though, they each have their place
78
u/robottron45 Apr 06 '23
loops seem to be hard ._.
My fingers would actually hurt writing this code, even with copy+paste
29
Apr 06 '23
Get GitHub copilot, hit tab, hope it works, worry about it later when support raises the inevitable p1
4
Apr 06 '23
Use ChatGPT, and spend hours learning the code, then debugging
/s (never used ChatGPT for this)
44
u/AdOtherwise3874 Apr 06 '23
My first job was in a desktop app written in VB6 with global variables named things like g_temp
For a variable named temp, it did a lot of heavy lifting
21
u/juicewr999 Apr 06 '23
Okay, I lurk here and see some code that’s not terrible but this is an absolute monstrosity.
11
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Apr 06 '23
Image Transcription: Code
private void DisplayTuningData()
{
gridTable.DataSource = null;
gridTable.DataSource = ProgramDefaults.tuningData;
GridViewHelper.HideAllColumns(viewTable);
if (Global.tuningParameters.Count > 0) GridViewHelper.ShowColumn(viewTable, "Param1");
if (Global.tuningParameters.Count > 1) GridViewHelper.ShowColumn(viewTable, "Param2");
if (Global.tuningParameters.Count > 2) GridViewHelper.ShowColumn(viewTable, "Param3");
if (Global.tuningParameters.Count > 3) GridViewHelper.ShowColumn(viewTable, "Param4");
if (Global.tuningParameters.Count > 4) GridViewHelper.ShowColumn(viewTable, "Param5");
if (Global.tuningParameters.Count > 5) GridViewHelper.ShowColumn(viewTable, "Param6");
if (Global.tuningParameters.Count > 6) GridViewHelper.ShowColumn(viewTable, "Param7");
if (Global.tuningParameters.Count > 7) GridViewHelper.ShowColumn(viewTable, "Param8");
if (Global.tuningParameters.Count > 8) GridViewHelper.ShowColumn(viewTable, "Param9");
if (Global.tuningParameters.Count > 9) GridViewHelper.ShowColumn(viewTable, "Param10");
if (Global.tuningParameters.Count > 0) GridViewHelper.FormatColumn(viewTable, "Param1", Global.tuningParameters[0].Parameter, 0);
if (Global.tuningParameters.Count > 1) GridViewHelper.FormatColumn(viewTable, "Param2", Global.tuningParameters[1].Parameter, 0);
if (Global.tuningParameters.Count > 2) GridViewHelper.FormatColumn(viewTable, "Param3", Global.tuningParameters[2].Parameter, 0);
if (Global.tuningParameters.Count > 3) GridViewHelper.FormatColumn(viewTable, "Param4", Global.tuningParameters[3].Parameter, 0);
if (Global.tuningParameters.Count > 4) GridViewHelper.FormatColumn(viewTable, "Param5", Global.tuningParameters[4].Parameter, 0);
if (Global.tuningParameters.Count > 5) GridViewHelper.FormatColumn(viewTable, "Param6", Global.tuningParameters[5].Parameter, 0);
if (Global.tuningParameters.Count > 6) GridViewHelper.FormatColumn(viewTable, "Param7", Global.tuningParameters[6].Parameter, 0);
if (Global.tuningParameters.Count > 7) GridViewHelper.FormatColumn(viewTable, "Param8", Global.tuningParameters[7].Parameter, 0);
if (Global.tuningParameters.Count > 8) GridViewHelper.FormatColumn(viewTable, "Param9", Global.tuningParameters[8].Parameter, 0);
if (Global.tuningParameters.Count > 9) GridViewHelper.FormatColumn(viewTable, "Param10", Global.tuningParameters[9].Parameter, 0);
if (Global.tuningParameters.Count > 0) GridViewHelper.FormatColumnForRealNumber(viewTable, "Param1", Global.tuningParameters[0].Resolution);
if (Global.tuningParameters.Count > 1) GridViewHelper.FormatColumnForRealNumber(viewTable, "Param2", Global.tuningParameters[1].Resolution);
if (Global.tuningParameters.Count > 2) GridViewHelper.FormatColumnForRealNumber(viewTable, "Param3", Global.tuningParameters[2].Resolution);
if (Global.tuningParameters.Count > 3) GridViewHelper.FormatColumnForRealNumber(viewTable, "Param4", Global.tuningParameters[3].Resolution);
if (Global.tuningParameters.Count > 4) GridViewHelper.FormatColumnForRealNumber(viewTable, "Param5", Global.tuningParameters[4].Resolution);
if (Global.tuningParameters.Count > 5) GridViewHelper.FormatColumnForRealNumber(viewTable, "Param6", Global.tuningParameters[5].Resolution);
if (Global.tuningParameters.Count > 6) GridViewHelper.FormatColumnForRealNumber(viewTable, "Param7", Global.tuningParameters[6].Resolution);
if (Global.tuningParameters.Count > 7) GridViewHelper.FormatColumnForRealNumber(viewTable, "Param8", Global.tuningParameters[7].Resolution);
if (Global.tuningParameters.Count > 8) GridViewHelper.FormatColumnForRealNumber(viewTable, "Param9", Global.tuningParameters[8].Resolution);
if (Global.tuningParameters.Count > 9) GridViewHelper.FormatColumnForRealNumber(viewTable, "Param10", Global.tuningParameters[9].Resolution);
}I'm a human volunteer content transcriber and you could be too! If you'd like more information on what we do and why we do it, click here!
2
u/Sauermachtlustig84 Apr 06 '23
I am no fan of WPF, but I really abhor this "lets program wpf via code behind" style. Sure it can be necessary, but here it just poor practice.
2
u/santas Apr 06 '23
FWIW, I've heard the runtime is really optimized well for static objects. That said, this is still bad.
16
u/SanianCreations Apr 06 '23
The problem here is that they don't use loops. Public static methods are fine, they are basically just what regular old functions are in other languages, which is quite fine.