Author Topic: The stupidest things you've ever done with code  (Read 3273 times)

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5135
  • LV: 198
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
The stupidest things you've ever done with code
« on: December 27, 2013, 11:35:08 AM »
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.
« Last Edit: December 28, 2013, 03:38:44 AM by Ryex »
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.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline KK20

  • Master Scripter Fixer
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3143
  • LV: 378
  • Gender: Male
  • Choco Octo <3
    • View Profile
Re: The stupidest things you've ever done with code
« Reply #1 on: December 28, 2013, 12:02:45 AM »
I've mentioned this one too many times before.

I basically did this:
Code: [Select]
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
Code: [Select]
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.
« Last Edit: December 28, 2013, 12:04:55 AM by KK20 »



Other Projects
RPG Maker XP AceUpgrade RMXP to RMVXA performance!
XPA TilemapTilemap rewrite with many features, including custom resolution!


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

Join the CP Discord Server!

Offline PhoenixFire

  • Moderator
  • Astral Trancist
  • ***
  • Posts: 918
  • LV: 6
  • Gender: Female
  • ~That's an interesting notion, in it's own way~
    • View Profile
Re: The stupidest things you've ever done with code
« Reply #2 on: December 28, 2013, 02:50:36 AM »
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....
Next off, how to create a first person shooter using microsoft excel.

<Remember when computers had turbo buttons?

Offline winkio

  • Epiq
  • Administrator
  • Guardian of Chaos
  • *****
  • Posts: 4505
  • LV: 199
  • Gender: Male
  • I am lying.
    • View Profile
Re: The stupidest things you've ever done with code
« Reply #3 on: December 28, 2013, 03:18:54 AM »
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:

Code: [Select]
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.

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19985
  • LV: 648
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: The stupidest things you've ever done with code
« Reply #4 on: December 28, 2013, 03:20:41 AM »
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      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


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

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

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 749
  • LV: 31
    • View Profile
Re: The stupidest things you've ever done with code
« Reply #5 on: December 30, 2013, 03:42:15 AM »
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.)

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5135
  • LV: 198
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: The stupidest things you've ever done with code
« Reply #6 on: December 30, 2013, 10:58:56 AM »
@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.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline bigace

  • Transcended Spirit
  • ***
  • Posts: 211
  • LV: 16
  • Gender: Male
    • View Profile
    • Bigace Scripting World
Re: The stupidest things you've ever done with code
« Reply #7 on: January 11, 2014, 08:47:30 PM »
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.

Offline Ryex

  • Arctic Bird of Programming
  • Global Moderator
  • Chaos Ultimate
  • ****
  • Posts: 5135
  • LV: 198
  • Gender: Male
  • Wants to write a compiler for fun
    • View Profile
Re: The stupidest things you've ever done with code
« Reply #8 on: January 11, 2014, 09:33:48 PM »
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.

DropBox, the best free file syncing service there is.
(click to show/hide)

Offline Heretic86

  • Astral Trancist
  • *****
  • Posts: 749
  • LV: 31
    • View Profile
Re: The stupidest things you've ever done with code
« Reply #9 on: January 13, 2014, 03:06:00 PM »
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.)