Yet more dangers of macros in C++

March 27, 2009 at 1:34 am (PT) in Programming

I saw some code:

std::string s = foo();
bar(s.c_str());

I tried changing it to:

bar(foo().c_str());

and things broke. It turns out that bar() was a macro that expanded to:

#define bar(s) do { struct st; st.someString = (s); baz(&st); } while (0)

(If you’re wondering about the do ... while (0), consult the comp.lang.c FAQ.)

This is fine for C code, but in the C++ world, this is dangerous. In this case, foo() returns an anonymous std::string object by value. That anonymous object then is destroyed after its internals are assigned to st.someString but before baz() gets to use it, causing baz() to be called with garbage.

Moral #1: Macros that don’t have perfect function-like semantics shouldn’t look like functions. For example, macros should be clearly indicated by naming them in all uppercase.

Moral #2: Use inline functions when possible. (In this case, however, the macro was provided by a C library.)

An attempt to measure the state of a relationship can affect its outcome.

Is one person genuinely interested in the other, or is it just polite fiction? Should that wave function really be collapsed?

(Not that I have the slightest clue about dating. And, yes, I’m probably overthinking all of this, although I make no admission to being smart.)

Follow-ups to earlier posts

February 20, 2009 at 7:41 pm (PT) in Personal

On CableCARD impressions:

  • It’s been suggested to me that CableCARDs might seem to have a high defect rate because the process self-selects defective cards. If a customer has issues with one, the cable company probably can’t tell if the card is actually faulty, so it likely throws the card back into the pool of available ones rather than returning it to the manufacturer. This means that if a cable company gives you an unboxed card, it’s probably one that someone else already returned.
  • After trying a Comcast set-top box at relatives’ houses, I think as annoying as it is for the TiVo HD to list channels I don’t receive, I’m grateful that I at least can hide them manually. Comcast set-top boxes don’t offer even that. (I’m not sure if they can hide the adult programming channels from appearing in the guide either.)

On Government bureaucracy in action:

  • And almost exactly a year after the last jury summons, my dad received another one. At least he didn’t receive an absentee ballot this time.

On Exit excitement:

  • I’ve recently discovered that the answer is: no, I haven’t.

People are strange

February 14, 2009 at 1:14 am (PT) in Personal

My mom’s cell phone rings. My mom’s upstairs, so I answer it.

A woman on the phone says, “Your ??? are ready. You can come pick them up anytime.” (She’s speaking very quickly, and she’s speaking loudly enough for there to be audio clipping. Plus, I get lousy cell phone reception at my house, so I can’t fully make out what she’s saying.)

“Uh, what?” (She’s not expecting to pick up anything.)

“??? are ready.”

“I’m sorry, could you say that again?”

“This is ??? and we’re calling about the ??? you ordered” (If someone asks you to repeat something, slow down!)

“I think you have the wrong number.”

She confidently replies, “No, I have the right number.” (A normal person would simply apologize and hang up, trusting that the called party knows what they’re talking about.)

“Exactly whom are you looking for?” (Isn’t this something she should have established from the start?)

“Martha.”

“There is no one named Martha here. Sorry, bye!”

The next day, she calls again. This time my mom answers the phone and has almost the same exact conversation. (The woman calling from the store is so loud that I can hear her over the cell phone speaker, again insisting that she has the right number.)

Vilifying Visa

January 18, 2009 at 4:29 am (PT) in Rants/Raves, Usability

After submitting a credit card purchase at Newegg, I was greeted with a “Verified by Visa” webpage:
Verified by Visa screenshot

This page is idiotic.

  • I was directed to this page without any warning.
  • The page uses the domain verifiedbyvisa.com, not visa.com. A tip to financial institutions trying to thwart phishing scams: pick one domain name and stick with it. People are going to be directed to this page automatically, so the address does not need to be memorable or even human-readable. Using other domain names is confusing and looks suspicious, and if users become accustomed to it, it opens the door for phishers to use their own, look-alike domains (such as, say, verifiedbyvisacard.com, which is available as I write this).
  • For goodness’ sake, register your security certificate properly and completely. “Run by (unknown)” is not reassuring, nor is being verified by “Thawte Consulting”. (I’m sure Thawte Consulting is a big name in the security certificate space, but are they as recognizable as VeriSign? Besides, VeriSign acquired them 10 years ago. Again, pick one name and stick with it.)
  • The page provides me with none of my basic, personal information so that I can have some assurance of whom I’m dealing with. Verification is a two-way street. Continuing to ignore this makes phishing easier.
  • The page outright lies to me. The button says, “Sign up to complete purchase”, but Newegg already emailed me my purchase confirmation. I shouldn’t have to say this, but lying does not build up trust. Duh.

Memorable Massachusetts milestones

January 17, 2009 at 9:11 pm (PT) in Personal

Even ignoring my flight cancellation fiasco, my trip to Massachusetts for Christmas/New Year’s a few weeks ago was particularly memorable, being full of a number of firsts for me:

  • It was the first time that I’ve played Guitar Hero.
  • It was the first time that I’ve used a Wii Fit.
  • It was the first time that I’ve played Brain Age. (I apparently impressed my cousins by getting “jet speed” on the basic arithmetic tests. I stink at Sudoku though, but I already knew that.)
  • It was the first time that I’ve tried Comcast video-on-demand. I’m thoroughly unimpressed by the selection. (It was particularly disappointing considering that Comcast misleadingly includes its video-on-demand selection in its advertised comparisons against DirecTV.) I like Netflix Instant Watch on TiVo better.
  • It was the first time that I’ve rented a car.
  • It was the first time that I’ve driven in Boston. I hate rotaries.
  • It was the first time that I’ve (sort of) driven on snow. Okay, it was mostly limited to driveways, but that was still plenty scary for me. The streets I drove on were plowed.
  • It was the first (and hopefully the last) time that I’ve been in a car while it rolled over. (No, this isn’t related to any of the previous items. I wasn’t brave/crazy enough to drive while it was snowing. And yes, everyone thankfully escaped injury.)

The uncanny valley of intelligent software

December 23, 2008 at 1:52 pm (PT) in Usability

There’s a phenomenon in robotics called the the uncanny valley. It’s also commonly used in the context of computer graphics, where cartoonish characters (e.g. The Incredibles) are more acceptable than those that aim for realism but fall short (e.g. The Polar Express, Beowulf). It’s also been used in the context of user interface look-and-feel. I think there’s an uncanny valley for “intelligent software” too.

Software is becoming increasingly complex, and it’s not uncommon for programs to provide knobs to control their behaviors. Providing too many knobs, however, can overwhelm a user with choices. Programs can combat this by providing fewer knobs and picking default settings appropriate for common use cases, and by trying to do more actions automatically for the user. They can go too far, however; programs that try to make too many decisions on their own become more mysterious, sometimes seeming unpredictable, out-of-control, and annoying.

The Microsoft Office Assistant (“Clippy”) seemed like a good idea at the time, but it was artificial intelligence gone awry. It tried to be smart to recognize when users needed help, but it wasn’t smart enough to know when it was unneeded or when its advice was off-base. Similarly, this is also one of the reasons why I hate Facebook’s “News Feed” (nee “Top Stories”). Facebook uses some unknown weighting algorithm to pick which items to show in what order, but it ends up seeming random; some items seem chronological, but some aren’t.

This is something we deal with at VMware; we provide a number of knobs to allow users to tune virtual machines for their needs. Some settings don’t make sense when used together though. At what point is this obvious, at what point do we take the easy way out and display a message explicitly explaining that enabling option X will disable option Y, and at what point does the message itself become an annoying obstacle?

I confess that I don’t know that it’s actually a valley, though; it could just as easily be a cliff. Are computers that act perfectly like humans really what we want? Humans often don’t do a good job of understanding what other humans want either.

We originally had a flight at 9:55 PM yesterday night from San Jose to Boston with a connection in New York. JetBlue calls us on Sunday afternoon to tell us that our flight is cancelled and to reschedule through their website. By the time I get home to get online, the next available flight it offers me is four days later, arriving the day after Christmas. Lame. The website also offers to give me a refund, which is useless with such short notice.

I call JetBlue to see if there’s anything else they can do (maybe put me directly on another airline?), but they say no and that the Thursday flight is my only choice. Sigh. (Can’t some of the passengers on the next day’s flight be bumped off to make room for us? Is it really more fair to screw some passengers a lot rather than screwing a lot of passengers some? Debatable, I suppose.)

After I hang up and start looking at other airlines’ offerings, I realize that I have two other major airports at our disposal: Oakland and San Francisco. The JetBlue web page for rescheduling cancelled flights doesn’t allow departing from a different airport, but attempting to a book a flight direct from Oakland to Boston shows that there are available seats on a 9:15 PM flight that night. I call JetBlue back, ask if I can be put on that flight, they confirm that will work and reschedule me, noting that the flight is delayed to 11:05 PM.

After I hang up, I decide to check the flight status to see if it’s delayed any further. JetBlue’s website says that it too is cancelled. What? Did the agent just reschedule me to a cancelled flight? The website still lets me book seats on that flight. I check again an hour later, and now it says that the estimated departure time is now 10:45 PM but still claims that it’s cancelled. (Why is the departure time changing to a supposedly cancelled flight?) I call JetBlue back and ask. One agent says that the flight does appear to be cancelled. Another agent says that it isn’t. I tell each of them about the conflicting information, they put me on hold while they double-check, but I get disconnected before either can get back to me.

I check with Oakland Airport. Surely they’re the final authority on knowing which flights are actually departing from their runways. Their website says that the flight is not cancelled and that it’s scheduled to depart at 11:30 PM; I call them to confirm, and the lady there says 11:05 PM. (She also explains that the flight was cancelled earlier that day but that they decided to go through with it after all.) Even when we show up at the airport, the departure time at the gate says 11:10 PM, but the airport’s computer screens say 11:20 PM. Wacky.

Our flight actually did manage to leave (at around 11:30 PM), and we did manage to arrive. Phew! It could have been a lot worse (and was for a lot of other people).

CableCARD impressions

September 20, 2008 at 10:42 pm (PT) in Rants/Raves
  • I have no idea why CableCARD has such weird capitalization.
  • It’s surprising how CableCARDs—solid state PCMCIA devices—seemingly can have such a defect rate. Most people I know who’ve tried to set up a CableCARD have had to exchange them at least once. Also, since CableCARDs must be paired with the device they’re connected to, it’s hard for Comcast to test them beforehand, and it’s easy for them to shift blame to the device manufacturer.
  • I think it’s funny that the Fremont Comcast office has a wall of televisions in its customer service lobby, but they’re all standard-definition CRTs. There’s not a single high-definition television in sight.
  • Comcast’s website is really confusing, and they do an awful job of explaining the differences between different plans.
  • The non-local HD channels that Comcast carries seemingly are from Eastern feeds and aren’t time-delayed for Pacific time. What the heck? On one hand, I guess it (sort of) increases the available choices of what to watch when, but on the other, I think it’s confusing. It’s not like this is the Central time zone, which is accustomed to being the Eastern time zone’s gimp.
  • It’s annoying that the TiVo HD lists hundreds of channels I don’t actually get; can’t the CableCARD figure that out? Or maybe Comcast intentionally wants to show people all the channels they could be getting if they signed up for a more expensive plan.
  • TBS’s stretch-o-vision is lame. I don’t know how people stand it. Their argument about not confusing viewers with pillarboxing would hold more water if every HD channel did the same thing, but luckily most channels aren’t that stupid. So instead people end up with a mixture of pillarboxed 4:3 content on some channels and distorted 4:3 content on others, which is more confusing. If they want to avoid complaints about black bars, they could do what ESPN sometimes does and show big station logos on the sides. I’d even prefer (non-animated) banner ads.

Oski M. Wizard

August 28, 2008 at 11:59 am (PT) in Personal

Structure and Interpretation of Computer Programs is easily my favorite CS book (although I confess it is the only one I’ve actually read). Its exercises happen to utilize characters named with double entendres: Alyssa P. Hacker (“a Lisp hacker”), Cy D. Fect (“side effect”), and Louis Reasoner (“loose reasoner”).

When I was a teaching assistant at Berkeley for its SICP-based course, I created my own character: Oski M. Wizard (“a Scheme wizard”). The name was perfect since “Oski” is the name of U.C. Berkeley’s mascot, and SICP is also known as “the wizard book” due to its cover graphic.

Sadly, he never got much exposure. I tried to get Professor Fateman to use him on one of his exams, but I think he didn’t understand the joke. (I probably should have pitched it to Professor Harvey instead.) At least I managed to use him in some practice exercises I gave to my section (which is more than I can say for another character I made, Sue D’Coda).

Poor Oski. And he so desperately wanted to impress Alyssa.