If you're used to playing your instrument through an amplifier, playing through the amplifier and using a microphone to record to a computer or recording console will produce a more natural sound. This is the method of recording used in most studios. However, if you play an instrument such as electric piano or keyboard synthesizer that does not generally benefit from playing through an amplifier, recording direct may be much simpler, and provide a cleaner sound.
Sometimes, recording direct is the best option because you don't have an amplifier available or because there are restrictions on the amount of noise you can make in your physical location. This is especially applicable to people who live in apartments or other high-density living areas, as well as people who record while others are trying to sleep. In these situations, it may be possible to record amplified instruments during the day when neighbors and children are at work or school, and record other instruments such as keyboards later at night.
If you're simply trying to record an idea before you forget it or just want to take a rough sketch of a song to band practice, it's often easier to record directly and avoid the hassle of setting up microphones. On the other hand, if you're trying to record songs for commercial release or to feature on your website, it may be worth it to spend the extra time it takes to get the best quality recording.
If you're forced to record guitars direct to a computer, you can use various software plugins to help recreate the sound of an amplifier and microphone. Similarly, some newer solid-state guitar amplifiers include modeling and speaker emulation technology. If you own one of these, you can plug your guitar into the amplifier, set the controls to your preferences and connect the amplifier to the recording console or computer, bypassing the amplifier's power section and speakers. It's also possible to record a clean signal directly and then play it back through an amplifier at another time. You can then rerecord the signal using a microphone. This is commonly known as re-amping.