Smart contract codes are not directly visible to everyone. If you choose to, you can publish the source code and link it to the scanners for everyone to see.
The bytecode can also be reverse-engineered to get some sort of source code but it's typically not very readable. As with all reverse-engineered codes. This you can't prevent.
Furthermore, Ethereum (or its community) encourages developers to be open. The reason is trust through transparency: if the source code is known everyone can check it to make sure they know exactly what the contract does. People feel safer giving away their hard-earned Eth to contracts which they know to be honest.