Friday, April 6, 2012

Reinventing Time

Today, I pair programmed with a classmate of mine. His goal was improving his TDD skills. I found some old code dealing with conversion between string and date objects that was in dire need of refactoring. We first cleared out all of the code from the existing functions. My partner then wrote test cases one by one and I wrote code to make them pass. Here are a few of the things I learned:

  • Converting 24-hour time to 12-hour time is fairly easy with the help of a mod (%) operation
  • assertArrayEquals, not assertEquals, should be used for comparing arrays in JUnit (duh?)
  • SimpleDateFormat is a pretty useful class for simply formatting dates
  • Properly utilized regular expressions to split a string with multiple delimiters ("|", OR, is a useful regex character)

P.S. I would have to say that my level of self-awareness of copying code is II. Please see what the levels mean in my learning plan.

No comments:

Post a Comment