The deck guns of U-boats were the primary weapon when raiding shipping; they would surface next to merchant ships, warn them to abandon ship, and then use the deck gun to put holes below the waterline. Later they had to resort to torpedoes exclusively because of convoys, escorts, even planes that could be launched by convoys. The problem was they could carry far more shells than torpedoes...
Look also at Britains HMS M1 M and HMS X1 submersible cruisers. The Japanese I400s are interesting. We apparently had plans drawn up for bigger and better versions that never made it off the drawing board. Our later considerations related to closing the submersible aircraft carrier gap, This Aircraft Carrier Could Go Underwater... IMPOSSIBLE Submarine Aircraft Carrier
I think the even later flying submarines was a better idea but thats a different conversation.
The problem was they could carry far more shells than torpedoes...
I suspect that many of our ships will, unfortunately learn this lesson one day.
Who knows, maybe there will be a naval battle again where the combatants are within eyesight.
The Surcouf supposedly collided with a freighter while the French submarine was running submerged at a depth of a few m meters.