Wednesday, July 6, 2011

first OO step

I want to keep my C learning as straight C right now and not try to dabble in C++ or Obj-C quite yet. I'm going to use Python to experiment with object oriented programming. Hopefully once I get my head around OOP it will translate to C++ or Obj-C if I get around to that.

There isn't a Project Euler for OOP concepts (to my knowledge) but I think I have a good idea for a project. I mentioned before my interest in using Python to parse a CSV file so that I can extract certain information from it that's not quickly doable by hand. I made a test CSV file:

 

It's just example data that mimics what my support tracking spreadsheet looks like (but converted to CSV). There are many ways of formatting CSV and it's important to note that columns that include commas that aren't to be used as separators of columns have quotes around them. The columns are as such:

Date Added: This is the date I entered the case. They are always in chronological order.
Date Closed: The date that the issue is resolved. If this column is blank it means the case is not closed.
Group: The company the user is with
Contact: The person I interact with in the company on the issue. It's usually just one person but every so often I'll include two names separated by a comma.
Issue: A description of what's going wrong.
Notes: This is where I keep track of my thoughts on the matter. In the real thing I have a system for tracking my thoughts across multiple days by prefacing an entry with "UPDATE 7/5/2011: " but I left that out for simplicity until I learn more about parsing CSV in Python.
Database: If there are returns or orders made in our shipping database in regards to a support case I include the relevant numbers or names here.
Tags: This is experimental but I really want to use it. Tags are semi-standardized classifications that I'd love to use for searching. My goal is to be able to search for any case with a specific tag or tags, and obviously count cases with certain tags to keep track of what's having the most problems.

I'm an OOP newb so I'm not quite sure how to arrange the data and operation on the data into classes. If I were to do this in straight C I'd define a struct that has each of the columns as a member, and then I'd have an array (or linked list) of these structs such that each element of the array held all the info of one case (one row in the CSV file). If I wanted to print out every case that had the tag "XYZ" I could easily scan through the array and find them. This seems very straightforward to me but the goal here is to use OOP which right now doesn't seem straightforward but hopefully it will later.

Should I define a class that represents a case? What methods would that class contain, and how would the data for that class be stored? Maybe one useful method in a class would be to return how long it took for that case to close (and return NULL if the case isn't closed).

But then how to I store all of the unique instances of the classes that basically represent every line in the CSV? Then we're back to arrays. Can there be an array of instanced classes? How do I initialize each class such that it will be filled with the data from one line of the CSV, and how do I keep track of where I am in parsing the CSV? Should the functions that do the parsing be contained in a class of its own?

Headache. I feel like this is unnecessarily difficult but maybe by the time I work through those intro to Python documents I'll know enough to ask better questions.

No comments:

Post a Comment