image

Chapter 13 - Unit Testing

This chapter’s basic message is - “Write Unit Tests”, " Code later". This is one of the programming approaches that is popularly known as Test Driven Development. Some of the points I learnt from this chapter are

  • You have subclass the unittest module so that you can use all the useful features of the module in your own function
  • Each individual test that you write takes in no arguments. It returns no value whatsoever. If the method exists normally with out raising any exception, the test is considered passed
  • TestCase class provides a method called assertEqual to check whether two values are equal.
  • There is also a method called assertRaises to check whether the code fails for bad input. Instead of calling manually the function, passing in the argument and then checking whether it raises a specific exception, assertRaises is a goodway to check this all in one single function call
  • Each test case should handle only one question
  • Each test case must be able to work independently of the other test cases

Chapter 14 - Test First Programming

The purpose of this chapter is to show code development via testing. In the previous chapter, set of unit tests were written for testing the conversion from number to roman numerals and roman numerals to numbers. Through a series of Python programs, the chapter manages to come up with an all tests-ok code. I particularly like this idea of writing tests before even you start coding. It will force one to think of all the possible ways to develop a nice set of code.I tried doing this with out looking at the author’s working and I found the solution in the book far more elegant than my code. It never occurred to me that you can use regular expressions for checking the correct input for the conversion code. Overall one of the best chapters in the book.

Chapter 15 - Refactoring

By adding some more functions to the roman numerals problem, the author shows way to refactor the code.

Chapter 16 - Functional Programming

  • map and filter functions have been in Python forever. List comprehensions have been introduced since Python 2.0.All the three functions are very useful when you want to vectorize stuff. If you have already coded in MATLAB or R, vectorizing is the way you think and code Thankfully List comprehensions enable to you to think in vector centric way After coding with map, filter and list comprehensions, I think I like list comprehensions the most.
  • The author strongly recommends using map, filter and list comprehensions for creating a better code
  • The book shows a nice way to import modules dynamically

Chapter 17 - Dynamic Functions

This is my favorite chapter of the book. I was amazed at how the author takes a simple example of pluralizing a noun, introduces the concept of lambda functions, generators to make the code look extremely beautiful. From a raw if then statement code, the author takes the reader in a systematic manner in 6 iterations to a code that simply is beautiful. I am really thrilled to see so much of infra built in to this language. I don’t think I will ever move out of Python and R to do anything. The one thing that I have to practice and implement in my own code soon is generators. This chapter has had so many ‘aha’ moments that I will revisit this chapter at a later date. The last chapter offers a list of performance hacks that probably an experienced programmer might appreciate. Overall a fantastic book. Loved every moment of it