We all love laser guns (which are usually plasma weaponry) but why guns? It's not like we need the long barrel for making it more accurate or the stock to control recoil. So why guns and why not something else?
User Expectation and Skeumorphic Design
The floppy disk 💾 is used (less so than five years ago, but used) as a save icon, even though outside of old industrial machines and nuclear missile silos, no one uses floppy disks. Your phone makes a shutter sound when you take a picture, despite not having a shutter. Electric cars are designed to look like gasoline vehicles in many ways that are utterly unnecessary, because it’s what people expect, and when something looks the way people expect, it makes them happy and comfortable and more likely to award your Laser Gun Company with the government contract for one million Pew Pew Guns. So your industrial designers make it look like a nice old fashioned projectile-throwing rifle, even if it doesn’t strictly need to.
It's an interesting question because our current laser guns look more like giant flat panels that fire invisible beams of heat at airplanes and torpedoes.
But those are aimed by computers. People need to use sights to aim. A longer barrel gives a more accurate sight and better control of the gun. It also allows the weapon to function like a bat in close fighting and could hold other attachments like grenade launchers or backup conventional rifles for when laser just won't work (like the Chinese mirror armor they developed in response to USA laser weapons).
Take a look at the wikipedia article on lasers.
A laser consists of a gain medium, a mechanism to energize it, and something to provide optical feedback. The gain medium is a material with properties that allow it to amplify light by way of stimulated emission. Light of a specific wavelength that passes through the gain medium is amplified (increases in power).
The accompanying diagram shows that the gain medium is a long tube. The longer the gain medium is, the more the laser is amplified.
Furthermore, one can have a laser version of choke (change the spread of the beam) by having a series of adjustable lenses, and a long barrel facilitates that.
To aim a weapon accurately, a long barrel is helpful. You also want to have some heft to dampen jitter (Photographers know that a light camera is harder to hold steady).
As well, you need some place to put all of the tech, even if you don't need a long lasing cavity you'll find some use for the volume. A short but thick device would be much less practical, for aiming as well as for carrying.
Of course the validity of all of these reasons depends entirely on the author's whim in a scifi setting. You coud have a short, giro stabilized hand gun with computer assisted aiming and nano components if you so please, but who wants to ruin a good trope?
Some considerations from Atomic Rockets (They have a gorgeous article about side-arms on hard Sci-Fi):
A portable laser weapon can't realisticly exist, since we have a major problem on portability of batteries and to save energy they would need focusing lens what can drive their form to be like a old Super 8 camoder due lens size.
Aiming can be done by a periscope, as in Star Trek, as energy weapons don't have trajectory deformations, like projectiles, reducing the need for a barrel.
I guess it is just for readers/viewers to be able to recognize in a fraction of a second that the character is holding a weapon that can hit at a distance.
To justify this would be so that military personnel doesn't need to adapt to a new way of fighting and can be even more efficient than before without the required formation time. Then you still need batteries, plasma ammunition, electronics to handle the energy release, attachments and so on that make is as big as a classic gun.
Your "long barrel" comment implies a rifle configuration as opposed to a pistol configuration.
For a given level of technology a rifle has more space for "stuff" than a pistol.
What sort of stuff?
- Power/energy: it can fire more times before it runs out of juice. It can also pack a greater punch for armour piercing.
- Targeting: The rifle form factor allows invisible light sensors to read the eyes of the shooter and automatically place the laser on target. It also allows dynamic aiming adjustment to keep the shot on target long enough to be effective. I always thought Predator shoulder mounts have no way of targeting unless linked to a visor.
- Crowd suppression: either multi-shot (machine gun-like but each shot targeted) or wide beam (close up shotgun-like scattershot).
- Robust/Hardened design: smaller form factors are more prone to failure of delicate parts. A laser that can't shoot is just a stick.
- Heuristics/Learning curve. It's pretty obvious which end to point towards enemy and a trigger to activate. If it looked like a Dyson Airblade (or a makeup mirror, or a bow & arrow) it's not so obvious.
Alternate form factors
I believe we are in the last generation of personal war-fighting. Drones and automatons are the future.
So an adventuring rascal of the future is more likely to have a weapon drone in close proximity or close response time.
- Yondu Udonta in Guardians of the Galaxy has his Yaka Arrow.
- Han Solo should have wasted Greedo (first!) with a small remote sitting on the booth. Of course that would change the cowboy elements of the space opera.
Close protection drones would probably be big enough to shield behind while they lay fire upon aggressors. So I'm guessing the size of a riot shield.
If personal anti-gravity doesn't exist in your world then the drone has wheels and/or legs.
Another approach: the Close Protection Drone is actually made up of nano-robots hiding as clothing and cover exposed body parts quickly. Return fire is handled by specialised nano-bots that are part of the outfit and therefore have no specific form. Laser fire shoots out of the body.
- The laser source is a long tube. The beam bounces back and forth in it and is amplified by the excited medium inside. The thinner and longer the tube is, the better collimated the beam is. That means it does not spread as much and therefore remains effective at longer distance.
- The long barrel also makes aiming more accurate.
- The stock is not needed to absorb recoil, but the additional fixed point it provides improves how steady you can hold it to get good aim.
It's not clear what your question is when asking about an imaginary weapon that does not yet exist, so any answer would depend on which particular weapon you're referring to.
But not all laser type weapons are shaped like a gun, some are shaped more like a TV remote control than a gun. (more photos here )
Though even the federation uses a more traditional long barreled rifle-like shape for larger guns, and since it's made up technology there can be lots of reasons including cooling, a longer laser/phaser chamber for more power, etc
In addition to the excellent reason given by Daniel B, there are other considerations with the look, expectations and usability issues. Guns, like knifes or spears, have two ends, a good one and a bad one. If your laser gun looks like the Star Trek TNG class 1 phaser: then you not only risk holding it the wrong way (darn it, which way to enemy?), but also it isn't clear to enemies what you are holding. What's that, a garage opener? A medical scanner?
For a gun, as famously pointed out by Douglas Adams, it is important to make sure that you know when you are at the wrong end of it. With a traditional gun design, there is no doubt. Bullets come out... here.
Makes me think of a fun detail I saw in "Edge of Tomorrow". A thing that looked like what I believe is called a "claymore" mine with "This side to enemy" written on one of its otherwise identically looking sides. I don't know whether these have that text written on them in reality, but I wouldn't be surprised! The design sucks ass.
Now that we come to design, why does a pistol look like a pistol, and why do little boys who play cowboy point out their index finger? Well, guess why. Because that's exactly what the design of a pistol imitates, and it is exactly what we are innately able to do without training. You can just point your finger at something, and your finger will point to it 99% good. There's no doubt about what pointing the barrel towards something in the same manner will do either.
There would be much "better" designs for pistols that transmit recoil more favorably. But they don't let you point your imaginary index finger intuitively.