In academia, students get to see PLENTY of bad code
They write quite a bit of it themselves!
Not all the code they see is in books. A lot of it is ill-documented scientific code written on the spur of the moment to check out a new idea. If it works, write a little MatLab wrapper and release into the wild. FUN!!
Yes, we teach our students how to gather requirements, write documentation, carefully craft the code. However, quite a bit of our own code is written quickly, and the scientific paper serves as the documentation. One reason we get away with it, is that many of our programmes are really rather small snippets reading data, applying the new algorithm to it, and writing some output. In many cases, the code does not get released as production code. Only in larger scale efforts do we apply any thorough software engineering skills.
So, us academics often don't abide by our own rules.
Mea culpa, mea culpa, mea maxima culpa!