July 22, 2007

My love-hate relationship with warehouse clubs; or, why I didn’t renew my Costco membership

Filed under: Consumer — marcstober @ 12:14 pm

I didn’t renew my Costco membership this time. Not that $50 will break the bank but I have a hard time believing
that it’s really buying me convenience and savings. I think it’s time to take a look at my motivations.

We never went to these stores growing up; my mother preferred to shop in small quantities as she needed things and was more concerned with the week’s grocery budget. I liked to help her with the shopping but she was never wanted to pick the large sizes of things if they cost more, even if I was proud of my arithmetic skills in understanding it had a lower unit price. Today I guess they’d call her way “just-in-time inventory management” on a household scale. When we went to other people’s houses I was always envious of their well-stocked pantries. I can really wound up about little details sometimes, and not having the right plastic bag to pack my sandwich in or something would really bother me. I resolved to do things differently when I grew up. In shopping, like so many other things when you’re starting a family, you have to deal with tension between doing things you own way now that you’re the grown-up and being faithful to the way your parents raised you.

We had tried Costco once before we had a baby (we got a free promotional membership when a new store opened) and immediately rejected it. We didn’t have room in our small apartment for anything in bulk sizes. When we joined again we were in a larger condo, with a new baby. We’d been going to Target on almost a weekly basis to buy diapers and formula (at the back of the store, so you have to walk by everything else). It was around the time of the 2004 Presidential election and I remember hearing things about how despite Target’s cachet, Costco was more of a blue-state retailer, in terms of how it treated workers or something — I don’t remember exactly, it seems like there was a red state/blue state analysis of everything back then. Anyhow, having a family with children involves a certain amount of routine that makes it more practical to buy things in bulk.

This is the essence of the game: there are really very few things that it makes sense to buy in club sizes. I can easily count them on my fingers: toilet paper, trash bags, Ziploc bags, laundry soap, Diet Coke, juice boxes. The best part about Costco, by far, was never running out of these items (fulfilling that childhood dream I mentioned above). Wandering around that big store, though, it seems like a waste of time to go in and buy just those few things. Almost every food product we’d tried at Costco resulted in wasted leftovers; even nonperishable and frozen food loses its appeal eventually. I’ll admit there are a couple things – a coffee grinder; a large chromed-wired shelving unit – that I got a deal on at Costco and continue to enjoy. But far more often a trip to Costco ended with shopping time gone and a long shopping list remaining. If Costco helped save money it was as much by allowing us to buy cheap groceries at Trader Joe’s once the non-grocery items were crossed off the shopping list. (I give a lot of credit to the people who run main-line groceries stores like Shaw’s; they don’t get any respect but at least make an honest business of selling people things they actually needed.) The other side of the game is that you are supposed to pretend that you are buying at wholesale prices intended for business-to-business purchases; the membership fee is a bit of legal fiction that makes you “technically” qualify as a business. The whole thing seems offputtingly undemocratic to me – what do you mean my money is no good here if I’m not a “member of the club”? It’s true that the selection of products sometimes includes variations you won’t find at other retailers, including some things that resemble common food-service supplies; but the products at Costco are clearly intended to be sold to consumers, at least as much as they are at any other retailer. At my last job they bought break-room snacks and supplies at Costco, but we were a small software company; we didn’t buy computers there any more than restaurants confusing using Costco with Sysco.

What finally did Costco in for me was napkins and then plastic wrap, and then some funny business with a computer printer. (Oh, and diapers.) While it’s great to know that you can get a case of commercial-grade napkin-dispenser napkins when you need them, we stopped seeing the ordinary store-brand white household napkins. Then, while I’d had some great Costco plastic wrap, heavy duty, with a nice cutter, that I’d originally bought in a package of two 750 square foot rolls, the same product was now packaged in a single 3000 s.f. roll, that wouldn’t fit in my drawer. (The drawer that was a carefully considered part of the kitchen I’d just renovated for tens of thousands of dollars!) Then I was looking for a new computer printer, and in doing some research realized that Costco (a) had a different model number for the same HP printer you could buy elsewhere – it was actually a better price at Costco.com but felt sleazy and (b) it was $5 more in the store than online. Regarding diapers, while we aren’t buying them at the moment, Costco stopped carrying Pampers in favor of the store brand (or Huggies). All are adequate but we liked Pampers, and the bottom line in all of this is that if Costco isn’t going to be the go-to place for certain categories of household supplies, then they aren’t going to be a place we go to at all.

At least not for now. Actually I’m thinking of joining BJ’s instead. They advertise smaller sizes and, at least in our particular location, are closer to other stores in case they don’t have everything we need. The warehouse clubs like to advertise themselves as a resource for frugal households, but really they’re just a new way someone’s invented to part consumers with their money. But really it all boils down to making the never-ending need for toilet paper and juice boxes somehow interesting, and at 1000 words I can at least say it’s been interesting.

July 7, 2007

Serializing arbitrary Python objects to JSON using __dict__

Filed under: Software Blog — marcstober @ 9:58 am

Python is my favorite programming language and although I don’t (officially) use it at work, I keep it around for writing quick utilities for my own use. Lately I’ve been using it for some simple code generation.

Anyhow, as my little code generation utility got fancier I had the need to be able to serialize some objects into a text file, edit the text file, and deserialize it back into objects. Basically a poor-man’s configuration editor.

I’ve done this before with the Microsoft .NET Framework by using the System.Xml.Serialization.XmlSerializer class. There are a lot of quirks and subtleties to XML Serialization, but for this sort of simple task, it works well.

I don’t mind XML, but I thought I’d try serialization using JSON. In part just to try out the latest fad, but even more so because I’ve always wanted to try bulding something with YAML, and now that JSON is YAML, that seemed like the way to go. I was initially turned on to YAML because of its bulleted lists, which looked a lot like a to-do list I’d type out for myself, and it seemed like magic that this same format could be machine-readable data without any further translation (the same feeling you get from Python in general). Maybe it was magic, because I’d never really gotten YAML figured out (not that I spent so much time on it) and while JSON doesn’t have the bulleted lists it’s easier to understand overall. Essentially, JSON reduces all structured data to ordered lists or key-value pairs; it’s one of those things that seems so simple but that zillions of other data formats tried and failed to do.

The next question is which JSON parser to use. You can do just about anything with Python but there’s a bit of a dichotomy between the stuff in the standard library that follows the one-right-way principle, and newer things where there are still a few ways competing and you have to get a feel for what’s been accepted by the community. I first tried json-py, then after reading this, simplejson which promised to be more “extensible” (though to be fair, json-py is at least worth more than you pay for it).

It turned out I couldn’t do what I wanted to do in either (or any) JSON implementation, I got errors that my object is “not JSON Serializable.” It seemed that it wasn’t going to be quite so easy to serialize my arbitrary object to JSON. This led to a long bout of searching the web and comp.lang.python for answer.

(Fortunately by this point it was 5:00 on Friday. I couldn’t really justify figuring out a new object-serialization scheme as part of my day’s work, so it became a weekend-morning programming project of my own, which also means I feel more free to spend time blogging about it.)

I found a couple interesting things along the way. First, what I am really trying to do is pickle, the standard Python way of “preserving” objects (i.e., in vinegar?) – but it doesn’t use a human readable format (or just barely, they are strings). Second, there is an XML pickle, although I didn’t try it.

I was thinking I would have to write some subsclass of simplejson’s objects to do what I wanted, which really wasn’t what I wanted to do; the whole point was *not* to write my own serialization/deserialization logic. Then I realized that the reason it seemed so easy with .NET is because XmlSerializer didn’t just take an arbitrary object, it also needed to be explictly told that object’s type. The type information wasn’t contained or implied by the XML file, it was specified by the code calling the serialization and deserialization. In fact, when I’d first encountered this I had thought that the need to specify a type made XmlSerializer seem a little less “magic” than the general idea of dehydrating and rehydrating objects to/from text. Anyhow, once I realized that my objects needed to be translated to and from built-in data types in my own code, and I was okay with that, I found a really Pythonic way to do it, using __dict__:


import simplejson
class Person:
    def __init__(self, name=None):
        if name:
            self.name = name
people = [ Person('Marc'), Person('Rachel') ]

# Fails with error that Field class "is not JSON serializable"
#s = simplejson.dumps(fields)

# This is what we want.
s = simplejson.dumps([p.__dict__ for p in people])
print s

# Deserialize
clones = simplejson.loads(s)
print clones

# Now give our clones some life
for clone in clones:
    p = Person()
    p.__dict__ = clone
    print p
    print p.name

Of course, this doesn’t work for arbitrary object graphs, but it satisfys the “80/20 rule” of what I need most of the time.

Note that there are probably some security risks (at least) in rehydrating objects using __dict__ like this so make sure you only use this technique with trusted data, or come up with some other defensive mechanism.

Comments welcome.

July 2, 2007

Finally, the kitchen is done

Filed under: House Blog — marcstober @ 10:07 pm

I know I haven’t been much of a houseblogger; maybe I’ll do better when I’m doing my own projects. In any case, while it’s still fresh, I put together an album to document not only how things came out but why we did them that way (the magic is in the details):