Hacker News new | ask | show | jobs
by actually_a_dog 1550 days ago
I like your criteria, so I'm going to put a question I used to ask in interviews up against it: let's write (and test) the world's worst JSON encoder, in TDD style. The ultimate goal of this question was to end up with a function (in Python, when I was asking it) that could JSON encode primitive types, along with lists and dicts. No fancy stuff about trying to figure out what to do with general objects or anything. No worrying about circular references. No tricks. Just take a Python data structure as input and output a string representing a valid JSON encoding of that data structure.

1. You need to know how to write a half decent test case, and, for full credit, how to write a recursive function. Check.

2. As alluded to in the previous point, we can judge the quality of the test cases. So, I think this is at least a provisional pass.

3. A really good candidate can talk about issues like Unicode, how to handle or avoid stack overflow, dealing with circular references, maybe think a bit about optimizations.

4. Unless you consider recursion to be "fiddly code," then we meet this criterion as well. I allowed people to use str() or repr() to convert things to strings, so there was no incidental difficulty there, either.

5. Nope, no tricks. Just use recursion.

So, it looks to me like I had a pretty okay question.

Anybody take issue with any of what I wrote, or have any suggestions for making it a better question?

1 comments

It sounds like a pretty good question to me.

As a follow up you could scope out how familiar the candidate is with alternate encoding options and what the trade-offs and use cases are. (BSON/MessagePack, Protobuf/Avro/Thift, FlatBuffers/Cap'nProto).