Generally, anything which you hire someone to create for you is a "work made for hire" and you will have the intellectual property rights to it. You can make this more explicit by having the programmer execute an agreement specifically stating that anything made pursuant to (whatever work agreement you hire them by) is a "work made for hire" and that as a work for hire, all intellectual property rights belong to you. The agreement should also state in the alternative that if it should be concluded that the work is not a work for hire, that the programmer agrees to assign all intellectual property rights to you, and execute any documents necessary for that purpose. Finally, before even telling them the idea, have them sign a confidentiality agreement in which they agree to not use the idea for their own benefit or disclose it to any third parties.