I mean, you should still rename the buttons so they're not all button1, button2, etc. You still have to reference those buttons and textboxes eventually in your code, and usernameTextbox is a lot better than textbox3.
True. I worked with windows forms for about 3 years. The only time I found that I needed to edit the the designer.cs is when I accidentally created an event I didn’t mean too. Cuz windows forms doesn’t delete the event methods, even if it’s not used. (This is because you dynamically change events)
Edit: I did this instead of going to the designer removing the event and then deleting the method. I found it faster to just remove the method double click on the error and remove the reference from the designer
I'm not really sure that's an excuse. I use code generation to program faster but I don't just leave it in an obviously dog awful mess of generated code.
No, this is literally not meant to be edited by hand except in rare cases like another user pointed out.
There's a gui designer that allows you to design the layouts and styling of all the form components, then this file is generated as a result. The only reason there's a file at all is because the compiler needs smoke kind of source code to compile. It's nothing but a very explicit list of instructions on how to generate each component, which despite not being very pleasant to look at, is the most efficient code for the machine to read and compile.
this.Download = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton1 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton2 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton3 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton4 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton6 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton7 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton8 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneProgressBar1 = new Siticone.Desktop.UI.WinForms.SiticoneProgressBar();
this.siticoneButton5 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton9 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton10 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton11 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton12 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneButton13 = new Siticone.Desktop.UI.WinForms.SiticoneButton();
this.siticoneTextBox1 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox2 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox3 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox4 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox5 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox6 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox7 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox8 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox9 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox10 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox11 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
this.siticoneTextBox12 = new Siticone.Desktop.UI.WinForms.SiticoneTextBox();
The UI part of winforms is wired into those fields, you can't change one side without re-architecting the other side.
I agree the generated code is fine. Additionally, there isn't much of a way to clean up this code, if a program has 20 winforms buttons then there will be 20 button objects somewhere, there's no fixing that and you can't just "use an array".
Is this a template generated thing, a bunch of UI designer changes before removing code behind, or something else? There’s not enough to go on here, because it’s just the UI objects generated by the GUI designer.
Can’t honestly call this bad code without seeing the other parts of the puzzle. Of course GUI designer code is going to look bad at a glance, but that’s just a tiny piece of the picture though.
Yeah, this is pretty bad lol. What is your recommendation? I mean, maybe load the form controls into an array and instantiate a SiticoneButton or SiticoneTextbox based on the form field type?
If I have to do things like this manually, I like to use dictionaries
that way I can just use this.
Dictionary<String index, SiticoneTextBox textBox> buttons = Dictionary<String, SiticoneTextBox>();
int tI = 1;
buttons.Add("siticoneTextBox"+tI,new SiticoneTextBox()); tI++;
buttons.Add("siticoneTextBox"+tI,new SiticoneTextBox()); tI++;
Can also use a for loop instead of the Index++ thing if you want, but I find manually incrementing a bit better for documentation when doing this kind of thing, since quite frankly, it makes remembering what does what a bit of a pain.
161
u/[deleted] Feb 05 '23
Isn't it generated code?
347
u/IBJON Feb 05 '23
This is generated code from a .Net framework. Maybe your friend needs to find someone who knows what they're looking at to look at his code.
87
u/Conscious_Yam_4753 Feb 05 '23
This looks like code that a visual GUI designer generated.
50
u/Friendputer Feb 06 '23
Imagine asking your friend to review your code and he just roasts you on the internet for clout with strangers
31
u/FormulaNewt Feb 05 '23
This looks like designer code. Leave it be.
40
u/RobertgamingROYT3 Feb 05 '23
I am pretty sure my theme did those automatically after I just added them as objects in WinForms
48
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Feb 05 '23
Image Transcription: Code
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!
11
u/Beautiful-Musk-Ox Feb 05 '23
what is the fixed version of this code?
7
u/RegentStrauss Feb 06 '23
Won't pile on about it being designer code, but it is good practice to name things like "TextBox12" something easier to find and reason about later.
3
u/wiesemensch Feb 06 '23
The worst thing is the out of order numbering.
3
u/MineKemot Feb 06 '23
You have friends who are also programmers?
7
u/SeasonsGone Feb 05 '23
Friends don’t let friends not know about data structures
2
u/shizzy0 Feb 05 '23
Not a lot of progress, huh?
2
u/Paul_Robert_ Feb 06 '23
LGTM
2
u/[deleted] Feb 06 '23
Prettyyy coooool buddy!!!
Thats some great french!!!
3
u/[deleted] Feb 06 '23
Is this a template generated thing, a bunch of UI designer changes before removing code behind, or something else? There’s not enough to go on here, because it’s just the UI objects generated by the GUI designer.
Can’t honestly call this bad code without seeing the other parts of the puzzle. Of course GUI designer code is going to look bad at a glance, but that’s just a tiny piece of the picture though.
1
u/Acrobatic-Bank-2737 Feb 06 '23
Jesus Christ… It’s Jason Bourne.
1
u/EngineeredBuilds Feb 06 '23
Average c++ hello world be like:
1
u/MLDKYT Feb 06 '23
Using siticone.desktop.ui.winforms;
1
u/zukas-fastware Feb 06 '23
I am a performance engineer working with C++, and this type of code makes my blood boil. You made me sad :(
-1
u/Pitiful_Magician_577 Feb 06 '23
Ok
-1
u/[deleted] Feb 06 '23
how can someone write this and at no point think to themselves, "there must be a better way to do this"?
-2
u/[deleted] Feb 06 '23
Jeez you’d think this subreddit is r/badcoder with the amount of roasting OP is getting 😂
Edit: oh shit badcoder exists
-9
u/this_underscore Feb 05 '23
Imagine using a for statement haha
-13
u/FormulaCarbon Feb 06 '23 edited Feb 06 '23
i mean, i dont know java that well, but cant you just
edit: saw the flair. I meant c#
-18
u/[deleted] Feb 05 '23
Yeah, this is pretty bad lol. What is your recommendation? I mean, maybe load the form controls into an array and instantiate a SiticoneButton or SiticoneTextbox based on the form field type?
-18
u/viperfan7 Feb 05 '23
If I have to do things like this manually, I like to use dictionaries
that way I can just use this.
Can also use a for loop instead of the Index++ thing if you want, but I find manually incrementing a bit better for documentation when doing this kind of thing, since quite frankly, it makes remembering what does what a bit of a pain.
Or you can just use an array like a normal person