The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

pgb_ct (3) [Avatar] Offline
In general, I like this chapter. But you might consider the following thoughts and ideas. Some of them may seem like I am splitting hairs, but I offer these thoughts to help you.

1. Chapter 4 is titled “Polymorphism with Multimethods”
Clojure protocols are another form of polymorphism so I see why you use the qualification “with.”

The word “with” is a very restricting clause. So, I think “Multimethod Polymorphism” or “Polymorphism though Multimethods” might be better than “Polymorphism with Multimethods”

I'm splitting hairs here, but I think “Polymorphism though Multimethods” feels better.

2. P 103-106: I feel like these Java examples distract from your nice Clojure books. I love aspects of Java, but I think you are losing focus here. Will all of your readers be fluent in Java? Or comfortable enough in Java so these pages make sense?

3. P 109: At first, I was confused by the “& options” in the defmulti.

4. P 109, just before subsection 4.3.2: Is the key advantage of polymorphism to avoid the “pain” adding new rules about affiliates and percentage? Yes, the cond form will get messy.

Perhaps even better you are using the type system to decouple different type-based functionality.

5. P 109-110: Can you put a diagram in for where each argument goes?
For me to understand what is going on, I had to pull up a Clojure interpreter and enter these defn, defmulti, defmethods and defs.

I have a good deal of experience, so I hoped I could read this section and the next time I was near a Clojure interpreter, then I could just recall enough from this example to type a similar one to enjoy. I had to look back and draw a diagram.

Here is my attempt at tweaked version:

;; In different contexts, we want to apply this function to different methods.
;; This function has not been modified in any way to be applied polymorphically.
(defn fee-amt [percentage user]
(float (* 0.1 percentage (:salary user)))

;; The next macro indicates an method a-f will be dispatched based on the value of :referrer
(defmulti a-f :referrer)

;; These are methods for dispatching the fee-amt function.
;; These methods are selected by the :referrer which is one of, and :default
(defmethod a-f [user] (fee-amt 0.03 user))

(defmethod a-f [user] (fee-amt 0.01 user))

(defmethod a-f :default [user] (fee-amt 0.05 user))

;; These defs have :referrers to use the type system to differentiate the
;; functions. Along with these different references are the appropriate :salaries.
(def user-1 {:login "Rob" :referrer :salary 100000})

(def user-2 {:login "Kyle" :referrer :salary 90000})

(def user-3 {:login "Celeste" :referrer :salary 190000})

;; The selection keys are given here immediately after the :referrer key word.
;; The :salary values are also given in the def statements above.
(a-f user-1)
(a-f user-2)
(a-f user-3)

6. P 114, -9: “This is much simpler than creating the whole double-dispatch mechanism in a language like Java or C++ that does not support it.” This is correct, but the sentence is awkward to read.

7. P 114, -3: the word “looks” is split across lines. But, more significantly you are hedging your words too much: “Sometimes, a hierarchy may involve...” How about either
a. “A hierarchy may involve...”
b. “Sometimes, a hierarchy involves”
amitrathore (132) [Avatar] Offline
Re: Chapter 4: Polymorphism
- Agreed, changing the name to Multimethod polymorphism.

- The Java examples demonstrate the problem with a popular OO language where polymorphism is very limited.

- I've added a sentence to explain the options thingy.

- didn't understand what you mean by a diagram... could you expand?

- modified the sentence about missing double-dispatch in Java to make it read more clearly

- fixed the text about a hierarchy that sometimes involves... smilie

Thanks for all the feedback, appreciated!