exercise programming style

Introducing Exercises in Programming Style

This is the 1st post in the Exercises in Programming Style focus series. Recently, my colleague Bertrand lent me a copy of the book Exercises in Programming Style by Cristina Videira Lopes. Among all the books that sit on my reading pile, I decided to put it on top, and started reading right away. The concept behind the book is pretty simple, but very interesting: there is a problem to solve with code - search for the 25 most common words in a text file. But here's a twist. There's a dedicated se

exercise programming style

Exercises in Programming Style, stacking things up

This is the 2nd post in the Exercises in Programming Style focus series. Last week, we had our first taste of Exercises in Programming Style. Remember, the goal is to write a simple program, but to comply with some constraints. The previous constraint was that there was only a single variable available, an array. With a statically-typed language such as Kotlin, it required a lot of casting variables to their correct types before using them. This week, the constraint is as radical, but different.

exercise programming style

Exercises in Programming Style, Kwisatz Haderach-style

This is the 3rd post in the Exercises in Programming Style focus series. In previous posts, we had a simple problem to handle - find and sort the 25 most frequent words from a file. Then, we had to comply with different sets of constraints regarding the code: first, no variable but a single untyped array; then, only a stack and a heap. This week, the constraint is to achieve the goal with the shortest code possible. For that, the usage of Kotlin's stdlib is more than welcome.

exercise programming style

Exercises in Programming Style, recursion

This is the 4th post in the Exercises in Programming Style focus series. This week's post will be back to fundamentals, as the constraint is to use recursion. Recursion in computer science is a method of solving a problem where the solution depends on solutions to smaller instances of the same problem (as opposed to iteration). The approach can be applied to many types of problems, and recursion is one of the central ideas of computer science.

exercise programming style

Exercises in Programming Style with higher-order functions

This is the 5th post in the Exercises in Programming Style focus series. This week, the chapter is named 'Kick forward'. The style's constraint is not to call a function directly, but to pass it to the next function as a parameter, to be called later. I'm not sure whether the concept of higher-order functions has its roots in Functional Programming. However, the concept itself is easy to grasp. A higher-order function can be used as a function parameter - or as a return value - of another functio

exercise programming style

Composing Exercises in Programming Style

This is the 6th post in the Exercises in Programming Style focus series. Last week saw us using higher-order functions by passing them as the parameter to another function, and dynamically calling them. The parameter passing is quite nice, but it's not easy to follow the flow of the program. This week we are going to keep those functions, but make use of them in a different way, with function composition.