It is currently Thu Sep 21, 2017 2:15 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Painfully Redundant Code
PostPosted: Mon May 01, 2017 3:38 am 
Offline
User avatar

Joined: Sat Jan 03, 2015 5:58 pm
Posts: 366
Location: ...
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:
//this for an entire paragraph
printf("T");
wait(1);
printf("H");
wait(1);
printf("E");
wait(1);


Top
 Profile  
 
PostPosted: Mon May 01, 2017 4:06 am 
Offline
User avatar

Joined: Thu Sep 15, 2016 6:29 am
Posts: 248
Location: Denmark (PAL)
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.


Top
 Profile  
 
PostPosted: Mon May 01, 2017 4:12 am 
Offline
User avatar

Joined: Fri May 08, 2015 7:17 pm
Posts: 1730
Location: DIGDUG
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


Top
 Profile  
 
PostPosted: Mon May 01, 2017 4:19 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10010
Location: Rio de Janeiro - Brazil
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.


Top
 Profile  
 
PostPosted: Mon May 01, 2017 8:15 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5626
Location: Canada
Source code for "DRAGON: A Game About a Dragon". A platformer somehow written without the concept of arrays or loops.

https://gist.github.com/alessonforposterity/832da4fab11e10609dad/


Top
 Profile  
 
PostPosted: Mon May 01, 2017 2:12 pm 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 750
Location: Sweden
At least it looks good on the outside!

nicklausw wrote:

I'm glad it's Tic Tac Toe and not Chess. Or Igo!


Top
 Profile  
 
PostPosted: Mon May 01, 2017 3:00 pm 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 5626
Location: Canada
Pokun wrote:
At least it looks good on the outside!

That's all that counts. ;)


Top
 Profile  
 
PostPosted: Mon May 01, 2017 7:26 pm 
Offline
User avatar

Joined: Sun Dec 12, 2010 10:27 pm
Posts: 278
Location: Hong Kong
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.


Top
 Profile  
 
PostPosted: Tue May 02, 2017 1:41 am 
Offline
User avatar

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

_________________
http://www.tmeeco.eu


Top
 Profile  
 
PostPosted: Tue May 02, 2017 2:54 pm 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 750
Location: Sweden
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.


Top
 Profile  
 
PostPosted: Tue May 02, 2017 3:09 pm 
Offline
User avatar

Joined: Sat Feb 16, 2013 11:52 am
Posts: 218
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/alessonforposterity/832da4fab11e10609dad/



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.


Top
 Profile  
 
PostPosted: Tue May 02, 2017 5:38 pm 
Offline
User avatar

Joined: Fri Nov 19, 2004 7:35 pm
Posts: 3932
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!


Top
 Profile  
 
PostPosted: Wed May 03, 2017 9:26 am 
Offline

Joined: Wed May 19, 2010 6:12 pm
Posts: 2265
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.


Top
 Profile  
 
PostPosted: Wed May 03, 2017 10:05 am 
Offline
User avatar

Joined: Mon Jan 03, 2005 10:36 am
Posts: 2945
Location: Tampere, Finland
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: kkfos.aspekt.fi


Top
 Profile  
 
PostPosted: Wed May 03, 2017 11:53 am 
Offline

Joined: Sun Sep 19, 2004 11:12 pm
Posts: 18995
Location: NE Indiana, USA (NTSC)
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bregalad and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group