A bullet's explosion is not a fixed pressure. An explosion releases a certain fixed amount of gas, but as the volume of this gas expands - as the bullet is pushed down the barrel - the pressure of the gas reduces ($P \propto \frac{1}{V}$).
Since pressure is force per unit area, and the area of the bullet exposed to the pressure is constant whilst it is in the barrel, the force it experiences (which is proportional to its acceleration) decreases as the pressure in the barrel decreases.
When the bullet leaves the barrel, the build up of "explosion gas" can now immediately mix with the rest of the atmosphere, and the net horizontal force on the bullet drops immediately to zero - it is being pushed by atmospheric pressure by the same amount from the left and right.
So what is the ideal barrel length?
Given what has just been said, if the barrel were very short, the explosion pressure would be lost almost immediately, so the bullet would be subjected to very little acceleration.
On the other hand, if the barrel were extremely long then the pressure would decrease and decrease as the bullet moves along until eventually it would be less than the atmospheric pressure. At this point the force on the bullet from the atmospheric pressure would be larger than from the "explosion pressure" and it would actually start to decelerate before it even leaves the tube.
So you want your barrel to be adjusted according to the amount of gas that will be released in the explosion. You want it to be adjusted in just the right proportion so that when the bullet leaves the barrel, the pressure behind it from the explosion is exactly equal to the atmospheric pressure, so that it experiences the most possible amount of pushing from behind before it is expelled.
However, this is all assuming that there is no friction in the barrel. Of course, after accounting for this additional backwards force, working in the atmospheric pressure's favour, it is clear that we would be better off with a slightly shorter barrel as the point of no net force on the bullet is pushed back.
Furthermore, we haven't mentioned air resistance. I'm not actually sure how this would effect things as the picture is getting quite complicated now - it would probably work in the same way as friction, favouring a slightly shorter barrel length.
Oh, and of course this reasoning assumed that no gas could leak around the edges of the bullet in the barrel!