Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
I've decided to start writing a weekly post about the bugs I encounter, either in my personal code or at work.  Part of this is to just share tips/tricks... part of this is to share lols.

Most of my bugs will likely be in Scala code.  For those unfamiliar, Scala is a JVM-like language that adds in functional programming.  Basically, it's Java + Python.



This week's bug was a fun one.  So, we have this object (a singleton instance of a class), and it has a bunch of properties.  It also has an "All" property which is a set of them.  We'll say these properties represent languages:

object Languages {
 val All = Set(Java, Python, CPlusPlus)

 val Java = "java"
 val Python = "python"
 val CPlusPlus = "c++"
}


Can you spot the bug?  Yes, this does compile, so it's not that...

If I did this, you'd find it real quick:
scala> object Languages {
    | val All = Set(Java, Python, CPlusPlus)
    |
    | val Java = "java"
    | val Python = "python"
    | val CPlusPlus = "c++"
    | }
defined module Languages

scala> Languages.All
res0: scala.collection.immutable.Set[java.lang.String] = Set(null)

wtf.  Why is it a set of null?!  Well, as it turned out (after 4 hours of scouring through a ton of code built on top of this simple object), it's because Scala objects and classes evaluate those out of order... if I had made the vals below lazy (evaluated on call; not on defining the class) it'd have worked properly.  Sadly, that has a memory overhead.

The real solution is just to put All at the bottom of Languages:
object Languages {
  val Java = "java"
  val Python = "python"
  val CPlusPlus = "c++"

  val All = Set(Java, Python, CPlusPlus)
}


And boom.  It worked:
scala> object Languages {
    |   val Java = "java"
    |   val Python = "python"
    |   val CPlusPlus = "c++"
    |
    |   val All = Set(Java, Python, CPlusPlus)
    | }
defined module Languages

scala> Languages.All
res0: scala.collection.immutable.Set[java.lang.String] = Set(java, python, c++)


So, yeah, this was just an annoying bug that cost me almost an entire day.  Figured I'd share my annoyances.

Josh

Josh Avatar
Where were you when Reach fell?

******
Legendary Studio Member

4,806


May 2008
I am working on implementing In-App Purchases for a VOD app I created using Adobe AIR. Was testing this morning and discovered that my in-app purchases were working fine, but the videos wouldn't play after the purchase had been made. Did some troubleshooting and discovered I was calling

this.requestSoftKeyboard();

instead of

this.requestVideoURL();


Code complete ftl. :(

Chris

Chris Avatar

******
Head Coder

19,519


June 2005
So, today's bug is a tad different. It's not a bug in my code, but rather a bug in someone else's code making my life hell.

I was working with a third-party API that we used to make purchases for things we need. Now, because of our design, we don't request in bulk. We make individual requests for each item. Well, this third-party decided to bill the credit card on the account for each individual item. Now, when we request 30 items in under a second, and they hit our card at the bank 30 times... the bank tends to shut down the card.

So, needless to say, I accidentally shutdown a corporate card 4 times this week. :D They've since fixed the bug, but it was a tad annoying to work around. :P

newBookmarkLockedFalling