+ 10

Dev didn't know about loops... (funny but a good lesson for beginners)

This post on the subreddit /r/programminghorror has been making the rounds for quite a while, but for those who haven't seen it, I wanted to show it anyway. It's both funny and sad at the same time. This developer created a rudimentary game using Microsoft XNA without ever learning about for or while loops, or classes for that matter: https://www.reddit.com/r/programminghorror/comments/4dguj8/dev_didnt_know_about_for_or_while_loops/?st=iuvebmds&sh=e30d61a5 Here's a link straight to the code: https://gist.github.com/alessonforposterity/832da4fab11e10609dad/ One could say that the patience is commandable, but honestly, that's just one way of justifying stupidity. For those who are eager to learn programming to create games or really do anything, remember to first and foremost get a good grasp of basic programming practises. Learning these basic skills will save you (and others!) a lot of headaches and time, while the lack of them will be stop you from advancing futher.

27th Jun 2017, 3:17 AM
Taija
Taija - avatar
7 odpowiedzi
+ 8
You have obviously never heard of the benefits of unrolling loops! Again, it has to do with making the code faster. Maybe that was what he had in mind. -edit ok maybe not but it made me think about it. The benefits would have been there if he had used an array instead of multiple variables. https://en.m.wikipedia.org/wiki/Loop_unrolling
27th Jun 2017, 8:54 AM
Karl T.
Karl T. - avatar
+ 6
Daaaaamn..
27th Jun 2017, 4:38 AM
jay
jay - avatar
+ 6
OH my gawd.. what mess is this! int boss1Clean = 0; int boss2Clean = 0; int boss3Clean = 0; int boss4Clean = 0; int boss5Clean = 0; int questHPBonus = 0; int endpageCT = 0; int endpageFrameX = 0; int endpageFrameY = 0; int haveTreasure1 = 0; int haveTreasure2 = 0; int haveTreasure3 = 0; int haveTreasure4 = 0; int haveTreasure5 = 0; int haveTreasure6 = 0; int haveTreasure7 = 0; int haveTreasure8 = 0; int haveTreasure9 = 0; int haveTreasure10 = 0; int haveTreasure11 = 0; int haveTreasure12 = 0; int haveTreasure13 = 0; int haveTreasure14 = 0; int haveTreasure15 = 0; int haveTreasure16 = 0; int haveTreasure17 = 0; int haveTreasure18 = 0; int haveTreasure19 = 0; int haveTreasure20 = 0; int haveTreasure21 = 0; int haveTreasure22 = 0; int haveTreasure23 = 0; int haveTreasure24 = 0; int haveTreasure25 = 0; int haveTreasure26 = 0;
27th Jun 2017, 5:31 AM
Shivam Tiwari
Shivam Tiwari - avatar
+ 6
@David Ashton Heh. Code-inception? I didn't know anything about Microsoft XNA before, but it's apparently a set of tools with a runtime environment specifically made for creating games. It probably has a way of managing classes and such, but since this person didn't create any classes and directly changed every variable each time, he must have had to write quite a lot of code by hand, with the help of ol' copy & paste of course. Some of the code just looks.. draining. For example, this part: if (kbState.IsKeyDown(Keys.Left) && (jumpVal == 49 || clawVal == 49 || breathVal == 49 || confVal == 49 || swlVal == 49 || swrVal == 49 || leftVal == 49 || rightVal == 49 || upVal == 49 || downVal == 49)){ if (jumpVal == 49) { jumpTrue = true; } if (clawVal == 49) { clawTrue = true; } if (breathVal == 49) { breathTrue = true; } if (confVal == 49) { confTrue = true; } if (swlVal == 49) { swlTrue = true; } [..... and so on, you get the point] And then the exact same is repeated, except with "else if (kbState.IsKeyUp(Keys.Left)". And then he repeats BOTH conditional statements but for the value 50, and 51, and 52.. it's madness! For references sake, look at the code in this short Microsof XNA tutorial about collision detection: http://rbwhitaker.wikidot.com/collision-detection
27th Jun 2017, 8:53 AM
Taija
Taija - avatar
+ 6
@Karl T When you look deeper into his code, you'll notice it has nothing to do with optimiziation and everything with lack of knowledge. I'm all for unconventional techniques if it gives you the results you desire in the particular use case, but for a video game with thousands of variables that are constantly changing, it's not useful or optimal. Most unrolling, after all, doesn't mean doing away with loops alltogether, but reducing the instructions needed. In this case, there were no loops at all and the code is also lacking other basic programming practices, like arrays and classes. Not using loops or using them less can be also be a part of functional programming, but this isn't what's being done here either. Occam's razor applies here; ignorance is the likeliest cuplrit.
27th Jun 2017, 9:09 AM
Taija
Taija - avatar
+ 5
Maybe he wrote a code to write that crazy code 🤪
27th Jun 2017, 5:15 AM
David Ashton
David Ashton - avatar
+ 4
Dyyyyaaammmmnnnn
27th Jun 2017, 11:08 AM
Washiul Alam Sohan
Washiul Alam Sohan - avatar