Seeking Simplicity

What is simple? Rich Hickey makes a good abstract definition, but it can be difficult to translate to everyday code. I encourage you to watch that before returning to this. I’ll still be here. Ok, let’s start at that definition. Hickey’s simplicity is the disentangling of concerns. It’s easy to convolute from what seems like straight-forward statement. For example, a high-level example would be what domain-driven design proponents argue for. Separate solving your problem domain from the machinery that you use to solve it. Separate How from What or When. ...

May 3, 2015 · 10 min

Objective-C: Lazy Sequences

Lazy data structures are a powerful abstraction can increase the readability of your program while encouraging separation of concerns. What are they? Simply put, they are data structures that “realize” what they contain when they’re needed (or right before they’re needed). What can you do with lazy data structures? How about a page-scraper that paginates as needed: # pseudocode seed_url = "http://example.com/page/" # generate a lazy list of urls: # - http://example.com/page/1 # - http://example.com/page/2 # - etc. urls = lazy { for (i = 0; i < 100; i++) { yield seed_url + string(i) } } # a lazy list of html pages pages = map(urls, fetchURLPageContents) # a lazy list of list of links links_per_page = map(pages, extractLinksFromHTML) # flatten to just a lazy list of links links = join(links_per_page) # do stuff with links for link in links { record(link) } This creates a powerful abstract that separate tasks your program needs to get done behind an implicit interface. The ending for loop doesn’t need to know that those links came from multiple page fetches or the file system. If the loop short-circuited, then it minimizes the number of unnecessary fetches. ...

July 7, 2014 · 4 min