Archive | Skimmer’s Guide RSS feed for this section

Skimmers Guide for Week 15 of Functional Programming for the Object-Oriented Programmer

21 Jul

“…today’s commonplaces of object-oriented programming were mysterious and brain-bending twenty or thirty years ago… Monads and other higher-higher-higher-order abstractions may follow the same trajectory. I hope they do.

What did we read about?

This was our fifteenth week of ‘Functional Programming for the Object-Oriented Programmer‘ by Brian Manick.

We start from Page 141 at section 10.10 Lifting Functions with Monads, finishing at Page 146 at the end of chapter 10!

Only 6 pages to read this week but they are absolutely rammed packed with information and examples.

What stood out?

  • Page 142 – The m-lift monad is introduced which is a concise way to do short-circuiting.
  • Page 144 – The sequence-m monad is introduced as a way of transparently doing looping.

If you read nothing else this week…

  • Page 146 – 10.13 Choose your own adventure – A succinct summary of monads, which bestow upon programmers both great power and great responsibility 😉
Advertisements

Skimmers Guide for Week 14 of Functional Programming for the Object-Oriented Programme

21 Jul

“…functional programming terminology is perhaps slightly less than optimal for novice understanding. That is the case with monad terminology.”

What did we read about?

This was our fourteenth week of ‘Functional Programming for the Object-Oriented Programmer‘ by Brian Manick.

We start from Page 132 at the start of section 10.6 Monads as Data-Driven Extended Continuation-Passing Style. Finish at Page 141 at the end of section 10.9 Exercises

We continue looking at monads and delve into them further. We work on a simplified version of the truth and gradually form a concrete appreciation of the complexity and power of monads!

What stood out?

  • Page 139 – 10.8 Cond is all about “a multi-way” if, appearing much like a switch statement.
  • The exercise at the end of our reading is amusing and gives us our first chance in writing our own monad!

If you read nothing else this week…

  • Page 133 – “The lie” gives you a working understanding of monads, which is absolutely critical.

Skimmers Guide for Week 13 of Functional Programming for the Object-Oriented Programme

8 Jul

“A monad is a collection of functions that can be used to modify stepwise calculations.”

What did we read about?

This was our thirteenth week of ‘Functional Programming for the Object-Oriented Programmer‘ by Brian Manick.

We start from Page 121 “10 Branching and Looping in Dataflow Style” and read all the way through to Page 131 stopping at “10.5 Extending continuation-passing style”.

Going over the “->” and “let” functions again, we compare the linear/non-linear calculation of them both. We look at removing explicit branching through “monads”, which allow us to insert code after the computation steps in the normal flow of our code.

Finally we are introduced to the “continuation-passing style”, revolving around the idea of “flowing the result” of each step of our computation into the next. There are some Exercises to get you to grips with it and then we elaborate on how the style gets evaluated.

What stood out?

  • “10.1 That pesky nil again” (Page 124) – A well worked example of doing nil checking automagically via the “with-monad” and “domonad”.
  • “10.2 Continuation-passing style” (Page 126) – An interesting use of the “->” function which actually makes computation steps clearer.

If you read nothing else this week…

  • Practice the continuation-passing style in Exercises 1 – 3 (Page 127).
  • “10.4 Expansions in Evaluation” (Page 128) gets under the covers of continuation-passing style and how it gets evaluated. We compare this to how the “domonad” gets evaluated and how understanding both is critical to understanding how monads in general work.

Skimmers Guide for Week 12 of Functional Programming for the Object-Oriented Programme

29 Jun

“With loosely-coupled objects that communicate only by passing behaviors (functions) around (rather than entire bundles of state and behavior in the form of objects), the early part of design may become easier.

What did we read about?

This was our twelfth week of ‘Functional Programming for the Object-Oriented Programmer‘ by Brian Manick.

We begin on Page 115 at the start of section 9.4, picking up the exercises from last week’s reading. We finish at Page 120 at the end of chapter 9.

The exercises revolve around putting into practice what we have learnt about “Point-Free Programming”. We are introduced to the new juxt function before being tasked with a diverse set of exercises to test understanding on various topics so far.

Finally we look at higher order functions from the perspective of object orientated programming and how we can decouple our design using “function passing” (either directly in Ruby or via single abstract method interfaces in Java).

What stood out?

  • Exercise 2 introduces the neat little function juxt, definitely a good tool to know about and not a bad exercise either.

If you read nothing else this week…

  • Exercise 7 – 10 are brilliant practice of the Clojure we have learnt so far. Highly recommend everyone gives it a try as they are great for working on your code style and thinking about reducing duplication.
  • “9.5 Higher-order functions from the object-oriented perspective” – only two pages but makes you think about how you should handle your dependencies (on functions or on objects).

Skimmers Guide for Week 11 of Functional Programming for the Object-Oriented Programme

20 Jun

Skimmers Guide for Week 11 of Functional Programming for the Object-Oriented Programme

8JUN

“A function that can close over external values is called a closure. I mention that because now you know why Clojure is called ‘Clojure’.  It’s a portmanteau word combining ‘closure’ and ‘Java’.

Higher Order FunctionsWhat did we read about?

This was our eleventh week of ‘Functional Programming for the Object-Oriented Programmer‘ by Brian Manick.

We began on Page 108, at the start of chapter 9 “Functions That Make Functions”. We read through to Page 114, leaving the exercises for next week.

We learn all about closures, and the important role they play in functional programming.  First of all we looked at how repetition can be avoided by creating a partial function, and the Clojure partial function.

We then read about lifting functions to a higher order.  Higher order functions are functions that act on other functions rather than plain values.

Then we looked at point free, or parameter-free, functions and took the Clojure comp function as an example.

To finish there was  a mild rant about style, looking at the different stylistic choices that are available.

What stood out?

  • This week we started to look at what really makes Functional programming different.  You may be familiar with the idea of a factory method creating objects, but functional programming takes it to a whole other level.  Personally I found it necessary to keep rereading paragraphs while I tried to understand what the author was trying to tell me.  Hopefully next weeks exercises will help to complete my understanding.
  • We also caught glimpses of the concepts that underpin functional programming.  The author makes light of the strange expressions in little asides like “No doubt the term ‘closing’ seemed perfectly apt to someone somewhere” and “no doubt the analogy of formal parameters to geometrical points seemed perfectly apt to someone somewhere.”  Personally I’d like to know more about the thinking behind these names.
  • The mild rant on style is revealing.  In Java we are used to having conventions that are followed by everybody so that there is a consistant style.  In Clojure there are so many ways of doing something it is no wonder that functional code can be so incomprehensible.

If you read nothing else this week…

  • If you already understand higher order functions then you can skip this week.  You may find the mild rant on style interesting.
  • If you are new to functional programming then you have to read all of it.  There are a lot of big concepts being introduced.

Skimmers Guide for Week 10 of Functional Programming for the Object-Oriented Programmer

10 Jun

“…I think you could say “There is a thing that we’re justified in saying is an object-oriented architectural style.” We’re not at that point for the functional style yet, so far as I can tell.

What did we read about?

Our tenth week of ‘Functional Programming for the Object-Oriented Programmer‘ by Brian Manick.

We pick up on a new chapter on Page 99, “8 Embedding Functional Code in an OO Codebase”. No exercises this week and we blitz through until the end of the chapter on Page 107.

To be honest, a lot of this chapter is irrelevant or uninteresting, revolving around boilerplate code or SQL. Skimming/skipping through is recommended!

What stood out?

  • Concept of “functional nuggets” in OO code, Page 100. An interesting theory, sadly demonstrated in a rather tedious fashion.

If you read nothing else this week…

  • The big picture, Page 108.  Talking about the evolution of functional programming and looking forward to “Functional Patterns for Enterprise Application Architecture.”

Skimmers Guide for Week 9 of Functional Programming for the Object-Oriented Programmer

8 Jun

“…don’t read Lisp functions from top to bottom… look for the most important code (typically closer to the bottom of the function, often the most visually dense) and read it first.

What did we read about?

This was our ninth week of ‘Functional Programming for the Object-Oriented Programmer‘ by Brian Manick.

We began on Page 90, at the start of section “7.6 Processing Sequences of Maps”. We did the two exercises, starting on Page 94, and then continued reading through to Page 98 at the end of chapter 7.

Continuing with the student courses example, we work through how to manipulate the course data. New and powerful features of Clojure are introduced, such as destructing and external binding.

Rather interesting we finally touch upon design at a high level within functional programming. Brian discusses his thoughts on how to handle encapsulation within a dynamic language as well.

What stood out?

  • Destructuring arguments, Page 92, is an incredibly useful tool that reminds me a lot of pattern matching. Brian covers it very well succinctly, although there promises to be an entire chapter on it later!
  • Avoiding argument passing by using external binding is a very interesting topic (starting on the bottom of  Page 94). Again it will be covered in a later chapter but is raises the interesting design question on where and when to “nest functions”?

If you read nothing else this week…

  • Information Hiding, Page 98, brief but thought provoking section on encapsulation. Do you think using private helper functions and file based modularity is enough?
  • Discussion of the pros and cons of nesting functions, bottom of Page 96. In functional programming, does deciding on the number of higher level functions to use and their responsibilities reflect the design of classes in imperative programming?

Skimmers Guide for Week 8 of Functional Programming for the Object-Oriented Programmer

27 May

“Only a fool tries to define something as nebulous as a style of programming. So here goes!”

“My solution will seem so inefficient as to border on professional malpractice.”

What did we read about?

This was our eighth week of ‘Functional Programming for the Object-Oriented Programmer‘ by Brian Manick.

We began on Page 78 at the start of Part II and read through to page 90.  There were three exercises.

In Part II we are going to learn about writing in a functional style in Clojure. 

It started by looking at what a functional style is, and how it is different from an object-oriented style.  It is summed up as follows:

  • Object oriented: stable relationships and varying paths.
  • Functional: Many specialised flows and shapes.

Unfortunately, it isn’t clearly explained what that actually means.

Hopefully working through the example problem, which involves matching students to courses, will make things clearer.  The solution involves annotating maps and then filtering them based on those annotations.  To help us create the solution sets, map annotations and the arrow operator were introduced.

What stood out?

  • We talked about avoiding conditionals back in week 2.  Section 7.2 shows how we are actually going to do this.  The approach sounds appealing.
  • On the group we felt the need to talk about sets several weeks ago.  Now the author has finally decided to introduce them in section 7.3.
  • The approach described in section 7.4 is rather clumsy.  Hopefully we’ll be shown a better way next week.

If you read nothing else this week…

  • Sets are introduced in section 7.3
  • The arrow operator is introduced in section 7.5

Skimmer’s Guide for Week 7 of Functional Programming for the Object Oriented Programmer

20 May

“Pat yourself on the back! You have both used and implemented the built-in function reduce, perhaps the most dreaded of all sequence functions.”

What did we read about?

It’s our seventh week of ‘Functional Programming for the Object-Oriented Programmer‘ by Brian Manick.

We come to the end of the “Embedding and Object Oriented Language” with some exercises and a bit of wrap up.

  • Begin on Page 73 at section 6.4 Exercises

    • Exercise 1 (Page 73)
    • Exercise 2 (Page 74)
    • Exercise 3
    • Exercise 4 (Page 75)
    • Exercise 5
    • Exercise 6
  • Finish at Page 77 at the end of chapter 6

Screenshot_14_05_2013_12_56

What stood out?

  • Anybody playing the functional tutorial drinking game can take two drinks: one for recursion and the other for factorial 😉
  • The answer for each exercise feeds into the next, building up the complexity to use increasingly sophisticated forms of recursion.
  • The exercises conclude by introducing the powerful reduce function.

If you read nothing else this week…

  • Whatever you do make sure you complete exercises 1 to 6.
  • Exercise 5 is partially tricky, kudos if you complete it without hints! (note the result doesn’t have to be in-order)

Skimmer’s Guide for Week 6 of Functional Programming for the Object Oriented Programmer

13 May

“I picked the rather odd name method-cache to give me an excuse to point out that this implementation isn’t completely silly.”

What did we read about?

This is our sixth week reading Functional Programming for the Object Orientated Programmer.

  • Begin on page 56 at the start of the chapter, read until page 73,  leaving exercises for next week.

This week we finally start learning about Recursion and how it can be used to implement Inheritance in our object system. We touch on using assert for pre-conditions and define a superclass “Anything”. In a rather round-about fashion, we look at how we can do method overriding.

Although rather slow and slightly patronising at times, the book covers different patterns for recursion and visits the problem of tail recursion.

What stood out?

  • The use of a method-cache to do method overriding is very silly but somewhat interesting.

If you read nothing else this week…

  • Try to get to grips with all the types of Recursion, this will stand you in good stead to do the exercises next week.