Page 1 of 2

Painfully Redundant Code

Posted: Mon May 01, 2017 3:38 am
by nicklausw
Stumbled across this gem (warning, 18,000 lines of code).

If you don't feel like freezing up your computer, it's pretty old so you've probably seen it before anyway. But if not then it's a tic-tac-toe program where the whole game is run through printing a manually-made board for every possible board. Oddly fun to look at.

Has anyone other than myself ever unironically written code this poorly before? I remember my first scrolling text C program from all the way back in 2011, I printed out every character and then waited a frame over and over. My poor 10 (11?) year old self didn't know what a char array was. It looked something like this, except it used some windows-exclusive wait function that I can't remember.

Code: Select all

//this for an entire paragraph
printf("T");
wait(1);
printf("H");
wait(1);
printf("E");
wait(1);

Re: Painfully Redundant Code

Posted: Mon May 01, 2017 4:06 am
by Sumez
I always start out with intentionally redundant code if I feel like it's too much of a bother to think ahead of things I don't feel I can comprehend completely before the code is actually out there. This is especially true for assembly code, where it can be pretty opaque what logic can really be shared between similar routines. A good example is checking collisions on the Y axis and X axis respectively. I would write them out completely, copy paste the other, and modify them, then try to shrink my code and figure out what I can parameterize or what variables could be much more generic.
Never expect to organize your code perfectly in your first attempt.

Re: Painfully Redundant Code

Posted: Mon May 01, 2017 4:12 am
by dougeff
Someone posted this on reddit, with the title 'first year programming student'. I believe the assignment was to move peices on a checkerboard. He ended up writing if statements for every possible position. It's over 150,000 lines long.

https://youtu.be/mBaZhoEAz7I

Re: Painfully Redundant Code

Posted: Mon May 01, 2017 4:19 am
by tokumaru
My first experience with programming was using batch files, so yeah, I did try to create games drawing all possible images using ASCII art. I tried making a platformer and a first person shooter, neither got very far (maybe 20-30 screens each), and they definitely didn't feel like actual games.

Re: Painfully Redundant Code

Posted: Mon May 01, 2017 8:15 am
by rainwarrior
Source code for "DRAGON: A Game About a Dragon". A platformer somehow written without the concept of arrays or loops.

https://gist.github.com/alessonforposte ... e10609dad/

Re: Painfully Redundant Code

Posted: Mon May 01, 2017 2:12 pm
by Pokun
At least it looks good on the outside!
nicklausw wrote:Stumbled across this gem (warning, 18,000 lines of code).
I'm glad it's Tic Tac Toe and not Chess. Or Igo!

Re: Painfully Redundant Code

Posted: Mon May 01, 2017 3:00 pm
by rainwarrior
Pokun wrote:At least it looks good on the outside!
That's all that counts. ;)

Re: Painfully Redundant Code

Posted: Mon May 01, 2017 7:26 pm
by Gilbert
It's not 18k lines of codes, but to similar effect, I once made a simple online point & click adventure game (well, around 20 years ago...), after discovering how to use image maps on a picture to link to different pages (later I think most people moved on to using tables/frames and images assembled with sliced components).

It didn't use variables or whatever (not that I knew how to, either) to keep track of the progression and what items the player was holding (or in other words, the game flags). Instead, a separate html file is used for every different combination of the flags. So, say there are two items, A and B, and another game flag to mark certain progress, and thus we can use three binary digits to represent them (like, for example, 101 to denote Item A available, Item B not available, the progress flag set) and convert these three digits into an octal digit, to be put in the html file's name, so there were several dozens of html files (named by numbers, and you could basically "cheat" if you know what the numbers meant, though I've lost my notes so even I myself don't know about them now) used in such a short game.

The game is not online anymore, but could still be reached through an archived page. As it is very possible that not every single html page was archived, it is almost certain that the game is not completable now as you would hit a 404 at some point of the game.

Re: Painfully Redundant Code

Posted: Tue May 02, 2017 1:41 am
by TmEE
I looked through my really old code and it seems the only really inefficient thing I did was long strings of IFs. I had no clue what CASE was at that time. Also no indendation, some stuff is pretty difficult to follow due to it, but I had other structures implemented that I continue to use to this day...

Re: Painfully Redundant Code

Posted: Tue May 02, 2017 2:54 pm
by Pokun
Before I learned any real programming I played around with RPG Maker 95 and 2000 for Windows. These RPG Makers had no scripting, and you programmed by adding commands in a GUI environment. I had no idea what a variable was but I had just learned to use switches (RPG Maker's boolean variables) which made it possible to actually do things other than just making maps and NPCs and stuff.

I used this to make my very first mini game (a target shooting game) that was totally predetermined, I used switches to control what step it was in, making it 100% possible to win every time with no effort once you had figured out the very simple trick behind it.

OK this wasn't as much redundant code as it was primitive code, but that Tic Tac Toe is quite similar to it. I had no idea how programming worked, nor how the majority of the commands in RPG Maker worked, so I just tried to figure out things myself.

Re: Painfully Redundant Code

Posted: Tue May 02, 2017 3:09 pm
by Punch
rainwarrior wrote:Source code for "DRAGON: A Game About a Dragon". A platformer somehow written without the concept of arrays or loops.

https://gist.github.com/alessonforposte ... e10609dad/

Came to post that... I'm not sure if I believe that the code isn't some elaborate performance art, it's just mindblowing to think that he wrote all that code without ever thinking "there must be a better way of doing this!" :lol:

Re: Painfully Redundant Code

Posted: Tue May 02, 2017 5:38 pm
by Dwedit
If you copy-paste, you can make big long code without looking back.

Re: Painfully Redundant Code

Posted: Wed May 03, 2017 9:26 am
by psycopathicteen
My code for rotating 64x64 sprites is like that, because it is full of unrolled loops for shifting pixels left and right. I have six different routines depending on how many pixels to shift in which direction. 3 for left, and 3 for right. One for shifting 1-4 pixels, another for shifting 5-7 pixels, and one for shifting 8 pixels.

Re: Painfully Redundant Code

Posted: Wed May 03, 2017 10:05 am
by thefox
Not directly related, but here are some other examples of interesting coding styles:

QB64: https://github.com/Galleondragon/qb64/b ... e/qb64.bas
A QBasic-compatible BASIC->C++ translator in 25k lines of spaghetti.

Lugaru: https://github.com/jspjut/lugaru/blob/m ... meTick.cpp
(See https://en.wikipedia.org/wiki/Lugaru.)

I'm pointing out these two examples because despite the spaghetti code and redundancy, they somehow manage to work surprisingly well.

Re: Painfully Redundant Code

Posted: Wed May 03, 2017 11:53 am
by tepples
psycopathicteen wrote:I have six different routines depending on how many pixels to shift in which direction. 3 for left, and 3 for right. One for shifting 1-4 pixels, another for shifting 5-7 pixels, and one for shifting 8 pixels.
Why don't you just shift with the multiply register?