You really don't need a gun ......until you REALLY need a gun.
Missile and rockets are the current Shiney objects that get all the attention. But they come with a couple of limitations. Both financially and in the amount of space both above and below deck they take up.
The British were on the way to removing their deck guns they competed for space with other systems and it was felt that in the future there'd be no need for such old fashioned foolishness.
And then the Falklands war happened and they began relearning all sorts of painful truths and not just the ones involving shipboard artillery.