Programming 101–7. abstractions II
Disclaimer: the Programming 101 series was originally written to be published as a short book. However, since I never got round to finishing it, I’m publishing the chapters here as individual blog posts…
Objects
Functions are extremely important to programming and even represent a specific programming style. Functional programming, which we will discuss later on in more detail, is programming that organizes everything as a series of functions that take a certain input and produce a different output. The output of one function is then used as input for the next. For instance, a spelling checker could be organized as the following series of functions:
- A: read a text file (input: file path, output: string)
- B: split the text file in lines (input: string, output: list of strings)
- C: split the line into words (input: string, output: list of strings)
- D: normalize words, e.g. ‘HELLO’, ‘hello’, ‘hello!’ -> ‘hello” (input: string, output: string)
- E: check if word is present in dictionary (input: string, output: Boolean)
However, functional programming is not always the most efficient way to organize things. Sometimes we would like to get a more object-centered approach, where data and the manipulation…