Author Topic: Methods That Break Mysteriously  (Read 478 times)

Offline capturts

  • Level 8
  • *
  • Posts: 43
  • Reputation: +1/-0
    • View Profile
    • Space Freight
Methods That Break Mysteriously
« on: November 16, 2011, 04:27:07 AM »
How do things break when you don't change them :(

I've spend the best part of an hour trying to fix something that I know I haven't changed in anyway. I can't even find the problem, some data just vanishes somewhere in a particular method and it's annoying. I'm not after help I just don't know how it got broken.  Has anyone else come across this phenomena?  >:(

Offline Nox

  • Level 35
  • **
  • Posts: 768
  • Reputation: +12/-2
    • View Profile
Re: Methods That Break Mysteriously
« Reply #1 on: November 16, 2011, 04:48:52 AM »
Well triple-check, maybe you missed something

And if it's not there then it was caused by a change you did elsewhere - that's why usage of global or static stuff it's unrecommended, these are not exclusive causes, just the more prone to. So check not the method itself, but everything it uses

Bugs or HW errors are extremely rare, it's most often not the case

Which language? Are you using APC/Eacc/Zend Opt. or something?
Also stuff like a need for volatile keyword in C, compiling optimizations, race conditions screwing up, but I doubt it be the case, just throwing some examples where stuff can go weird

It's often the tiniest stuff that can cause a bad behavior, a missing dot or something can screw the script up
Meet us at an IRC irc.freenode.net #bbg as well
https://vimeo.com/36579366 (a must-watch) | Join BOINC - no longer a hype, but you can help never the less

Offline capturts

  • Level 8
  • *
  • Posts: 43
  • Reputation: +1/-0
    • View Profile
    • Space Freight
Re: Methods That Break Mysteriously
« Reply #2 on: November 16, 2011, 04:49:42 AM »
YAY! Figured it out. The method hadn't changed the data from the database was coming back as an object when it should've been an array  :D

Offline capturts

  • Level 8
  • *
  • Posts: 43
  • Reputation: +1/-0
    • View Profile
    • Space Freight
Re: Methods That Break Mysteriously
« Reply #3 on: November 16, 2011, 04:55:59 AM »
Well triple-check, maybe you missed something

Triple... I looked at this about 1000 times   ;)

Thanks for the suggestions :) Yes It's often something small that breaks things. And in this case the error was elsewhere. If I had looked carefully at the data I would've seen the problem in 2 seconds flat.

Basically the data for a battle is stored in the database as json and I guess somewhere along the lines I'd accessed it as if it were an object. I think this is one reason I'm not so keen on the duck-typing in PHP. It sounds handy to be able to chop and change a variable to use it as an integer and then a string and then later on reuse the variable as an object but if it were strict typing the error would've been more obvious.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Methods That Break Mysteriously
« Reply #4 on: November 16, 2011, 05:19:48 AM »
How do things break when you don't change them :(

I've spend the best part of an hour trying to fix something that I know I haven't changed in anyway. I can't even find the problem, some data just vanishes somewhere in a particular method and it's annoying. I'm not after help I just don't know how it got broken.  Has anyone else come across this phenomena?  >:(
Multiple times :) My personal theory is that the gnomes that live inside CPU get drunk from time to time :D And that's the cause of these mysterious things.

Offline capturts

  • Level 8
  • *
  • Posts: 43
  • Reputation: +1/-0
    • View Profile
    • Space Freight
Re: Methods That Break Mysteriously
« Reply #5 on: November 16, 2011, 05:34:42 AM »
Well, not sure about gnomes, but definitely something seems to break stuff when you're not looking.

On a serious note, I find this is where the worst 'hacks' appear in my code. Something is working great, I work on a different bit of project and then come back and it's broken. Then I find myself adding stupid bits of code that adds 1 to an array index and then takes it off again 5 lines down.

Offline Harkins

  • Level 28
  • **
  • Posts: 424
  • Reputation: +11/-2
  • Coder, blogger, entrepreneur.
    • View Profile
    • Push CX - Blog
Re: Methods That Break Mysteriously
« Reply #6 on: November 17, 2011, 09:37:15 AM »
Write automated tests and use version control software and these problems will quietly vanish. I spent the first ten years of programming plagued by them, now I don't know the last time I saw stuff randomly break.

I'm guessing you're using PHP, SimpleTest looks like a straightforward tool. If you're on Windows, git is probably a big pain in the ass, but TortoiseSVN makes Subversion easy to use.

Let your tools do all the boring, tedious bookkeeping so you can write code.

Visit #bbg on irc.freenode.net to talk browser games anytime.

Offline Mutant

  • Level 10
  • *
  • Posts: 55
  • Reputation: +5/-0
    • View Profile
    • Kingdoms
Re: Methods That Break Mysteriously
« Reply #7 on: November 17, 2011, 02:56:40 PM »
Another vote for automated testing. It's not an easy thing to do (it takes years to learn how to do properly, just as it does to program). But once you learn how to do it right, it's amazing how much easier certain things get. I can't even write code without some tests to fall back on now.

Offline capturts

  • Level 8
  • *
  • Posts: 43
  • Reputation: +1/-0
    • View Profile
    • Space Freight
Re: Methods That Break Mysteriously
« Reply #8 on: November 17, 2011, 06:39:19 PM »
Yes, PHP in this case. I'll take a look at simpletest, thanks :)

Offline gnoh

  • Game Owner
  • Level 15
  • *
  • Posts: 127
  • Reputation: +2/-0
    • View Profile
Re: Methods That Break Mysteriously
« Reply #9 on: November 18, 2011, 08:27:28 AM »
Along with automated testing,  also use assertions to valid your assumptions about the parameters. 

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal