As someone who runs a application design and development business I have yet to receive or sign a contract that doesn't explicitly state the final disposition for the rights to the resulting IP. I would find it hard to believe that there's a publishing outlet that doesn't do the same in their contractor agreements, particularly with writers.
No actually code, on its own is not patentable, systems and algorithms are. All those cool Apache and BSD licenses are about copyright which apply equally to code and a news article.