When it comes time to connect your shiny new sound bar or AV receiver, your two main choices are HDMI or optical digital audio.
The simplest advice is to go with HDMI when you can. But if you can't it's not the end of the world.
Here are the pros and cons of each.
The basics
Both HDMI and optical pass digital audio from one device to another. Both are better than analog (the red and white cables). Both can pass multi-channel audio, like Dolby Digital. Both cables can be had pretty cheap.
The biggest difference is that HDMI can pass higher-resolution audio, including the formats found on Blu-ray: Dolby TrueHD and DTS HD Master Audio. These formats can't get transmitted across optical.
In terms of simplicity, HDMI also passes video signals. So if you want just a single cable between two devices, HDMI is your pick.
However...
Depending on your gear, you might not have the option for HDMI. Maybe you have an older receiver. Maybe you have everything connected to your TV, and you just want to get the audio out to a sound bar (and the only option is optical).
In that case, optical is fine. Don't sweat not being able to connect with HDMI. For most setups, the sound will be just as good with optical as with HDMI.
One complication is if you have a sound bar, like the Sonos Playbar or Vizio S4251w-B4, that benefits from a surround sound signal and you connect it to one of the many TVs that can't pass such a signal via its optical outputs. Neither of those sound bars have HDMI inputs anyway, so the best way to connect them is directly from the source to the bar via optical, skipping the TV. That, or get a new TV.
Better, a little...
Regardless of the gear you use, as mentioned there's also no way to get Dolby TrueHD or DTS HD Master Audio with an optical connection. However, that's not a huge deal.
While there is a difference between Dolby Digital and those high-res lossless formats, the difference isn't as pronounced as you might expect. On a decent system, with decent speakers, you might notice that the high-res formats are a little more open, a little smoother sounding.
On lesser gear, it's a lot less likely you'll hear a difference. Most sound bars, for example, lack the fidelity to do anything with the additional resolution. Many don't accept those formats at all.
Bottom Line
Use HDMI when you can. The cables are cheap, and having just one wire simplifies setup. If you can't, optical is fine. If your gear doesn't have HDMI, it can't take advantage of the high-resolution audio formats from Blu-ray anyway (unless you connect with analog, and decode from your Blu-ray player). On the other hand Dolby Digital is surprisingly good, and unless you have decent gear, you probably won't hear much (if any) improvement with Dolby TrueHD and DTS HD MA.