The stupidest things you've ever done with code

Started by Ryex, December 27, 2013, 04:35:08 am

Previous topic - Next topic

Ryex

December 27, 2013, 04:35:08 am Last Edit: December 27, 2013, 08:38:44 pm by Ryex
A lot of us have been programming for quite a while now, than means we've all made more than our fair share of mistakes. We've also probably some really stupid things when it comes to execution or written some terrible hackish code to reach our goals. why don't we share some of those stories and prevent others from repeating our mistakes?


I'll start first with one of my oldest mistakes.

Back when I was programming the DEE (Dynamic Effects Engine, the script behind my dynamic sounds and dynamic weather systems) I did something really stupid with checking to see if the player was in range of a source. as sources could have curved shapes there was a circular part to a lot of them. and instead off just checking to see if they were in a circle. I checked every pixel in a circle shape to see if they were standing on it. I ended up with major FPS problems (like 5-10 FPS). some quick advice form Blizz had me checking to see if the square of the players distance was greater then the square of the source distance (pythagorean theorem while avoiding the expensive square root operation) and I was rolling at top speed again. That was my first introduction to optimization, I ended up getting pretty obsessed with it over the next year but eventually learned only to optimize selectively as I needed to, other wise you waste a lot of time.

I have a few other stories to share but you'll have to share one of yours first to hear it.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

KK20

December 27, 2013, 05:02:45 pm #1 Last Edit: December 27, 2013, 05:04:55 pm by KK20
I've mentioned this one too many times before.

I basically did this:

class A
 def initalize(var)
   @stuff = var
 end
end

class B < A
 def initialize(var)
   super(var)
 end
end

begin
 #...
 klass = B.new("Hello")
 #...
end

And raged for over an hour wondering why I was getting "wrong number of arguments(1 for 0)" over and over.

Another one that had me angry for a while was why my return value was giving me an integer when it should have been a double. But mind you this was done in Intel X86 and linking it to a C file, so the change wasn't exactly obvious at first. I thought the problem was with my Assembly code the whole time, until I saw

extern int x86Method();

and practically screamed at the heavens. I merely copy-pasted the same C file from the last assignment, so I never thought to check it.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

PhoenixFire

Stupidest thing I've done with code? Ermm... Look at my latest (and only) script posted in the XP section lolz.. It's not so much that the code is bad, so much as it is my attempt to take on such a huge system as my first ever edit / conversion....
Quote from: Subsonic_Noise on July 01, 2011, 02:42:19 amNext off, how to create a first person shooter using microsoft excel.

Quote from: Zeriab on September 09, 2011, 02:58:58 pm<Remember when computers had turbo buttons?

winkio

While I have made plenty of mistakes myself, I actually want to share the base code for a final project in one of my classes.  The assignment was to make a generic networked game client, as well as a custom networked game server for a game.  So you could host your game, but you could play anybody else's game from the class.

This was a bad idea for a lot of reasons, but the an easy one is code readability.  To implement this, we end up with a lot of class and method declarations that look like this:


public abstract interface IExtVisitorHost<I, H extends IExtVisitorHost<I,? extends H>> extends Serializable
{
    public <R, P> R execute(IExtVisitor<R, I, P, ? extends H> algo,  P... params);
}

public abstract class AExtVisitor<R, I, P, H extends IExtVisitorHost<I, ? super H> > implements IExtVisitor<R,I,P, H>
{

}


Another is that in order to process these commands, we have to branch based on type.  So the more different types of operations your program contains, the more overhead there is on each individual operation.

In the end, the whole premise doesn't make any sense.  If everyone has to make a custom server, as might as well have them distribute a custom client as well, which can be optimized, updated, uninstalled, etc. more easily.

Blizzard

I've done so much stupid stuff already, I can't think of anything particular right now.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Heretic86

I'd say biting off more than I could chew.

Its one thing to add something like a Hunger property for characters, its another to try to create / fix a full Battle System.

(Off topic of thread)

@Ryex - Im using your Sound Script in my Collection of compatible scripts.  You've been given credit.

Im actually somewhat curious if you'd ever consider doing an Update on it.  For both performance and functionality.  Such as having multiple Sound Emitters, which I'm not sure if thats even possible.  I had some difficulty getting non dynamic background sounds to play as well...
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)

Ryex

@Heretic86
I'm not sure there is much I can do to improve it's performance. as for extra features, if by multiple sound emitters you mean overlapping sounds that isn't possible with RMXP's default sound system.
as for non dynamic BSG sounds. if there is no sound source on the map it should default to the map's BGS. otherwise it's going to try to use the sound source BGS if you in range (even if it's really faint) and the MAP BGS if your not. I'd suggest making the source large and the power smaller so that there is a large area where the sound is at full power and a smaller fall off area. if your still having trouble there should be a cutoff power setting in the script somewhere, try making that larger. PM me for more help.


Back on topic.


This one time when I was working on ARC's project converter I did something really stupid once. I was trying to get the converter to replace some common method calls to Load_data or something in the scripts. if you don't know RMXP stores scripts compressed with zip's Deflate. I ignore this and tried to do regexp matches on the compressed string representation of the scripts. obviously this didn't work as not match could be found on the compressed data. I spend a few hours trying to figure out why no matches were being found, was I doing something wrong? hand I written the regexp wrong? was this a bug between ruby versions? then I realied I had forgotten to uncompressed the data. the converter worked flawlessly there after.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

bigace

KK20 knows all the stupid things I've done coding.


Use Dropbox to upload your files. Much simpler than other upload sites, you can simply place a folder on your desktop that will sync with your DropBox account.

Ryex

but your supposed to share! don't worry there will be no judgment here, we've all been there.
I no longer keep up with posts in the forum very well. If you have a question or comment, about my work, or in general I welcome PM's. if you make a post in one of my threads and I don't reply with in a day or two feel free to PM me and point it out to me.<br /><br />DropBox, the best free file syncing service there is.<br />

Heretic86

This one time, at band camp, I didn't make backups of stuff I had uploaded and the server died!
Current Scripts:
Heretic's Moving Platforms

Current Demos:
Collection of Art and 100% Compatible Scripts

(Script Demos are all still available in the Collection link above.  I lost some individual demos due to a server crash.)