Firstly: Sometimes I hear that there are no viruses for Macs and sometimes I hear there are a few viruses for Macs. Can somebody clear this up? Perhaps the latter refers to Malware?
Secondly: What is it about Mac OS that it cannot get viruses? What is it about Windows that it is prone to so many virus attacks? I have heard about the market share explanation but I would like to hopefully understand about the programming explanation (in laymen terms).
Okay, let's start with the simplest part: Viruses are malware, but not malware are viruses.
You're asking if there are viruses for Macs. The answer is "no."
Is there some malware for Macs? The answer is "yes."
What is it about the Macs that make them immune to viruses? A combination of things, but at its root the answer is that Mac OS X is based on UNIX, which was designed from the get-go to be secure. It is a military-grade, bank-grade, government-grade OS.
Windows was based on DOS, which gave nary a thought to security. The complex legacy code that Windows continues to rely on is the source of most of its ongoing issues. The best thing that could ever happen to Windows would be a top-to-bottom rewrite, but customers would never allow it. A majority are still running the 13-year-old Windows XP, which is (as you might imagine) full of holes.
Why don't Mac users need to run anti-virus and anti-malware programs? Anti-virus is not needed because there aren't any viruses. Anti-malware isn't needed because OS X has a built-in anti-malware system called XProtect, which is silently updated by Apple. Of course, XProtect cannot overcome the leading cause of malware on the Mac, which is user stupidity. By this I mean people who respond to a pop-up that claims you have a virus, and then give their user password to the malware so that it is installed. Luckily, XProtect will usually disable it.
Apple has also engaged in a number of other steps to improve security, such as not allowing the automatic installation of software from unrecognized developers. Others, including Google, have done what they can to stop users from going to known phishing and malware sites, but that's an uphill battle.
Finally, the Mac community in my experience is much more "connected" to each other than the Windows community. On the rare occasion that a new malware threat raises its head, we hear about it from each other very quickly. I guess with Windows there are too many threats for something like that, so its every man for themselves so to speak, it seems to me.
Lastly, the market share "explanation" you've heard is 100 percent pure agricultural-grade bull fertilizer that was debunked years ago, but in case you need proof, I give you the malware-free iOS platform versus the malware-ridden Android platform. Both are extremely popular. I think that serves as the final proof that "security through obscurity" is the myth it has always been.
I hope that answers your question.