Native Language alike
to configureTheDisplay(theProfilesName, brightnessValue)
tell application "System Events"
*if not* UI elements enabled then
DisplayAssistanceInstructions() *of me*
openDisplaysPrefPane() *of me*
tell process "System Preferences"
click radio button "Display" of tab group 1 of window 1
quitPrefs() *of me*
But even in projects using Ruby...
def page201(from_page, visited_queen = false, threw_button = false)
if from_page == 59
enemy = if visit_queen
enemy.angry if enemy
# ... 30 lines of code
Books of "Choose your own adventure"
• If you ﬁght the troll with bare hands, turn to page 137.
• If you try to reason with the troll, turn to page 29.
• If you don your invisibility clock, turn to page 6.
What if you read this kind of book from the ﬁrst
page to the end?
You exit the passageway into a large cavern. Unless you came from
page 59, in which case you fall down the sinkhole into a large cavern.
A huge troll, or possibly a badger ( if you already visited Queen
Pelican), blocks your path. Unless your threw a button down the
wishing well on page 8, in which case there nothing blocking your
way. The [troll or badger or nothing at all] does not look happy to see
Sending strong message
The foundation of an object oriented system is the message.
— Sandi Metz, Practical Object-Oriented Design in Ruby
Tell a better story
1. Identify the message to be send
2. Find the roles which correspond to those messages
3. Ensure the methods's logic receives objects which can play those
Identify the message to be send
*Tell, don't ask
A story of parse many legacy CSV ﬁles of purchase
1. Parse the purchase records from the CSV contained in a provided
2. For each purchase record, use the record's email address to get
the associated customer record, or, if the email hasn't been seen
before, create a new customer record in our system.
3. Use the legacy record's product ID to ﬁnd or create a product
record in our system.
4. Add the product to the customer record's list of purchases.
2. For #each purchase record, use the record's #email_address to
3. Use the record's #product_id to #get_product.
4. #add_purchasedproduct to the customer record.
5. #notify_ofﬁles_available for the purchased product.
6. #log_successfulimport of the product record.
Find the roles which correspond to
*Single responsibility principle
Ensure the methods's logic receives
objects which can play those roles.
*Law of Demeter
2. For purchase_list.each as purchase_record, use
purchaserecord.emailaddress to customerlist.getcustomer.
3. Use the purchaserecord.productid to productinventory.getproduct.
5. customer.notifyofﬁles_available for the product.
6. self.logsuccessfulimport of the purchase_record.
purchase_list = legacy_data_parser.parse_purchase_records(data)
purchase_list.each do |purchase_record|
customer = customer_list.get_customer(purchase_record.email_address)
product = product_inventory.get_product(purchase_record.product_id)
Now it starting to look a lot like code.
Don't Know Where to Start?
Let's talk about method
Four parts of every method
1. collecting inputs
2. performing works
3. delivering output
4. handling failures
• diagnostics and cleanup
Some More Tips
1. Workround: Glue of the existing tools to perform works.
2. Refactor: Focus on Inrtent of a method rather than method's
3. One level of abstraction each layer.
4. Pair Programming helps.
5. Some times TDD is a good indicator.