So you want to write your own CSV code (2014)
I wrote my own CSV code.  That&#x27;s only about 10 issues, and I understand them all, and they&#x27;re easy to handle, and to test (unlike, say, threading issues, or OS bugs that don&#x27;t happen on my computer).<p>That wasn&#x27;t even close to being one of the more difficult parts of my program to write.  I&#x27;ve had to do zero work to maintain it.  I don&#x27;t seem to have ever had any bugs filed against it.  Are these supposed to be difficult?  Sure, don&#x27;t write your own encryption algorithm, and avoid touching threads if at all possible, but CSV?<p>Sure, I wish I could have used a library.  Unfortunately, once you start adding requirements, the options start to vanish.  It needs to be a C (or C-callable) library.  It needs to accept input as Unicode strings (lines), not just files on disk, or bytes.  It needs to return results line-at-a-time.  It needs to have a compatible license.  It needs to support the same package manager as I&#x27;m using (or be a trivial to include, like a single file).  It needs to be reliable (essentially bug-free, or at the very least currently maintained).  It needs to be fairly efficient.  What library supports all these?<p>&gt; Writing CSV code that works with files out there in the real world is a difficult task. The rabbit hole goes deep. Ruby CSV library is 2321 lines.<p>I love Ruby, but that file looks a little nuts to me right now.  The block comment at the top of csv.rb is over 500 lines long.  The Ruby module tries to do everything.  Just &quot;def open(filename, mode=&quot;r&quot;, <i></i>options)&quot; and its docstring are 100 lines long!  This class includes methods for auto-detecting the encoding, and auto-detecting common date formats, and some kind of system &quot;for building Unix-like filters for CSV data&quot;.<p>I don&#x27;t put all of that into my CSV parser, because I want my code to be modular.  I have features like data detectors and filters and open-file-by-filename in my program, too, but they&#x27;re fully independent, not tied to any one file format.  When I come up with a better way to detect dates in text, I don&#x27;t want to tweak a 6-line regex in every file format I&#x27;ve written.