Since Sudoku had been such a major part of the end of last week, we started the day with a discussion around approaches to difficult programming problems. The advice was pretty generic (e.g. test frequently, keep small methods), but we did start to delve into the single responsibility principle.
The morning challenges were pretty straightforward:
- Argument order dependency: refactor a class to use named arguments and hash.fetch with defaults
- Ruby drill – self: reviewing self in the context of classes and instances
- Re-implementing enumerable methods
The rocket (bonus) challenge for the morning was to watch and discuss a number of videos, including one on Simplicity vs Ease, and another on various ruby tricks. For the latter video, I was familiar with some of the tricks and doubt I’d use many others, but a few seemed quite helpful:
- Generate a random number from a range: rand(x..y)
- Easily determine if a string contains a substring: str[“hello”]
- Check the bitflags on a FixNum: x=2; x==0; x==1
- Print the method name/calle: p __method__; p __callee__
The afternoon lecture and breakout was on OOP foundations and primarily discussed inheritance vs composition. The afternoon challenges went a little deeper into OO principles and using what we had learned in the day’s lectures:
- OO TDD: given a selection of tests, produce the classes, methods and code to make the tests pass
- Classical inheritance: creating hierarchy of animal classes and subclasses with overlapping behaviors
- Orange Tree #2: an extension to a challenge from last week, making our Orange Tree and Orange classes easily usable with other types of fruit trees and fruits.
- CSV parser: loading in a CSV of data, creating and manipulating objects from it, and resaving. Then extending it to use YAML and JSON