Because the internal electrical connectors are different, it would be hard to plug in the wrong thing. If it doesn't belong, it won't fit.
You are right about the cable for the hard drive and optical drive. If they are both IDE devices, they use the same type of cable. They can be on the same cable even. The exception would be if the hard drive is the newer serial ata (SATA) hard drive. SATA uses a different cable and connects to a different controller on the motherboard. But the connectors are very different and you can't confuse them.