Suppose you come up with a jig for drilling holes in engine blocks. To you it is just a cost of doing business, like stocking the bathrooms with toilet paper. Your competitor can "invent" it fraudulently, file a patent, and blow your factory out of the water.
If you just want to protect yourself, just publish it somewhere. Prior art still exist with first-to-file, just not secret prior art. See Defensive publication[1], which isn't exactly a new concept, even in US patent history.
But then aren't you potentially giving away your competitive advantage?
Let's say I invent a new search engine, Poople. I don't have much money to patent it. But I can't keep the details secret either lest somebody else patent it. But by publishing the details defensively, my competitor with deep pockets, Paapo, goes and reimplements my algorithm and wipes me out of the marketplace.
You still have a year after publishing to file a patent. During that year, you only lose out on the patent if other innovations are made and published with regards to the subject matter of your patent and your application includes those other innovations. (You can still receive a patent if you restrict yourself to the invention described in your publication, but threading the needle in such a fashion could be difficult.)
Commercial sales by competitors are not subject to patent during that interim period, and they can continue such sales after the patent application is filed, but once the patent application is filed they can only continue to sell without a license the exact same products they sold before the application. So if the competitor changes the product sold, they could be subject to the patent (assuming the patent is granted).
As for your specific example: algorithms can't be patented; they are trade secrets. Specific software implementations of algorithms possibly can be patented. The difficulty, of course, is that deep pockets Paapo can always engineer around the specific software implementation you specify in your application.
I don't understand, why can't you keep it secret? Daniel_Newby talked about rogue employees, but you probably don't have them if you can't afford $10k for the patent. So, how exactly would your competitors get hold of it?