Tuesday, January 20, 2009

PROG2020 Assignment 1. Line Editor

My two classes with Brian this semester are PROG2020 (Data Structures) and PROG3060 (Adv, OOP). We use C++ in our Data Structures class, while our code for Advanced OOP is written in C#. Although I like writing in C++, I must say that my initial exposure to C# has left me eager to write applications using it. It seems like a powerful and intuitive language.

First term was a bit of a challenge for me - I had a job that limited the amount of time I could put into my study, and it affected my comprehension of later C++ topics like polymorphism. The first two weeks have been a real boot camp for getting into coding shape, but I've enjoyed the quick pace. It's a lot easier to keep up with the pace of the class when I have time to set up and get ready. Showing up 30 minutes late isn't as conducive to making class time productive.

We've been given our first two assignments - for Data Structures, we've been asked to write a simple line editor that employs a structure called a linked list. A linked list is a data structure in which units of data are organized by means of pointers. The linked list is composed of nodes: each node is a data object that itself contains 1) some sort of data and 2) a pointer. This pointer carries as its value the address of the next node in the list; that next node also contains some sort of data and a pointer. That pointer, in turn, points to the next node, and so the chain continues, organizing the nodes into a linked list.

The line editor works by treating a text file as a set of written lines - each line is distinguished in the text file by ending with a carriage return. A linked list is used to store a file's text while it is being edited; each node in the linked list stores a string that corresponds to a line in the text file, as well as a pointer that points to the next node.

New lines can be inserted into the text by inserting a new node into the linked list, and lines can be deleted by deleting nodes. The text edits can be saved to the text file by iterating through the linked list and writing the string variables to the file.

I worked with Emily VanZeumeren on this assignment, and we gave ourselves the challenge of building a line editor that followed Brian's example as closely as possible. I wanted to treat the assignment as a request from a client, and that meant making the program work as requested. Emily and I talked over what we needed the program to do in order to achieve this - it forced us to think in detail about the user experience as described by the assignment's example, by the assignment's rubric, and by the verbal explanation in class.

We put the final touches on it today - code was formatted, variable names were standardized, etc. - and we made a few slight additions to the requested spec. We added one keyword - "help" - as way to print to screen all of the line editor's commands. We also have a two-line text output above the command prompt when the program launches. The additions are pretty slight and I think they offer some value, but part of me balked at even that deviation from the model. Overall, I'm really pleased with it - it functions as requested, and it closely mirrors the way the editor was outlined to us.

Our second program is going to be a chat client. I'll blog on it after we're done making it.

No comments:

Post a Comment