Forgetting the first thing you learned about user interaction

The following is a pretty common problem in introductory programming textbooks:

 

Design a program that represents a vending machine. Return change using the fewest number of coins possible.

 

I solved this problem three times that I can remember: the first in Visual Basic (where I had to write a vending machine GUI), the second in C++, and the third in Logisim, a circuit simulator which I had to use to implement a sequential logic circuit. I imagine most programmers did something like this when they were students; it’s easy to understand, and a good test of many of the basic programming constructs, like conditionals and loops. But it’s also a good introduction to the kinds of things programmers should think about when designing a user interface, because of course, it’s much nicer for a vending machine to return 35 cents as one quarter and one dime than for it to give you one nickel and thirty pennies.

I was in the grocery store today buying about thirty dollars worth of stuff at the self checkout. I happened to have a hundred-dollar bill on me, so I stuck it in. The machine owed me sixty-five dollars in change, so it spat out sixty-five dollars. In five dollar bills.

Thirteen five-dollar bills.

There were bills falling all over the floor. I had to kneel down and snatch them all up before people started diving across the floor for them. When I shoved them all in my wallet, I think they stretched it out so badly that it’ll never be the same shape again.

The self checkout is a computer. It appears to run Windows XP; at least, it has the same blobby blue visual style. Yet it seems that it was programmed by the only programmer ever to avoid doing a “make change using the fewest coins possible” problem in school. Either that or the programmer just completely forgot about this problem, and also forgot that people like getting change in a way that doesn’t remind them of a piñata scramble at a kid’s birthday party, or a Vegas slot machine.

Advertisements

The Beauty of C++

It’s pretty widely acknowledged that C++ is not a very nice language.

Some people hate that it still has pointers. Some people hate that it now has references. Some people hate that it now has pointers and references. It has just enough library support that some of the utilities are useful, yet professors can keep track of them all and specifically forbid you from using all the useful ones on programming assignments. It has nice features like templates and operator overloading, but makes them so painful to use that you almost wish it didn’t. (Did you know that the stream operators must be overloaded as stand-alone functions, not as member functions of the class? Otherwise you get bizarre, nonsensical compiler errors that can’t be fixed until you vaguely remember reading in your C++ textbook two years ago that the stream operators must be overloaded as stand-alone functions, and then dig out said book and look it up to confirm.)

In fact, it seems that there’s only one person in the world who didn’t get the memo about the uncool nature of C++, and that person happened to be sitting in front of me on the first day of my undergrad discrete math class.

At UC Davis, the first programming course for majors focuses on C, without worrying about object oriented anything. The second programming course for majors covers C++ and object oriented everything. I was also enrolled in the C++ class that term, and during the first session earlier that morning, the instructor (a hardassed security research guy) had finished his introduction to C++ by telling us that it was a horrible language.

See, he knows that C++ is uncool.

But the guy sitting in front of me in discrete math had a different opinion: he insisted to his friend in a loud voice that C++ was—well, if someone had a gun to your head and would shoot you unless you could say something positive about C++, what would you say?

Stroustrup tried his best. He came so close to incorporating object orientation into C.

He gave it the old college try.

It makes some things easier than C.

It’s better than Cobol.

It’s fast.

It’s fast.

It’s fast.

He didn’t say any of these things.

He said it was beautiful.

He said “Yeah, I’ve looked at some C++ code, and man, it’s beautiful.”

He didn’t say it sarcastically, like “It’s beautiful. Yeah, man. Just beautiful.

He said it passionately, like a hot-blooded young man swept off his feet by a beautiful and mysterious woman.

He said it as if he’d seen C++ at the masquerade, shared a flirtation, danced with C++, tangoed with C++, spun C++ around with a rose clenched in his teeth, and then when he was done he’d said “So, C++. Shall we meet again?” And C++ replied “At the next masquerade. Look for me at the rise of the full moon.”

Of course, some of us had a similar flirtation with C++ when we were young, hot-blooded, bucks who had just recently chosen the manliest major around and were feeling invincible. But a year or so of its prima donna antics convinced us to leave it. The drama C++ brings to a simple act like making sure the correct override of a derived class method gets called through a base class pointer, the hysterics around templates, the fights over accepting instances of the string class instead of pointers to char; sure, it adds spice at first, but eventually it just gets to be too much. Maybe you feel manly at first, like you’ve conquered the most desirable woman in the world, but eventually you just get tired of fighting with C++ over even the smallest things. Eventually you just want a safe, plodding, homely sort of language, like Java. Sure, it’s not too bright. You have to explain everything to it at untoward length. It lacks those spicy features like operator overloading, and it doesn’t always do things in the smartest or most efficient way. But it’s a hard worker and is biddable enough if you give it what it needs. It never does something so hotheaded as seg faulting.

At this point, I had already taken two semesters of C++ programming, one general introductory course and one data structures and algorithms course. For me, after a year, the romance with C++ was over, and I was starting to discover all the warts and moles and festering gumboils it keeps hidden under its flamenco gown. Probably the most festering of all the gumboils, at least as far as being the ugliest and most idiotic syntax I could possibly imagine to represent the concept, is the “virtual void belch() = 0” syntax for declaring pure virtual functions (“abstract methods” for Java people). Other genius syntax decisions were requiring a semicolon at the end of class and struct definitions and requiring a space between angle brackets in nested template declarations.

You also might expect a beautiful language to make it easy to write beautiful code—beautiful in the sense of shorter, simpler, easier to read, expressed at a higher level of abstraction. C++ does none of those things. If anything, it does the opposite; it’s frequently easier to write the ugliest, most godawful thing you can imagine than anything halfway decent, because the language contains no infrastructure to help you write the nicer solution. For example, I can’t even count the number of times I’ve dealt with text using some variation of reading a single character at a time, clumsily saving some number of them in an array, and examining the whole mess with a huge, ugly if-else if-else if-else if-else if-else if-else-if else-else statement. I could have taken the high road and written my own regular expression engine, but with C++, go too far and it could end up screaming at you for three hours and then storming off to stay with its lover, refusing to come back until your deadline has passed.

C++ has its uses. It’s fast. It’s better than Cobol. It supports object orientation somewhat better than C. But one thing it is not is beautiful.

Thus I fulfill my rite of passage. I have rejected C++. I pass the test, and remain a programming blogger.

Why I would make the worst peer counselor ever

I discovered today that my university (UC Davis) has a facility called The House. Although it sounds like a Soviet reeducation facility, it’s actually a place where you can go to discuss your problems with peer counselors, people near your own age who understand the problems of young people nowadays.

I’m actually older than most of my schoolmates, but not enough to explain my total detachment from their reality. If I became a peer counselor, it would be disastrous. It would probably go something like this:

 

Distraught girl: I just broke up with my boyfriend.

Me: How terrible. Tell me about it.

Distraught girl: We started going out six months ago, and at first he was great, but then he started hitting me. <choked sob> And I always got the feeling he didn’t really respect me. He said one time “If we’d met before you were in college, you wouldn’t be in college. You’d be pregnant and barefoot in the kitchen.”

Me: How despicable. You were right to leave him.

Distraught girl: And he never put down the toilet seat!

Me: Okay. I’m failing to see how that follows from what you said before, but okay, we’ll accept as an axiom that that’s a crime on the level of misogyny and domestic abuse.

Distraught girl: But the worst part is, I still love him! I really need some help. How do you stop loving loser guys?

Me: I don’t know. But I think this book can help you. It has answers to every question you might have, and solutions to every problem, or at least an approximation algorithm if your problem is NP-complete. It’s called The Art of Computer Programming.

Distraught girl: Where can I find a solution to my problem?

Me: In Chapter 10. Unfortunately, Knuth won’t be finished with that volume for another fifty years. But until then, can I interest you in statistical tests of randomness, or are Latin squares more your thing?

 

Maybe it’s just a general rule that both English majors (which I used to be) and CS majors (which I now am) live in their own alternate realities where Wordsworth or Knuth has the answer to every problem.