Wednesday, December 21, 2011

Coding Quality and Your University Courses

All programmers are self taught - or are they?

The basic point of that post is true, at least in my case - my courses did little to teach me the details of good coding style and practice.  Of course (ha!) I also learned 5 programming languages in undergrad, so there was not a lot of time to get beyond the basics.

However, the courses also noted the building blocks of the larger concepts - modularity was handled in the first class via the "Karel the Robot" exercises - writing programs to make a small robot trace shapes.  This covered the idea of wrapping repeated actions in functions/subroutines to allow later re-use.

Pascal covered the side-effect in procedures vs functions

But the big thing I think that the courses gave me was the space to realize that I knew the right thing to do.  I was able to see the correct way by being allowed to do it wrong.

Case in point - I was taking a course that was taught in Fortran, and was waiting to turn in my program printout when the guy ahead of me in line asked if I would look over his program to see if I could spot the error in his code that was messing him up.

He told me that he knew BASIC already, so he was writing the programs in BASIC to get the algorithm right, then translating into Fortran for the grade - an excellent idea.  Then I looked at his code.  It was bad.  The first thing that struck me was that he was jumping all over the place, instead of having blocks of code in reasonable places.  IF X THEN GOTO 130 ELSE GOTO 200, instead of having the ELSE be a fall-through.  And so on.

I worked through his code to offer advice, but I don't know if he got the big ideas out of it.

But my main point here is that  if you go into programming, you should have the mindset to see the good stuff on your own - university education is to teach the things that your can't see.