r/shittyprogramming • u/*polhold01242 • Jun 22 '16
You can totally write unstructured code in C#
58
Jun 22 '16
Oh my god. The language gives you so much potential for writing beautiful and well structured code and instead they made this. Aghh. The passionate programmer in me is ripping his hair out.
19
34
u/thelehmanlip Jun 22 '16
Why I spent so much time copying this down is beyond me, but in case anyone else wants to run it:
_01: int b = 0;
_05: string t = "";
_10: for(b = 99; b > 0; b--){
_20: goto _100;
_30: t = t + " OF BEER ON THE WALL";
_40: Console.Write(t + ", " + t);
_50: Console.Write("\nTAKE ON DOWN AND PASS IT AROUND, ");
_60: if(b - 1 <= 0) { Console.Write("NO MORE BOTTLES OF BEER ON THE WALL"); } goto _80;
_70: goto _200;
_75: Console.Write(" OF BEER ON THE WALL");
_80: Console.WriteLine();
_85: goto _230;
_90: Console.Write("GO TO THE STORE AND BUY SOME MORE, 99 BOTTLES OF BEER ON THE WALL");
_95: return;
_100: t = b.ToString() + " BOTTLE"; if (b > 1) { t = t + "S"; }
_110: goto _30;
_200: Console.Write((b - 1).ToString() + " BOTTLE");
_210: if (b - 1 > 1) { Console.Write("S"); }
_220: goto _75;
_230: ;}22
u/TheTjalian Jun 22 '16 edited Jun 22 '16
Oh my god. I compiled it and it actually works. You'll need to chuck something at the end so the window doesn't close (Console.ReadLine()) worked well enough for me), but it works. I'm a little disgusted it works, but yeah. Thanks for the transcript!
EDIT:
_240: string rl = Console.ReadLine(); _250: if (rl == "more beer") { goto _10; }because in for a penny, in for a pound is my motto
2
14
u/YMK1234 Jun 22 '16
Doesn't line _60 always jump to line _80 no matter what? I'd imagine it should only jump in the if.
11
u/vegetablebread Jun 22 '16
That's correct. Labels _70, _75, _90, _95, _200, _210 and _220 are unreachable.
9
8
u/Lakonislate Jun 22 '16
_30: t = t + " OF BEER";
_40: Console.Write(t + " ON THE WALL, " + t);Isn't that how the song goes?
7
u/wOlfLisK Jun 23 '16
I'm imagining a tutor said "as long as it works, you get full marks" and you decided to make his life hell.
5
4
u/mushr00m_man Jun 22 '16
This is too easy. Get rid of all the nested statements and use gotos for everything.
4
3
u/TheTjalian Jun 22 '16
I just, just, why? Why is this even possible? Some coders just want to watch the world burn.
2
u/luckystarr Jun 22 '16 edited Jun 22 '16
This is beautiful! I have fond memories of learning the concept of a loop in a language like this (GW-BASIC). A long time ago of course.
2
u/Lystrodom Jun 22 '16
You got the lyrics wrong! It's "x bottles of beer on the wall, x bottles of beer! Take one down, pass it around, x - 1 bottles of beer on the wall!"
2
2
u/the_king_of_sweden Jun 23 '16
This perfectly illustrates why we need a GOSUB statement in C#
1
u/ekolis Jul 09 '16
We do have a gosub statement, it's just implicit!
Console.WriteLine("im in ur sub runnin ur codez"); // implicit gosub before Console.WriteLine
1
1
u/cosmicr Jun 23 '16
Serious question - why does C# have a goto statement?
1
u/skulgnome Jun 23 '16
For jumping into a sibling block. Less correctly, for being lazy about transaction restarts and jumping to start-of-transaction instead of using a do-while.
1
u/acylus0 Jun 23 '16
I mean... I understand where there may be extreme edge cases (highly unlikely) to use goto but why?
1
0
0
Jun 22 '16
[deleted]
4
u/MorallyDeplorable Jun 23 '16
They're abusing labels/gotos to implement an ustructured function, akin to the classic versions of BASIC were interperted, such as GW-Basic.
It's basically an odd way to implement a dated technique in a modern environment. It produces spaghetti code that's really hard to understand without excellent comments. In this example you'd pretty much have to run a simulation of the program in your head just to figure out the basics for it, since there's no documentation.
0
Jun 23 '16
[deleted]
3
u/MorallyDeplorable Jun 23 '16 edited Jun 23 '16
I find this annoying to read and I program to keep a roof over my head.
Also, GW-Basic is the predecessor to Q-Basic.
2
2
u/Terreurhaas Jun 22 '16
Am I not following the goto's correctly? I'm missing labels 90 and 95...