Spafford’s Recommendation
See Spafford’s Security Checklist for a good list of common ports and usage
Check general principles provided for safe programming
Learn to keep good programming principles during program inception
Use Code checking and Peer review
Use Saltzer’s Seven Rules to analyze your code