Switching CSV libraries

  • Setup
  • The types
  • Decoders
  • Generating the histogram
    • Finding “Julie days”
    • Generating ranges
    • Counting tweets within a range
    • Printing the histogram
  • A difference in our histograms

For our four-year “anniversary” of becoming Twitter pals, I decided to see how this program looks written with a different library. I decided to use the sv library which didn’t even exist when Chris wrote the first version of this program.The sv library on Hackage. Twitter no longer provides your archives in CSV format, and I don’t have an archive of my own tweets that is old enough to be in CSV format, so I couldn’t analyze my own tweets with this program. For those reasons, I used Chris’s old tweet archive, and so my goal with this program was to produce a histogram that matched Chris’s original.

This is my first time writing a CSV-processing program. I had, of course, read Chris’s original code before I started writing this, but to be quite honest, I found it extremely difficult to read and understand. I have never been a Scala or Java programmer, and I don’t think in terms of one big main where all the action happens. It’s difficult for me to read such programs, and it’s nearly impossible for me to write them. So, what I have done here has ended up being quite different from his original program, and even fairly different from his refactored program. I didn’t read his refactored program before I wrote this, at least not until near the end, and I was surprised to find that, despite how different so much of our program looks, some of it looks exactly the same.

I was very happy with my decision to use the sv library here. It’s not really a CSV-parsing library; it’s a set of combinators and wrappers around a CSV-parsing library. It uses a library called hw-dsv The hw-dsv library on Hackage.for the parsing, and there is an sv-cassava The sv-cassava library on Hackage. package that provides the sv set of combinators and types but uses cassava for the parsing. As such, I’m not going to be discussing how the parsing gets done at all, instead focusing on using the sv package.

Sign up for access to the full page, plus the complete archive and all the latest content.