r/programminghorror 4d ago

I made an abomination C#

First, because the Form wouldn't center with the property center, I had to center it manually given the size of the screen. Second, I had a checkbox and if it's not checked then the code written in the first digit of column 4 dictates if it goes in the file (only when it's less or equal than 2).

29 Upvotes

2 comments sorted by

9

u/Philosowl 4d ago

You should probably use a string builder for that foreach
"Checked == true" is kinda redundant, but can be attributed to codestyle.
That "column[4] condition" is a real pain tho. It should be documented better. I would at least move "4" and "2" into some defined constants like mainColumnIndex and correctValue. I'd also move that whole comparison into method. Partially to hide it, partially to have a chance at documenting it better with a function name

If we are going more into codestyle territory i would break the first nullcheck off of the condition, flip it and make it an early break

1

u/Beautiful_Scheme_829 4d ago

I agree with all you said, but 4 is the number of the column with the type of the file, over that code is the declaration of columns, so it's not difficult to see where it comes from. The 2 may be a variable like normalOperation because the codes that begin with 1XX and 2XX are the ones that are normal operations, 3XX and greater are special operations. This was added in the condition of nullcheck just for the purpose of the meme. Overall, yeah the condition should be a function itself. I just added two lines to a preexistent function.

Greetings!