1) I had a discussion with a friend and a programmer. - This could be one or two people.
2) I had a discussion with a friend, and a programmer. - This sentence is wrong. The comma is incorrect there, whether this describes one or two people.
a) I talked to a friend who is a programmer. - This is only one person.
b) I talked to two people, a friend, and a programmer. - This is not two people. This indicates FOUR people! (two people, plus a friend, plus a programmer)
Regarding B: If you want two people here, use "I talked to two people: a friend and a programmer." "A friend and a programmer" will be a non-restrictive appositive for "two people."
If you want one person and no ambiguity, you could write "I talked to my friend, a programmer" or "I talked to my friend, who is a programmer," or "I talked to a programmer, who is a friend." Other options are possible.
None of these is a case of the serial comma creating confusion. For example of that, see "A Serial Comma Creates Confusion" - http://zencomma.wordpress.com/2011/09/20/a-serial-comma-creates-confusion/