Cheating in CS is terribly easy to detect. We had programs we could use to pick up anything suspect, but I never actually used them - at the entry-level I was teaching at, it was pretty easy to catch someone out. In fact, often you can complete the assignment in the time it would take you to modify your stolen/plagiarized code so as to be undetectable. Half the time you just need to google the code they submitted before you find a forum/Yahoo Answers post from the student in question, and once you've been coding a student for a while you get a good feel for what exactly is and isn't their style and their code.
As to preventing it: there was a very simple policy at my university. You cheat, you fail. In most cases, it was rarely followed. We tended to be far more strict at the Summer School sessions, but then again, we also tended to get considerably more problems, mainly because the high school students and foreign exchange students attending didn't know better. The university also didn't really have a problem showing them the door.
Undergraduates were more of an issue. A lot of the time, we would let them know we'd discovered it, and let it slide. Repeat offenders were usually dealt with by using some kind of grade penalty. Very rarely did students get referred for academic discipline (although this is partly due to the entry-level nature of the courses I taught. Something high-level, or with a substantial amount of original research required, would be another story).
Finally, and perhaps most importantly - why were these students cheating? Well, honestly, I suspect because of the academic pressures placed upon them. I'd be extremely interested to compare the rates of detected cheating at somewhere like MIT, where grades are rounded up/down for GPA (ie, get a B+ and it's recorded as a B in your GPA, get an A- and it becomes an A) and at my university. Given the vast number of emails I used to get at the end of each semester from students desperate for a grade boost to help their GPA, I can see how some might have convinced themselves it was 'ok' to cheat. And maybe....just maybe...people are cheating because they're not getting the support they need. The article says the guy was taking the class for the second time. Sounds like maybe he wasn't getting the one-on-one help and extra support teaching staff should be giving him. Just a thought.