To put some light on the differently shaped symbols you're describing: The straight ones are from an typographically background not even quotes, but unit-symbols " for inch or arc-minute and ' for arc-second. The slanted ones you're describing are the typographically correct symbols for quotations and are most of the time formed like commas. As TextEdit is not a code editor, but a simple text writing tool it can be the case that quotes are automatically converted to the correct ones, which, as you noticed, do not work in code as they are other symbols. For those questioning, why correct quotes are most of the time not even on the keyboard layout, that's a remnant of the time of typewriters, where space, material cost and letter distribution where driving the keyboard layout evolution. Typographic correctness just wasn't valued as much as those other issues.
Edit: For code editing I'd suggest using dedicated software, which won't make any automatic typography replacements and sometimes even highlight such errors.