Sunday, April 29, 2007

Do CS Schools Encourage Sloppy Coding?

I'm currently pursuing a Masters degree in Computer Science.  I'm a little over halfway through the program so I've had exposure to several different classes.  To date I've not seen a class which required programming where I got a sense that the code I handed in was ever looked at by a TA or a professor.  Asking around, this does not appear to be an atypical experience.  Some schools have quality standards for the code written by their students but many do not.  If it compiles and accomplishes the task, that is sufficient for a good grade.

I totally understand why this happens.  The teacher/student ratio is low.  Looking at code is difficult and time consuming.  Often the professors want to let the students work in their own choice of language.  In that case, trying to stay on top of Ruby, C#, Java, C++, Perl, Lisp, Haskell, etc. is probably too much to ask.  This begs the question though of whether it is a good practice.

If you need code to do something simple (as most assignments do) and only the outward behavior matters, hacking it together will suffice.  Why bother freeing memory or checking error conditions?  Why bother commenting the code?  Why even validate your inputs?  These are all things that are absolute musts in the industry.  If you write code that doesn't handle errors, leaks like a sieve, and is hard to maintain, you'll be looking for work quickly.

After 4 years of programming like this, one gets into some pretty bad habits without some checks on quality.  Wouldn't it be better if we had something akin to code reviews for code which was handed in?

3 comments:

  1. I definitely agree with this observation. As a member of my school's student advisory committee, I have pushed for more code review as part of the grading process. I also approach professors that are giving example or starter code using gets() or similar practices. I see too many students copy these practices into production code. There is definitely a point to leaving out the input validation and error checking to show a particular point, but say what you are leaving out. That is one thing that impressed me about Writing Secure Code by Michael Howard. When he gave Code examples, he gave an indication of what he left out for clarity of the example. That is a rare practice I see in instructional material.

    ReplyDelete
  2. Having graduated from Michigan State University, my experience was that you don't need to write efficient or elegant code - unless your program doesn't work, in which case you may get partial credit for the code you have completed.
    It's really up to each student to do research and gain *experience* that teaches him/her how to code well.

    ReplyDelete
  3. I faced this hard transition when moving from undergrad to grad course in a different college.
    The quality checks (make based build, minimal API, input validation, single public class per file amongst others) in the 2nd college were very strict and the first few months were a nightmare. I constantly grumbled about their 'academic' approach to programming.
    Now when I look back upon it, I am extremely grateful that the instructors shamed me into better coding practices, else the same would have happened after I joined the industry.

    ReplyDelete