I feel like in a semi-realistic sci-fi story, railway guns would actually be useful. Railway guns were really massive guns mounted on large railcars and were kinda impractical. They were lacking in accuracy and were only limited to where there were rails. But, their shells could be shot so far that they reached very high into the atmosphere.
Therefore, railway guns could be brutally effective at preventing enemy ships from making landings or entering your planets atmosphere. The limited to railways is not a problem because just build a denser network. The accuracy problems can be solved with our modern technologies like better quality gunsmithing, aiming computers, and stabilizing systems on the shells. The main advantage of a railway gun is that there's no way for a ship to counter it besides blowing up the gun. It's very hard to stop a big fuck you shell from hitting your ship, unless you confuse the targeting system before it shoots.
You might ask, what about massive lasers and railguns? Massive lasers are not possible considering how lasers work, not to mention the blinding hazzard. Railguns, guns that use two magnetic rails to accelerate a shell to incredible speeds, are a good idea, though. You could mount a railgun on a railcar instead of a traditional gun.
Railway guns would be perfect for an old-timey sci-fi style with space pirates and stuff.