4.28.2008

USC Programming Contest: 6th Place!

This past Saturday, I participated in the USC Programming Contest. As you can see here, they used my code as one of the sample solutions. More importantly, as you can see here, I slipped in just two minutes shy of 5th place! I would have gotten to choose a video game as a prize, but since I had to leave early to volunteer at the GLAAD awards, I had someone grab one for me. I realize now that since my taste in video games differs so much from most people's, I probably could have just asked the contest organizers to give me whatever was left, and it would have been something I really liked. Instead, I ended up with an FPS from the Medal of Honor series, which Andy assures me is badly designed, badly coded, and generally just not a good series of games. So I'll probably sell it. It's more about the glory anyway.

In any case, I'm pretty excited, and the GLAAD awards were fun too. We got to watch the show for a few minutes, including seeing Kathy Griffin win for best reality show. The GLAAD people were so grateful for our help, they let us take gift bags with all kinds of swag in them. One paper, one programming project, and three big dance performances away from the end of classes! Then finals, then commencement (playing, not graduating), and then Brazil!

4.10.2008

Star shapes

So I skipped Philosophy today and went to my CSCI 101 midterm pretty early. Before it started, I was talking to Ashley and Rollerblades Kid (I call him that because I don't know his name, but he uses rollerblades as his primary mode of transportation) about the impending midterm, and computer programming in general. Ashley has no programming experience other than this class, and she was telling me how she had been having trouble on a recent assignment with opening an input file. The relevant code would go something like:

ifstream fin;
string filename;
/* ... */
cout<<"Please enter filename: "; cin>>filename;
fin.open(filename.c_str());

I don't think I ever figured out, based on her description, what she had done wrong, but she said she contacted a friend who works at Google, and her friend had told suggested some sort of modification using character arrays in place of strings. It makes you wonder why, when C++ was designed, they didn't rewrite ifstream::open() to accept strings. I mean, you could just do:

void ifstream::open(string filename) {
open(filename.c_str());
}

C++ just seems so user-unfriendly after playing around with things like Javascript and Ruby. It would be interesting to learn the history of various languages, because programming languages do grow and evolve like spoken languages, but there are also some clear differences between the way they evolve. In any case, I suppose they use C++ for the 101 class because it's well established, and the people running the department probably aren't familiar with a lot of the newer languages anyway. Plus, C++ forces you to think a little bit about the way the computer deals with data, internally, when you pass things by reference, or try to access an array value that's out of range. I suppose that would be helpful when you get to classes on data structures. (One of many classes, by the way, that I should be taking this fall, but can't because it conflicts with a required physics class.)

However, Ashley is a chemical engineer. Many of the people who take this class are business majors. They're not taking a data structures class, and have no desire to become programmers of any kind. There really ought to be another class for such people. In fact, sometimes I think a few basic programming skills ought to be required of all students. However, I would never wish this particular class upon the student body at large. This other class would be like Physics 100, which I gather is a physics class for people who really don't like physics. It would probably be taught in some version of BASIC, maybe VBA since it's infinitely more useful for many people than any other language. Ideally, it would be something where students can type things in at a command line, rather than having to write, compile, fix compiler errors, recompile, test, fix runtime errors, recompile, etc. There would probably be no need to deal with OOP, but maybe they'd touch on it at the very end.

As it is, no one is going to learn anything from a single class like CSCI 101, especially when we spend more time worrying about things like header files than we do actually writing code. I guess that's the whole point of Ruby. The programmer's job is to write code, and the interpreter takes care of everything else, like memory allocation. Anyway, I have a few problems with the way our class is taught, as well, but I'm sure I'll post about that another day.

What I wanted to post about was actually an exchange with Rollerblades Kid. I was complaining about what I called "bullshit" on the test. I tried to reproduce one from today's test from memory, but Blogger tried to interpret the << operator as the beginning of an HTML tag and it got all messed up. In any case, we have a couple of functions that have a more or less random assortment of +'s, -'s, switch statements, if statements, arguments being passed by value/reference, etc. They don't correspond to anything real at all, it's just arbitrary data manipulation. We have to trace through the program, then write down the output it would generate. Admittedly, these problems are pretty simple, and I guess they're okay for test questions, but it completely goes against the principles of good code writing. You can't use descriptive variable names when your variables do not in fact describe anything.

In any case, Rollerblades Kid didn't seem that concerned with this type of problem, because he was used to them from the AP Computer Science test (which I didn't take), but he and Ashley both objected strongly to "Star shapes" problems. The kind which are supposed to print output like:

*
**
***
****
*****
******

or

*
***
*****
*******
*****
***
*

I must admit that, in modern times, when we have the ability to use "real" graphics, there is no need to learn this particular skill. Yet for some reason, I find it much less like a pointless busywork assignment than the "bullshit" trace problems. I think that's because it solves a real problem. Not real as in real-world. Just real as in, there's an actual problem with a non-trivial solution, and the code is that solution. Yes, it's a problem you may never face, but the same could be said of so many problems you're asked to solve as classwork. Still, it's hard to explain just what it is that, to me, makes Star Shapes problems seem not to be completely worthless. You can actually learn something about good programming style from such problems. But of course, there is absolutely no guarantee that will actually happen.