nowucca.com - personal software technology blog

Sometimes as developers we all have that bug that is hiding in plain sight.  I think it it valuable to share real world experience and share some of these ones because you never know when you will encounter the same things again.

So, I have this bug hiding in plain sight - I am trying to manually 'adjust' a memberId before computing a percentage-based MOD for multivariate testing cell assignment.  Why am I adjusting the memberId like this?  Well, over time, using an adjustment will help avoid selecting the same poor customers for new experiences.  So my method looks like this (please bear in mind this is a cooked-up version so spare me questions):

        public int testBasedCellAssignment(String testId, int memberIdAdjustment, int percentage) {
          if (( memberIdProvider.getMemberId() + memberIdAdjustment % 100 ) < percentage ) {
             return memberTestService.allocateValue(testId);
          }
          return memberTestService.defaultValue(testId);
        }

This will always return the default value for the test.  Why?

...

Well because the MOD (%) operator binds more tightly than PLUS (+).  Because we have more than 100 members at work, the IF condition is never true.   This of course was not immediately obvious - in fact I only worked it out in the car on the way home.