Publishing and patenting aim at different goals within an IP strategy. The route that you choose to pursue in term of intellectual property depends on your goals. For example, if you intend to build a product from your research, then a patent will protect the invention contained in your product. On the other hand, if you just want to be acknowledged in the scientific community and make available your research, then publishing is your best option.
Actually, both are valuable and should be pursued almost simultaneously. But, before the study is published, you will want to have the patent application submitted to the USPTO, or in whatever country you live.
It can depend on the setting: In industrial science, patents are often valued.. In academic science, publication of articles tends to lead in emphasis - and patenting tends to be less predominant in the reward structure..
Pursuing a patent first is advisable because the patent protects your intellectual property rights as a creator and also to be recognized for the creation. Protecting such rights through a patent is particularly advisable for intellectual property and financial and business purposes, such as if you intend to market, sell, or otherwise use the creation to earn money or to license it to others for them to use to do so. After you obtain a patent, if someone were to publish an article claiming to have invented or discovered your creation, such article could be viewed as an infringment on your patent and as slander, libel, defamation, and/or breach of privacy in some jurisdictions.
Contrast this to the following situation that can occur if you publish a scientific article first before getting a patent: by publishing a scientific article, you notify others of your creation and arm them with information that they can use to secure a patent on your creation, and the only protection you have from publishing the scientific article is a mere copyright on the article itself, which is practically useless under fair use copyright law. People can take the information in your scientific article, use it to re-create your creation/invention, and then they can apply for and get a patent on the creation before you do so. At that time, even though you published the scientific article, they will have the patent and the intellectual property rights to the creation, and not even you can use their patented creation without a license from them, even though you were actually the one who created it. Moreover, you could not successfully challenge their patent in this scenario. Patent offices and patents do not protect the creators of creations, but only the first person to apply for a patent for such creation. Many intellectual property rights have been lost by inventors/creators allowing others to seek and obtain patents before the inventor/creator does so.
In sum, publishing the scientific article first will pose a serious threat to entirely destroying any interest you have in obtaining and protecting intellectual property rights to the creation/invention, and should not be done. It is thus advisable to seek the patent first, and once the patent application is filed to then (if you wish) publish a scientific article.
To add to my above comment, merely publishing an article is not always sufficient to preclude someone else from obtaining a patent on a creation/invention, because that determination can hinge on how adequate and thorough the article is to preclude the patent, the evidence available regarding such, and the courts view and weight of the evidence. Further, in evaluating whether a scientific article precludes a patent, courts consider many things and are inclined to rule in favor of the patent. Even if the article is adequate and thorough, one could merely ever so slightly modify your creation/invention and then obtain a patent on the modified version of your invention, and such a patent could prove resistant to challenge on grounds of the published article.
It must also be said that they are two very different forms of disclosure. In the articles the goal is to disclose as much as possible, in patents the opposite because it is only necessary to obtain protection