It is going to happen. And lots of times it will happen when it's dark, or wet, or cold, or all of that. Partially this is because in wet, cold, dark riding weather, it's harder to avoid all those things lying in the road that want to puncture your bicycle tire and tube.
Those little bits of metal, or glass, stick to your tire easier when it's wet and when you hit an especially nice pothole or curb they are driven right through the tire and into the tube.
So, what next?
First off, maintain control of your bicycle by gently braking to a slow stop. Get off your bike, move to a place out of the traffic path and examine your predicament. Riding on a deflated tire and tube can cause harm to your rim, so getting off the bike as soon as possible is important in order keep the rim intact.
This is where you get to put your bicycle tire repair tools and start thinking about those other