I used to dream in code all the time. It was when I was tackling a programming problem I was having trouble with. My mind would often solve it while I sleep; and I'd be able to solve the issue quickly in the morning.
It happens less these days. Either because I am more experienced or because development tools have improved; I no longer get stuck like I used.