Deck guns are for sinking small vessels not deemed worthy of one of your precious eels, finishing off crippled, unarmed mechants, and last ditch "Hail Mary" self-defense against attacking warships when you can not submerge or otherwise escape.
Because of their larger size, warships make a far more stable gun platform than does your u-boot. They also have more and usually larger guns than you do. All that translates into greater accuracy for them and more damage for you.
SH3 appears to have taken that into consideration for the AI, and you can get sunk pretty fast gunning it out with a DD or DE.
I've sunk Corvettes and armed trawlers with my deck gun, but never without taking serious damage to both boat and crew. I loose more watch officers that way.
Unnecessary gunfights with surface vessels, especially warships, is at best foolhardy and at worst suicidal - especially after 1940.
DIVE!
DIVE!
DIVE!