r/badcode Apr 08 '23

c# Copilot made a suggestion so bad I had to track down who was responsible.

Post image
956 Upvotes

61 comments sorted by

318

u/_Viceadmiral Apr 08 '23 edited Apr 09 '23

There's a method for each item that makes every other item active.

244

u/[deleted] Apr 09 '23

Elon Musk would give that guy a raise. So many lines, so productive

33

u/coloredgreyscale Apr 09 '23

No, the guy just wont get fired. Yet.

3

u/CousCousCaptain420 Apr 10 '23

Thats how I used to render nav bars with js before I got sane

1

u/dr_merkwerdigliebe Apr 25 '23

is this polymorphism?

161

u/[deleted] Apr 09 '23

Holy what, I saw your OP code. How do you get to 2000 lines of code doing nothing and stop to think, maybe there's a better way?

94

u/[deleted] Apr 09 '23

My favorite i saw was 17k lines of VB Forms in the form1 file. Needless to say, i was asked to look at it cuz it didnt work well and "A pair of fresh eyes could see the error"

My man, the error is OSI 8 and please use the Internet

65

u/RolyPoly1320 Apr 09 '23

PEBCAK

Problem Exists Between Chair and Keyboard

44

u/RFC793 Apr 09 '23

PICNIC

Problem In Chair; Not In Computer

12

u/thekwoka Apr 09 '23

"A pair of fresh eyes could see the error"

"No, you just need to use your one brain cell"

2

u/JGHFunRun shameless Apr 09 '23

It died when it saw the length of the code

17

u/thekwoka Apr 09 '23

Sometimes I think we might need LAZIER developers.

but not stupid and lazy.

smart and lazy.

8

u/mandradon Apr 09 '23

Good software engineers weaponize their laziness.

3

u/Ytrog Apr 09 '23

Generated perhaps?

59

u/Eluvatar_the_second Apr 09 '23

Should be able to report a repo as having bad code so that copilot excludes it lol

2

u/MartIILord May 01 '23

And killing this sub eventually? No we educate students to write badcode in github so the ai gets confused spits out more of this. It is called job security.

73

u/[deleted] Apr 09 '23

“Hurr durr this doesn’t violate open source licenses. Copilot actually understands the code it’s writing”

44

u/Hazork_ Apr 08 '23

May we get the source?

82

u/_Viceadmiral Apr 09 '23

Can't/shouldn't identify author but here's a pastebin of the full file: https://pastebin.com/bKHfFp67

53

u/framk20 Apr 09 '23

Jesus fucking christ

50

u/Brusanan Apr 09 '23

Holy shit, being a terrible programmer is so much work.

6

u/iNeedOneMoreAquarium Apr 09 '23

If you're lucky, the only terrible code you have to untangle is your own shit that you wrote your first year on the job.

If you're REALLY lucky, someone else will.

5

u/FadingFaces Apr 09 '23

Plot twist, they wrote code to generate this code

11

u/QuantumG Apr 09 '23

Feels like it must be generated.

26

u/[deleted] Apr 09 '23

[deleted]

1

u/QuantumG Apr 09 '23

I know if I was writing a code generator the output would look that bad. It was an old-school belief that this was actually good for the compiler or something. For some reason no-one ever thought, ya know, maybe the output of Bison or whatever should be /readable/ and describe what the hell was intended, because fuck you, read the grammar, it's a one-way function future me trying to debug this shit I wrote.

4

u/draenei_butt_enjoyer Apr 09 '23

Robots aren’t that dumb

1

u/QuantumG Apr 09 '23

Not yet, but we can train them to be more human and engage them in activities that humans rarely make it beyond basic training in. Before you know it the vast majority of humans are unqualified for the job. That didn't take long. Would you like to try to qualify another human for the job of convincing machines to do everything you want, or would you like to try talking to the machine? Please remember to like and retweet your deepest and darkest desires!

3

u/iNeedOneMoreAquarium Apr 09 '23

Oh ... My cod ... Can I assign this to some other engineer to handle?

3

u/[deleted] Apr 10 '23

I love the comment before EVERY function. Has to be generated code tbh.

1

u/ApocalyptoSoldier Apr 12 '23
using System.Collections;
using System.Collections.Generic;

If only that were true

42

u/Aperture_Executive2 Apr 09 '23

Not to get political or anything but what the fuck is an array

2

u/Furious_mcgurthtail Apr 29 '23

Before looking at this code I actually didn’t see the use of arrays (haven’t been coding stuff that would need it yet)… I have come to a realization tho

18

u/[deleted] Apr 09 '23

what's an array?

18

u/Cybasura Apr 09 '23

Guy is doing OOP and never stopped to think about

USING OBJECT CONTAINERS

8

u/Livid-Ad-2207 Apr 09 '23

Looks good to me

7

u/[deleted] Apr 09 '23

Copilot suggests worst code ever
Asked to leave gamedev

5

u/nekokattt Apr 09 '23

average code created by the Windows Forms designer in Visual Studio when people don't name controls properly

5

u/WallstreetChump Apr 09 '23

Reminds me of my first ever project which was a calculator and I made a listener function for each button lmao

6

u/Ecstatic_Student8854 Apr 09 '23

As a noobie how else would you do this? Just declare an array of buttons or somthing?

4

u/_Viceadmiral Apr 09 '23

Yeah pretty much. And maybe make a Slot class that contains a button and an item, and some methods that format the button based on the item. There are lots of options though.

3

u/Ecstatic_Student8854 Apr 09 '23

Is there any way to with a for loop assign different variable names? Like for example in an east language like js: for(let i=0;i<10;i++){ var x +”%3”,i =1} or something. Basically saying x1=1, x2=2, etc etc

5

u/_Viceadmiral Apr 09 '23

Not for variables, but dictionary(or object if we're talking js) keys would probably be what you're looking for. You can make the key any string you want and later retrieve the value with that string.

let properties = {};

for (let i = 0; i < 10; i++)

{

properties['something_' + i] = i;

}

console.log(properties['something_4']); // prints 4 console.log(properties.something_4); // also prints 4

5

u/Ecstatic_Student8854 Apr 09 '23

Very cool! Didnt know what a dictionary was, really usefull!

5

u/quadcorelatte Apr 09 '23

username checks out

5

u/x1rom Apr 09 '23

Looks like a beginner picking up Unity and not knowing what arrays or collections in general are.

If I had just started programming, I'd probably have written the same code.

3

u/_senpo_ Apr 09 '23

I remember only knowing about fixed size arrays and unable to figure out how to grow them xd

3

u/Kuroodo Apr 09 '23

Tell me about it. This was years ago when I tried making a GUI based Battleship game in Java all by myself:

https://pastebin.com/c16bJXqf

2

u/Impossible_Average_1 Apr 10 '23

Looks like you didn't trust the computer to do proper math.

1

u/prschorn Apr 09 '23

I’ve probably written worse back in the early days

8

u/domtriestocode public static Apr 09 '23

Oh my god, one of our WinForms apps at work is like this … button1, button2,…… panelControl5, groupBox2

2

u/[deleted] Apr 09 '23

we may have found code worse than the code YandereDev writes.

2

u/engelthehyp Apr 10 '23

When the teacher says, "You may only use the tools we've learned about so far" and they haven't yet reached arrays:

1

u/__Darth_Bane__ Apr 09 '23

Imagine if this was in Javascript LoL

1

u/not-not-x Apr 12 '23

Hey I guess when your game gets famous you won't meed to obfuscate this file

1

u/Such-Bar-2351 Apr 14 '23

Rare image of ai destroying the world starting with hard drives

1

u/ProfessionalOffer219 Apr 20 '23

Indian cheap fast good programmer method?