A couple of years ago, I went into a big-box shoe store and bought a pair of sneakers. At the checkout counter, the cashier grabbed a can of that bogus silicone spray stores always try to up-sell you. It's supposed to make sneakers shiny and waterproof, but it doesn't seem to do anything.

Before I could protest, she put it in my bag and said, "I'm giving it to you for free." OK, I thought. If it's free, it's free. I can always throw it out when I get home.

But I was still suspicious, and just before tossing the spray can into the trash, I looked at my receipt. Sure enough, there was the shoe spray, priced at $12.99. But there was also a discount of $12 on the price of the shoes. So the can wasn't really free: Factoring in the discount, it was a 99-cent rip-off.

I was angry, and I thought about going back to complain, but for 99 cents, it didn't seem worth the effort. Instead, I vowed never to buy shoes from that store again.

Later, I figured out what had probably happened. This is speculation, but I'm pretty sure that the cashiers were told to push the silicone spray, which customers didn't really want but which probably produced huge profit margins for the retailer. Cashiers, I'm guessing, were rewarded with a substantial commission when they made a sale, and the shoe store had probably put in place various contests with prizes for selling the most cans of shoe fairy dust.

But the wily cashiers had figured out a way to apply a discount to shoe sales. Maybe they kept newspaper coupons in their pockets, or maybe they just had the authority to give discounts on the spot. However it came about, they had developed this little ploy whereby they sold people spray they didn't want. Most customers probably didn't notice the 99-cent discrepancy, and the cashiers earned a few extra bucks in commission.

I can picture the M.B.A. who worked at corporate headquarters. I bet he reaped a big bonus for coming up with an incentive program that dramatically increased the sales of the high-profit silicone spray.

Meanwhile, did anybody notice that the sales of shoes fell by about the same amount?

Or that I started buying my shoes on the Internet?

I'm always on the lookout for these incentive schemes gone wrong. There's a great book on the subject by Harvard Business School professor Robert Austin -- Measuring and Managing Performance in Organizations. The book's central thesis is fairly simple: When you try to measure people's performance, you have to take into account how they are going to react. Inevitably, people will figure out how to get the number you want at the expense of what you are not measuring, including things you can't measure, such as morale and customer goodwill.

Suppose, for example, that you want to increase profits. You can't just tell cashiers to "increase profits" -- they won't know what to do. You are the smart one with the corner office and the subscription to Inc. You presume that a $13 add-on sale won't sound like a lot to a consumer after the person has already committed to a $100 pair of sneakers. You know the markup on silicone spray is just enormous, meaning huge profits. And you think that the easiest way to get your cashiers to push the add-ons is to give them bonuses when they do.

And for a few days, it works. Until the first cashier figures out the trick to selling even more silicone spray. And you are going to be real surprised when the latest income statement is prepared and your earnings are surprisingly limp, and more customers seem to be buying shoes from Zappos.com and you don't know why.

But anyway, back to Austin, the Harvard professor. His point is that incentive plans based on measuring performance always backfire. Not sometimes. Always. What you measure is inevitably a proxy for the outcome you want, and even though you may think that all you have to do is tweak the incentives to boost sales, you can't. It's not going to work. Because people have brains and are endlessly creative when it comes to improving their personal well-being at everyone else's expense.

As some of your workers substitute making the most of an incentive program for serving customers the best way they know how, the customer experience will suffer. Your best employees will find themselves fighting with incentive seekers to keep the business on track. Meanwhile, they will begin to lose faith in your judgment.

Here's another story. About a year ago, before the CompUSA chain was finally liquidated, I went into my local branch to pick up a few small items: a new keyboard, an iPod, and some other stuff. I was next in line at the checkout counter when a CompUSA employee grabbed me. "I can help you over here," he said. "No waiting."

He led me to a windowless back office with a handful of shabby cubicles. Instead of using a cash register and a bar-code scanner, he typed my credit card number and the information on the bar codes manually into some kind of mainframe terminal. He insisted on taking down my address information, too. The process took forever. The guy kept making mistakes and having to go back to the previous menu of options. At one point, he wandered off to get help. And when he was done, he asked me if I wanted a bag. Of course, I said. He wandered off again to find one.

This was not a normal retail experience, I thought to myself. And then it dawned on me: This wasn't a retail experience at all -- this was a corporate sales department. My guy had been hired to sell computers and peripherals to business accounts, and he likely got paid on commission, unlike the cashiers in the front of the store. He was probably supposed to cold-call corporate purchasing agents all day. When he couldn't make a living doing that, he got in the habit of going into the adjacent store, grabbing a real, live retail customer, and misrepresenting his or her purchases as a corporate sale.

Net result: The customer was annoyed by the longer checkout, CompUSA probably paid a commission it shouldn't have, and time and effort were wasted.

But wait -- the story gets better. The iPods were kept in a locked cage so that nobody could steal them. So my corporate sales rep took me with him to find his manager, who had the key. But the manager was busy mediating an argument between another sales rep and a customer, which I watched, amused. The customer wanted to return the extended warranty on a large purchase she had just made. The manager acknowledged that CompUSA's returns policy covered an extended warranty (which, as everyone knows, is almost all profit for a retailer). Still, the salesperson objected.

At first, I thought that the customer had been duped into buying a warranty she didn't want and was trying to return it, so it was unclear why the clerk was giving her such a hard time. But then I realized that the argument was over the fact that the salesperson had given the customer a discount on the merchandise, paid out of his own pocket. In exchange, the customer had agreed to buy the extended warranty, which would have resulted in a nice bonus for the clerk. Now she was returning the high-margin warranty while happily pocketing the discount. The customer had double-crossed the sales clerk!

So, this was my retail experience: Instead of buying the exciting new products I wanted, I was hurled into a mass of people scamming one another -- and all because of stupid, perverse commission systems that seemed like good ideas to the M.B.A.'s back at corporate. Well, CompUSA is gone now -- the remaining assets and the brand name were bought by a competitor -- but I'm confident plenty of retailers will continue to push extended warranties and bottles of silicone spray. Let me know how that works out.

At my company, we were worried that the same thing would happen if we paid salespeople on commission. I had a recurring nightmare of salespeople gone crazy, going to ridiculous lengths to make sales and ruining Fog Creek's hard-earned reputation as a friendly, win-win kind of company.

But we soon realized that commissions weren't the only management tool at our disposal. We simply established as a rule the idea that gaming the incentive plan was wrong and unacceptable. Employees generally follow the rules you give them -- and if they don't, you can discipline them or, in extreme cases, dismiss them. The problem with most incentive systems is not that they are too complicated -- it's that they don't explicitly forbid the kind of shenanigans that will inevitably make them unsuccessful.

Joel Spolsky is the co-founder and CEO of Fog Creek Software in New York City and the host of the blog Joel on Software.