Painfully Redundant Code

You can talk about almost anything that you want to on this board.

Moderator: Moderators

User avatar
nicklausw
Posts: 376
Joined: Sat Jan 03, 2015 5:58 pm
Location: ...
Contact:

Painfully Redundant Code

Post 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);
User avatar
Sumez
Posts: 919
Joined: Thu Sep 15, 2016 6:29 am
Location: Denmark (PAL)

Re: Painfully Redundant Code

Post 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.
User avatar
dougeff
Posts: 2875
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Painfully Redundant Code

Post 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
nesdoug.com -- blog/tutorial on programming for the NES
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: Painfully Redundant Code

Post 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.
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Painfully Redundant Code

Post 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/
Pokun
Posts: 1923
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Painfully Redundant Code

Post 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!
User avatar
rainwarrior
Posts: 8062
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: Painfully Redundant Code

Post by rainwarrior »

Pokun wrote:At least it looks good on the outside!
That's all that counts. ;)
User avatar
Gilbert
Posts: 479
Joined: Sun Dec 12, 2010 10:27 pm
Location: Hong Kong
Contact:

Re: Painfully Redundant Code

Post 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.
User avatar
TmEE
Posts: 789
Joined: Wed Feb 13, 2008 9:10 am
Location: Estonia, Rapla city (50 and 60Hz compatible :P)
Contact:

Re: Painfully Redundant Code

Post 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...
Pokun
Posts: 1923
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: Painfully Redundant Code

Post 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.
User avatar
Punch
Posts: 363
Joined: Sat Feb 16, 2013 11:52 am

Re: Painfully Redundant Code

Post 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:
This is a block of text that can be added to posts you make. There is a 255 character limit.
User avatar
Dwedit
Posts: 4470
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Painfully Redundant Code

Post by Dwedit »

If you copy-paste, you can make big long code without looking back.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
psycopathicteen
Posts: 3001
Joined: Wed May 19, 2010 6:12 pm

Re: Painfully Redundant Code

Post 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.
User avatar
thefox
Posts: 3139
Joined: Mon Jan 03, 2005 10:36 am
Location: Tampere, Finland
Contact:

Re: Painfully Redundant Code

Post 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.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Painfully Redundant Code

Post 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?
Post Reply