Monday, 30 September 2013

AI for Robotics/Python/Paging Woes

Just started the Artificial Intelligence for Robotics (a.k.a. Programming a Self-Driving Car) course online at Udacity: https://www.udacity.com/course/cs373.  TIL 1: writing Python on a mobile browser is hard; I got about halfway through the first section before I had to give up on working on my phone in bed with inconsistent whitespace and weird backspace behaviour and switch to a real laptop and keyboard, which was much nicer.  Python does not deal gracefully with ugly whitespace.  It's partly what makes Python so beautiful but definitely what makes Python sometimes frustrating.  But being able to get started into the course on my phone was definitely helpful for actually doing it vs maybe coming back later.  TIL 2: the functional features in Python are super handy - doing something to a bunch of things in a list is way easier with a lambda function and a map call than trying to awkwardly do the same in Java (http://docs.python.org/2/library/functions.html#maphttp://www.secnetix.de/olli/Python/lambda_functions.hawk)  TIL 3: self-driving cars are cool!  So far the course is really interesting, I like how the sections are really short so you can stop at any time, or go as far as you want.  We'll see if it's able to hold my interest for the entirety of the course or if I get bored and wander off partway through.

In other TIL today, be suspicious any time you add an if without an else.  At some point we'd added a check for an index out of bounds case in our paging code so we weren't taking a sublist bigger than the original list, but neglected to deal with the opposite, resulting in bad behaviour if our sublist was smaller than the second page.  I've now refactored out that bit of awkward logic into its own method and peppered it with unit tests covering all sizes of things (empty list, list less than one page of data, list exactly one page, exactly two pages, more than one page but less than two pages) and it's all working happily now.




No comments:

Post a Comment