marick / fp-oo

Code samples and exercise solutions for /Functional Programming for the Object-Oriented Programmer/
143 stars 49 forks source link

Exercise 4.1 Confusion #16

Closed chrispsn closed 12 years ago

chrispsn commented 12 years ago

I'm not sure what the exercise in 4.1 is asking me to do:

"Change the Point constructor to add x and y accessors."

What is an accessor? Is it like a 'get' method? Why would I need it if I can just use :x on a Point directly?

marick commented 12 years ago

On Sep 13, 2012, at 9:04 AM, chrispsn wrote:

I'm not sure what the exercise in 4.1 is asking me to do:

"Change the Point constructor to add x and y accessors."

What is an accessor? Is it like a 'get' method? Why would I need it if I can just use :x on a Point directly?

Yes, an accessor is another name for getter. I'll change the text to be more clear.

Some people feel fairly strongly that all access to instance variables should go through methods rather than direct field access. (I myself change my mind about this regularly.) There are some languages, like Ruby and Smalltalk, where (more or less) you can only get to instance variables through accessors.


Brian Marick, Artisanal Labrador Contract programming in Ruby and Clojure Occasional consulting on Agile Writing /Functional Programming for the Object-Oriented Programmer/: https://leanpub.com/fp-oo

marick commented 12 years ago

What's your name, by the way: I like to credit people who file bug reports.

chrispsn commented 12 years ago

My name's Chris Pearson. Thanks for clearing that up Brian. I'm enjoying the book!

On Friday, 14 September 2012, Brian Marick wrote:

What's your name, by the way: I like to credit people who file bug reports.

— Reply to this email directly or view it on GitHubhttps://github.com/marick/fp-oo/issues/16#issuecomment-8534673.