The essential advantage of both patents and trade secrets is that they protect the underlying idea.
A trade secret has an advantage over a patent because, so long as secrecy is maintained, the trade secret has an indefinite life (the Coca-Cola formula is more than 100 years old), whereas a patent has a limited life during which the patentable invention is public knowledge, thereby providing potential copiers an opportunity to consider ways to take evasive action to bypass the protection afforded by the patent.
Of course, a major defect of a trade secret is that the protection does not exist if the secret becomes known publicly (through no violation of contractual or fiduciary rights), or if others independently arrive at that information. By contrast, a patent protects the invention even though it necessarily becomes known publicly and even if others independently arrive at that invention.