found drama

get oblique

review: Clojure Programming

by found_drama

Clojure ProgrammingIn Clojure Programming (Chas Emerick, Brian Carper, and Christophe Grand; O’Reilly, 2012), the preface asks Who is this book for? It’s for a lot of people: experienced JVM developers, curious Rubyists, dissatisfied Pythonistas… Developers of all stripes that are looking to get introduced to, and become proficient in, Clojure. I myself have been circling the Clojure drainpipe for a while now, very nearly getting completely sucked in on numerous occasions. I’ve followed no one’s advice though–I have not started small, and instead keep jumping into sophisticated middle parts and getting mired.[1] I think I would have benefitted from this book a year ago; I’m certainly benefitting from it now.

At 587 pages[2], Clojure Programming is hardly a tome, but it is comprehensive, appreciably thorough, and makes a concerted effort to be accessible to the Clojure and JVM neophyte. That being said, the book is also far from short, and makes no pretenses about easing you into the language: you’ll be programming a naïve REPL by the end of chapter one. But this head-first approach is one of the reasons to love this book.

Emerick et al. found an excellent format for organizing the book, logically sequencing the material, and peppering chapters and sections with the right kind of illustrative, koan-style sample problems, eschewing the alternative of walking you through some contrived and over-arching application built one concept (and thus one chapter) at a time. As such, the book is broken into five sections:

  1. Functional Programming and Concurrency (the foundation);
  2. Building Abstractions (the sophisticated stuff);
  3. Tools, Platform, and Projects (the eco-system);
  4. Practicums (Clojure in the real world); and
  5. Miscellanea (other important stuff).

What’s marvelous about this structure is that you can decide for yourself whether to read it cover-to-cover, or whether to cherry-pick just the chapters relevant to your immediate challenges. What’s helpful is that the book cross-references itself for many key concepts. In the thick of chapter one and you don’t know what this “classpath” nonsense is? Jump ahead to chapter eight![3] Deep into chapter nine and you’re lost about how Clojure protocols relate to Java’s interfaces? A footnote steers you back to chapter six! The care taken to create these kinds of cross-references is tremendously valuable because it allows you to opt-in to some advanced concepts early on, getting a preview of the powerful features ahead of you.

Though Clojure Programming is overflowing with thoughtful, detailed, and well-composed information, where it really shines is the “Practicums” section. When I first started skimming the chapters in this section, the first thought that occurred to me was: “Herein lies the true esoterica.” I read about Clojure’s numerics and mathematics, about its intriguing use of “rationals”, about unchecked operations. I read about how to idiomatically implement different design patterns in Clojure. The deeper I got into this section though, the more that I realized that this was not a bunch of “out there” riddles and puzzles whose only purpose was to show off the sparkling fringes–no, this section was to demonstrate Clojure’s solutions to “real world” problems, and the kind of advantages afforded you by its functional style.[4] That being said, I appreciated how Emerick et al. were vigilant in observing when different approaches or language features would serve you well, and when you would be wise to avoid them.

A few other items that I feel compelled to point out:

  • The chapter on Java and JVM interoperability is strong. Anyone looking to introduce Clojure into their (JVM-based) organization would be wise to memorize this information…
  • …and then also memorize the chapter that specifically addresses how to go about introducing Clojure to your organization.
  • As with the other Clojure texts I’ve read, their is a focus on discussing “idiomaticity”, and differentiating between “working” or “valid” Clojure code, and idiomatic Clojure code. Seeing this again makes me wish that more authors writing about other languages put this much emphasis on idiomatic style.
  • Also, I am filled with tremendous gratitude that Emerick et al., when they cite Wikipedia at all, cite particular articles as “a jumping off point” or as “a surprisingly good resource” for the subject matter. I have read several books recently that cite Wikipedia as an authoritative reference and… Well, I find that to be in bad form.

I find it easy to recommend Clojure Programming to anyone with an interest in the language. There is enough “introductory” material that smart programmers will be guided in the right directions as they get started, but there is also enough detailed coverage that the book will grow right along with you. The chapters on the Clojure eco-system will help to steer you toward the right tools and resources to organize, manage, and scale your projects–as well as how to integrate them laterally within the JVM. Lastly, the practicums give you concrete and balanced approaches to answering some of the questions that you go into the whole endeavor already asking. I will be referring to this book often as I continue my explorations into Clojure.

  1. Case study: the first significant chunk of time I spent with the language was with early drafts of The Joy of Clojure. JoC is definitely an “intermediate-to-advanced” book. []
  2. Not counting the preface and index, which brings that up to 630. []
  3. Which, I’d like to add, is currently my favorite semi-layman’s explanation of the JVM’s classpath. []
  4. I suppose this should have been obvious from the name of the section. (What can I say? I got caught up in the details of rational numbers.) []

Linkdump for May 15th

by found_drama

Linkdump for May 13th

by found_drama

Linkdump for May 10th

by found_drama
  • By Chris Shiflett (via my Prismatic feed). I'm working on a similar list myself, and was glad to see something else like this out there. Shiflett's is an interesting list with some great choices. Three things that came to mind while browsing it:
    1. [1] “That’s a lot of PHP…”
    2. [2] I’ll ding any list like this that doesn’t contain a Zakas book, especially Professional JavaScript for Web Developers. (Though the early reviews of Maintainable JavaScript make it sound like a worthy successor to “The Good Parts”…)
    3. [3] I think there’s more to be learned by becoming a contributor to JSHint than simply using JSLint.

    Otherwise? Looks like a great list.

  • By Danny Croft. I've heard of, and had some limited success (experimenting) with PhantomJS, but hadn't heard of CasperJS. Sounds like it may be worth a look.
  • Interview with Ernest Hemingway in The Paris Review ("The Art of Fiction No. 21"):
    When I am working on a book or a story I write every morning as soon after first light as possible. There is no one to disturb you and it is cool or cold and you come to your work and warm as you write. You read what you have written and, as you always stop when you know what is going to happen next, you go on from there. You write until you come to a place where you still have your juice and know what will happen next and you stop and try to live through until the next day when you hit it again. You have started at six in the morning, say, and may go on until noon or be through before that. When you stop you are as empty, and at the same time never empty but filling, as when you have made love to someone you love. Nothing can hurt you, nothing can happen, nothing means anything until the next day when you do it again. It is the wait until the next day that is hard to get through.

  • "the ultimate archive of cross-browser css bugs, oddities and workarounds" • Seems like the sort of thing that ought to be tracked in a Github repo if you ask me…

getting Prismatic

by found_drama

Last week, Prismatic opened their virtual doors for 24 hours, letting anyone with a Twitter account sign-up. Having heard about it from friends a few times, and having seen it pop up in in my Twitter stream way more than a few times, I decided to try it out. The premise intrigued me: a service that builds a relevant and personalized news feed for you, just by watching what you’re interested in, and what your ambient relationships are also interested in.

After the first couple days, I’m feeling positive about it. The signal-to-noise ratio of the headlines in the home feed is good; anecdotally, I’ve found myself clicking through on about 50% of the articles so far. Not too many false positives. There are plenty gems in there: amusing stuff, inspiring stuff, interesting stuff, useful stuff… And the layout was a snap to figure out.[1]

What I’m still trying to figure out though is… well: How do I interact with Prismatic? How do I make it better for myself? And just how is it going to feed back into my daily activity? Continue reading →

  1. Also: the up/down-arrow keyboard short-cut is money. []

Linkdump for May 9th

by found_drama

dream.20120508: hallway

by found_drama

You’re walking down a hallway. It’s your hallway. The one in your basement, only the mudroom bit at the far end has been eliminated or flattened out. It’s just a long straight hallway. And you’re walking down from one end to the other, urgently. Only the hallway never gets any shorter. You never actually advance. The door at the end just taunts you. You can’t see through the window in the door. It’s just completely black on the other side of the glass. A cloudy void. Like squid ink suspended in space. You start to run. The door opens a crack, then it bursts open. But only for a moment. The hallway fills with balloon animals. A hundred balloon animals in every gumdrop color floats down the hallway toward you. Orange dogs. Blue cats. Green birds. A single purple mouse the size of your fist. Octopi, donkeys, fish, bears, lions, squirrels. Violet, red, yellow, indigo… Your perspective changes suddenly and radically. The hallway ascends now, the door at the top. You’re still running, but now it’s up and not toward. Your feet don’t touch the floor. You’re still not advancing. The animals float down toward you. They get closer. You grab one of them–an yellow dog with purple ears–right around the middle. You feel its heart beating, and when you look down, you can see the latex bulge and pulse right between your fingers.

responsive Orin

by found_drama

I pushed version 0.7 of Orin (this blog’s theme) on April 11th, and considering what happened between then and now… Well, I meant to make an announcement and I guess it just needed to wait about a month.

At any rate: version 0.7 of Orin refactors the blog as a “mobile first” responsive design. It was a fun little experiment. I suppose Orin is not strictly “mobile first”, because if it was, then it would have been designed with mobile devices in mind from the very beginning. However, my refactor of the design attempted to account for my mobile audience by putting the mobile-targeted styles as the default/baseline styles. If you go through the commit, history[1] you can follow the changes and see the challenges in this kind of refactor. Some reflections:

many examples are actually “mobile second”

A lot of the tutorials, resources, blog posts, and other places with sample “responsive” code seem to claim to be “mobile first” but then their media queries look like this:

@media all and (max-width: 1023px)

In other words: apply special rules for the mobile devices. On the one hand, this makes sense: in the research I did, the mobile devices are far more likely to support the CSS3 media queries. On the other hand, you’re also forcing the (less powerful) mobile devices to run all the code, and process all the CSS from all the rules.[2][3] As I took my cues from a lot of these resources as I worked my way through the learning, I found myself writing the code this way first.

margins (also padding)

When something “mysterious” was throwing me off in the layout, it was almost always something to do with the margins. (Or the padding.) It isn’t so much that these are calculated differently (they’re not) — but places where I’d always used margins to achieve certain results seemed to fall apart for me. Especially with orientation changes.

device-width and maximum-scale

Get familiar with these. When you’re just cutting your teeth on mobile, it’s easy to forget how different the pixel density on the mobile device is from your non-mobile desktop. Experiment. Play with these settings to get a feel for how they affect the layout.[4]

Sass/Compass organization

This is an area where I smell future experiments. During the early phases of developing version 0.7, I found that I would usually put the media query rules inline with the baseline style (for example) — i.e., immediately after it. While this was convenient, it also meant that Sass/Compass was compiling an @media rule every time it encounters one, instead of rolling them up. At first I was annoyed by this, but the more I thought about it, the more I realized that this was the correct behavior of the Sass compiler. If it attempted to roll them up based on @media rule matches… well: that’s the kind of “magic” I’ve found myself advocating against these past few months. So I withdrew my (unspoken) complaint against the Sass compiler and decided to re-organize the code. In a lot of ways, this actually turned into a clever solution.

conditional comments as an @media rule hack

In my quest to minimize the number of @media rules in the output, I stumbled across the strategy of moving the @media rules out of the CSS and into the mark-up. This offered a couple of advantages. First, I’m serving less CSS to the mobile devices. The WordPress style.css is the mobile stylesheet; the desktop styles get triggered by the @media rule in the second/supplementary stylesheet — thus only actually downloading those styles when we are confident that we need them and are on a screen resolution that can support them.

But whither Internet Explorer 8? Poor IE8, which needed no special CSS love in previous versions of Orin is suddenly “stuck” with the “mobile version’s” styles. If only there was a way to apply the desktop styles that we’re otherwise delivering via a media query…? Oh right: conditional comments! It’s not a “pure” solution; it’s not feature detection. I’d even go so far as to call it “cheating”. But it was cheating that got me what I wanted, and with only a minimum of fuss.[5]

Try it out!

As I mentioned at the beginning of this post, I pushed the changes and deployed the updated theme on April 11th. There is a good chance you have seen this in action already.[6] If not… The site now looks decent on a variety of mobile devices. And I am happy to admit that it didn’t actually take all that long.

  1. Relevant SHAs: d308f13fc0, 9eaeb307f7, 9b455240a4, and a9a587353c []
  2. As an aside: I’ll admit that I need to do more research in this area. I may be over-estimating the amount of processing the device does. Perhaps it only applies a given block of CSS after processing the whole stylesheet and determining which ones actually apply. And/but what if those overrides are furnished from another stylesheet all together? What if… what if…? I am making some assumptions, but most of them seem like reasonable assumptions. []
  3. Also: I’ve seen the “rules” called “breakpoints” in a lot of places. And I cannot figure out why this is. We’re not debugging, they’re not breakpoints. []
  4. And as an aside to all this: a third-generation iPad did not seem to report its device-width in the way I expected. Anyone else notice this? []
  5. After all, the stylesheet delivered from the conditional comments is the same one that would have been delivered if IE8 supported the media query. []
  6. I know of at least one person that contacted me about it to compliment me on the improvement. []

Linkdump for May 6th

by found_drama

dream.20120506: partials

by found_drama

Starring Robin Williams as a grizzled and down-on-his-luck police detective. Starring across an inhumanly tall prostitute. In a world where Work has purchased two oil tankers and constructed an artificial island between them for exclusive parties. But the islands keep sinking.