Wednesday, February 15, 2012

Pattern Ignorance

I've been in graduate school for a few years now and keep asking myself how we could engender good habits in students - like any good Codewright - during their education, like usage of version control or refactoring.

My database class provides a good example of the potential and the obstacles. The first project involves creating a schema where the tables have contraints that prevent the tables to be created all at once and those same constraints make it impossible to load the sample data all at once. You don't need the actual schema, I'm just describing a bit of complexity where it influences the assignment.

So the data is provided in text files in a comma seperated form and the approach I decided upon is simply parsing the values and then generate SQL statements in the right order.  First off, I thought about using an ORM framework, like Hibernate, but have no experience with one.  I did find a CSV library to parse the data which cut down the code I had to write but will complicate the grading because the TA will need to download and extract the library in order to run what I submit so I'll have to include those details in a readme file.

So, processing a single file is fairly straightforward; parse the file into a list of lines, loop over the lines, generate the appropriate SQL statement for the data from that file. I soon found myself repeating code for looping over the lines since the files for each table needed slightly different SQL statements.  In rejecting the ORM approach, avoiding the definition of domain objects as simple containers for data -- I also didn't really need domain objects for each file because there was not going to be any behaviour, not to mention the lack of a data framework -- I continued the straight text approach.  Looping over the lines in the first file (Employee), it was easy to directly call a routine to generate SQL rows.  This caused a problem when I wanted to reuse the looping structure for the next file (Departments).  I could leave the loop and add an argument but that would require defining an interface and implementing a distinct class for each file. Avoiding data objects puts me on the slippery slope of avoiding other patterns too; what I keep telling myself is it's only for this one project, it's due in two days, and the TA isn't going to give bonus points for using nifty patterns assuming he's ever been exposed to them.

In short, there is no incentive to produce well-written code.  The assignment is graded by evaluating the results without regard for the methods used to produce those results. 

Delicious Bookmark this on Delicious

1 comment:

  1. That is a conundrum - I just wonder what benefit you're getting from being at graduate school if you're able to recognise issues like this?

    I guess the reason the problem exists is that no-one involved realises that it is a problem...


I reserve the right to delete inappropriate comments at my discretion