Rotary encoder, debounce

I just started using some of those RGB LED rotary encoders from bourns... I was worried about contact bounce but then I realized that the problem wasn't bounce, it was just jitter if the knob was rotated so slowly that the encoder switched back and forth a bit before continuing. So I simply wrote a program that made sure all those extra little jitters were ignored and a step was only counted if it included an accompanying roll in the same direction.

int num = 0;
int lastNum = 0;
int pinA = 2;
int pinB = 3;

int thisPos = 0;
int lastPos = 0;
boolean goingUp = false;
boolean goingDown = false;
void setup(){
  pinMode(2,INPUT);
  pinMode(3,INPUT);
  Serial.begin(9600);


}

void loop(){
  boolean isA = (digitalRead(pinA)==HIGH);//turn pinA into a boolean, isA
  boolean isB = (digitalRead(pinB)==HIGH);//turn pinB into a boolean, isB


  thisPos=(isA)?((isB)?2:1):
  ((isB)?3:0);//Convert quad to 0 to 3

  if(thisPos==0&&lastPos==3&&goingUp){//if encoder gets to 0 from 3 and we were given permission to count up then count up and reset permissions
    num++;
    goingUp = false;
    goingDown = false; 
  }
  if(thisPos==0&&lastPos==1&&goingDown){//if encoder gets to 0 from 1 and we were given permission to count down then count down and reset permissions
    num--; 
    goingUp = false;
    goingDown = false; 
  }

  if(thisPos==2&&lastPos==1)goingUp=true;//if encoder is rolling up then allow program to count up when it gets to zero
  if(thisPos==1&&lastPos==2)goingDown=true;//if encoder is rolling down then allow program to count down when it gets to zero

  lastPos=thisPos;//set lastPos for next loop
  if(num!=lastNum){//if the number has changed, print it
    lastNum = num;//set lastNum for next report
    Serial.println(num);
  }
}

I couldn't find any info on doing this, I'm sure I didn't think of this first... Why is everyone worried about debounce with rotary encoders, this code works perfectly for me. What am I missing?

The way rotary encoders use quadrature encoding means that contact bounce only leads to oscillation by one position (which will happen anyway if the shaft is on the threshold of a step). So the worst that happens is you read one step away from the notional current position (usually this isn't a problem as you are either controlling a conceptually analog value, or only reading the value after the button is pressed (at which point the encoder will be in a detent position and shouldn't be bouncing or jittering).

Or put another way bounce and jitter should only be happening on one channel (A or B) at any particular time, which is fairly benign.

You could add some hysteresis to the output value if you want to prevent bounce and jitter appearing to your application code.

  if (position < actual_pos - 1)
    position = actual_pos - 1 ;
  if (position > actual_pos)
    position = actual_pos ;

Where actual_pos is the raw value from decoding quadrature and position is the value used elsewhere in the code.

It may not be bounce. Many applications of encoders are for position feedback and that is not considered a problem. If you debounce it, it might miss motion at higher speeds.