You'll hear 'coding exercises' a lot as the answer to this question. And while these exercises certainly have some value (they certainly test a person's desire for the position as they have to do up to 20 hours of unpaid work!) you should use them carefully.
One problem is that, more often than not, these exercises are not related to the project/roll. Which seems crazy to me. If you do use exercises with a candidate, make sure they are designed to test their ability to do the job.
There are many other ways to discover if a programmer is a good candidate - without looking at a single line of code!
Get some Face Time:
You can tell so much from just talking to someone. From the inflection and tone of their voice to their body language. Restricting yourself to an audio or email exchange denies you of that valuable character insight.
Many freelancer platforms attempt to protect themselves from being disintermediated by heavily discouraging direct phone contact. Instead, they rely on simple online tests and gameable peer rating systems. While there is nothing wrong with either of the methods, they need to be combined with more personal techniques to build a more complete accurate picture of a candidate.
Ask for their Opinion:
Ask them about their favorite programming language and why. The way they answer will reveal a lot. If someone has a strong opinion about a topic it’s a good indicator they are passionate about it
Check them out on GitHub:
How much do they contribute to the industry at large and open source projects? As well as giving you an insight into their coding this gives you a great insight into their mindset and passion. Open source projects are a way people give back to the industry by helping to fix things for a greater good. Now that sounds like someone I would want on my team
How often do they deliver what they code?
Tinkering with code is one thing. Being able to ship a complete product is another. Find out about projects they have finished, which they haven't and what happened
How well spoken are they?
Are they good communicators? If they behave like a black box then you will struggle to work with them and hire a team around them.
How well do they write?
This is similar to the above point but distinct enough to matter. A great writer will often be better at their job, whether that be marketing or programming. My advice is simple here: when stuck between similar looking candidates, always hire the better writer.
Use a trial period:
It's a safe and fair way to test them on a project without not paying them for their time. At Scalable Path, we give clients a month to evaluate a developer. If it’s a good or bad fit, it will be obvious. And if not, both sides save themselves a lot of trouble and risk by testing out the situation first.
Apart from the coding exercises, these methods can be used by non-programmers and so are very useful for PM's when interviewing.