I'm no exhaust expert, I'm only pitching in from what I know about engines. Generally, the longer the tube (for the same diameter), the higher the the difference in pressure between the inlet and outlet of the pipe.
In practice, your exhaust outlet is at atmospheric pressure. The inlet to your exhaust pipe in a turbo diesel would be the turbine outlet, or in an N/A diesel, the exhaust manifold outlet. Your turbo or N/A exhaust pressure would be higher for a longer tube as compared to the shorter tube. So generally, the shorter the exhaust pipe, the lower the pressure difference along the exhaust. This helps in increasing volumetric efficiency of the engine, and power.
Problem is, you can't just went it to the side. Sitting at idle at a traffic light with the window open, the hot exhaust gases will rise and enter your cabin. Exhaust gases being toxic with particulates, NOx and other nasties, it's best to route it elsewhere. Stacks help do that, they exit at a higher point than car windows, and even when the car is moving, they keep exhaust away.