Software is also somewhat protected because unlike a physical device reverse engineering is far more difficult. I can open pretty much anything and have a CAD model in less time than the original engineer took to design it.
True, I have learn programming and experience disassembling programs, and is really really difficult to understand how a program work just this way. If the program has millions of lines of code it is nearly impossible.
Patents are a contract, the state gives you monopoly, you give the state the knowledge(with plans, drawings and explanations) of how your thing works. Without showing the code, you should not be granted a patent.