Fun With Coding
Sep. 7th, 2012 10:32 amSeveral jobs ago, I was assigned to track down a particular bug in our firm's main web application. In the process of doing so, I found that, for reasons unknown to me, some of the data was being passed around in comma-delimited strings, like so:
"foo,bar,baz"
Well, okey-doke, if you wanna, sure.
It also transpired that, in this context, a zero-length string could be a perfectly valid piece of data, like so:
"foo,,bar"
Foo, then nothing, then bar.
It also-also was true that the number of pieces of data could vary from zero to some arbitrarily large number.
"foo"
"foo,bar"
"foo,,bar,baz,bax,,scott,jean,hank,warren,bobby"
","
That last, of course, represents two pieces of data, both of them being zero-length, separated by one comma.
It turned out, after (not too) much noodling, that the problem was that this system had no way of distinguishing between "no data whatsover" and "one piece of data, which is zero-length". They're both represented by the same comma-delimited list, "". I ended up having to write an encoder-decoder that turned zero-length pieces of data into something unlikely to occur in actual code, like "[[]]". Not too much later, I moved on to somewhere slightly more sensible.
"foo,bar,baz"
Well, okey-doke, if you wanna, sure.
It also transpired that, in this context, a zero-length string could be a perfectly valid piece of data, like so:
"foo,,bar"
Foo, then nothing, then bar.
It also-also was true that the number of pieces of data could vary from zero to some arbitrarily large number.
"foo"
"foo,bar"
"foo,,bar,baz,bax,,scott,jean,hank,warren,bobby"
","
That last, of course, represents two pieces of data, both of them being zero-length, separated by one comma.
It turned out, after (not too) much noodling, that the problem was that this system had no way of distinguishing between "no data whatsover" and "one piece of data, which is zero-length". They're both represented by the same comma-delimited list, "". I ended up having to write an encoder-decoder that turned zero-length pieces of data into something unlikely to occur in actual code, like "[[]]". Not too much later, I moved on to somewhere slightly more sensible.