Perks of Life in the Kingdom of Nouns

Execution in the Kingdom of Nouns is one of Steve Yegge’s most entertaining posts about the verbosity and noun-centricity of Java (and other strongly typed languages without first-class functions). His post paints a picture of life outside JavaLand, where things are simpler and more straightforward:

There’s rarely any need in these kingdoms to create wrapper nouns to swaddle the verbs. They don’t have GarbageDisposalStrategy nouns, nor GarbageDisposalDestinationLocator nouns for finding your way to the garage, nor PostGarbageActionCallback nouns for putting you back on your couch. They just write the verbs to operate on the nouns lying around, and then have a master verb, take_out_garbage(), that springs the subtasks to action in just the right order.

With simplicity, there’s always a tradeoff. How does one test that take_out_garbage() actually works? You’ll need a full environment with real nouns lying around and all you can do is check the environment after completion. In the Kingdom of Nouns, you can pass in mock nouns and carefully watch what the function does with them. Maybe it’s important that the recycling gets separated, but if you only check the end environment, you won’t be able to tell it wasn’t.

What if trash day is moved to a different day? You might need a new take_out_garbage_wednesday(). As ridiculous as it seems, passing in a GarbageDestination makes the chore more flexible and testable. During testing I can pass in a destination of “right here”, saving me the hassle of creating an environment that includes the walkway out to the curb.

Whether you’re executing global/static functions or class methods, being able to pass dependencies in (where to find the trash, where it goes, when is it supposed to be there) not only makes your function more flexible, but more testable to boot.

This is not to suggest that Steve’s post was anti-dependency injection. I get the impression it was more a frustration of the expressive limitations of Java (when he wrote it—I think it has lambdas now). You can do dependency injection just fine without concrete classes, of course, but you wouldn’t want someone to pass in an array of GPS coordinates when you really need an object that you could call getStreetAddress() on. Type hinting an AddressProvider in the argument would let end users know exactly what to pass in and let the compiler/runtime know not to even bother executing the function, because we don’t have what we need. Also type hinted arguments allow good IDEs to prevent you from making mistakes, or to autocomplete existing variables in scope matching that type.

A Zend Framework App in a Single File

Most PHP micro-frameworks I’ve reviewed have some major cons: incomplete namespacing of functions/classes/global vars; doing too much/little; being under-tested; and the worst: forcing a unique (and usually under-documented) code structure that will make it difficult to “graduate” an app into a more full-featured framework. It also seems silly to rely on “micro-optimized” code if performance isn’t your number one goal and you have well-tested libraries sitting around.

So over the weekend, as a proof of concept (and mostly to get better acquainted with ZF’s MVC implementation), I built some minimal classes allowing one to implement a “quick and dirty” Zend Framework MVC app in a single script, with the resulting abomination being relatively easy to convert to a full app. The README shows how such a script might look. Continue reading  

Minify update

Minify 2.1.4 is approaching release and will have several long-awaited features and hopefully easier configuration.

Looking towards version 2.2/3(?), I recently committed the beginnings of a complete refactoring of the Minify API. The goal is to have a more flexible and extensible design that can include plugins like LESS and maybe handle @imports on the server-side—I’m still mulling over how radically a plugin should be able to alter the overall processing of the request. A key to doing this is splitting plugins into at least two stages and allowing the first to influence the cache id, and possibly add more sources/processors. By asserting that the request’s cache id is stable after the first stage, you can serve requests from the cache most of the time without running the second stage (JSMin, calls to Closure Compiler API, etc.).

Another goal was to eliminate static/global state from all components and have each component independently testable, meaning refactoring out access to global state like request/$_SERVER vars, file access from controllers, etc. A bunch of new classes and interfaces (read: files) could mean a performance hit, but we will also add an internal URL cache so that most requests will not load the system at all. At most once every N seconds the full stack will be loaded in order to make sure the cache is up-to-date with file mtimes, etc., but most requests will hit a very minimal front controller that simply includes a pre-generated PHP script (sending the necessary headers and output) depending on query string and Accept-Encoding. In theory this should be absurdly fast (for PHP output anyway), but of course sticking a reverse proxy in front is always a better idea if you can.

There’s a lot of work to be done. I thought of the URL cache a little late so some of my earlier design decisions were based on performance, and they need to be revisited.

Plastic Sitars Intro for piano

I’ve been playing more music lately, but also trying to go back and learn the fundamentals of reading/writing music and keyboard playing—I can play chords and pop melodies semi reliably but suck at playing scales with either hand. Yesterday I created a free account at Noteflight, which lets you compose scores online (you have to enter notes via mouse/keyboard, but the UI is pretty quick once you get the hang of it). The import feature successfully digested a 15 year old MIDI file of something I wrote in college.

The (yet unrecorded) French Horns song “Plastic Sitars” always started with rhythm guitar live, but for a few months I’ve been toying with a short solo guitar piece as an intro, ideally stealing Johnny Smith’s tone. Below is a piano arrangement for my tour of airport cocktail lounges.

Elgg Core Proposal: New Table “entity_list_items”

[This proposal has been superseded with ElggCollection.]

As of Elgg 1.7.4 there’s no way to specify a specific list or ordering of entities for use in an elgg_get_entities query. E.g. one might want to implement:

  • A “featured items” list for a group or user widget. On a group page this could be implemented in “left” and “right” lists for better display control
  • “Sticky” entities in discussion lists, or any other object lists
  • A “favorites” list for each user

Continue reading  

About damn time, guys

Opera 11 will have extensions.

Mozilla 1.0 had the first decent extension system in 2002, and since then Opera users have been begging for one and getting lame excuses and half-baked substitutes that offered none of the power of real extensions:  “Panels” were just HTML docs beside the viewport, and “widgets” just HTML apps in separate chromeless windows.

If Opera doesn’t want to sit at 1% market share for 10 more years, they better get this right. An “extension” system should be able to alter chrome and context menus at the bare minimum.

Five years later a “new” French Horns recording

In 2005 I wrote a vocal melody and lyrics on top of a blissy keyboard instrumental by Slavagoh. I really liked the repeating three chord progression and had planned to incorporate his recording into the French Horns demo, but decided to keep it minimal.

I kinda had always regretted that, so five years later I managed to glue those recordings together:

[audio:http://mrclay.org/mp3s/Surest%20Things_untitled%20bliss.mp3|titles=Surest Things – The French Horns & Slavagoh]

screenshot of Audition mixing session Both recordings were almost the same tempo, but the Slavagoh recording was about a semitone lower in key. After nudging his recording into the same key and time-stretching (thankfully both were recorded to drum machines), there were still some beat mismatches on the ends to deal with. Eventually I ended up with three instances of “untitled bliss” spliced in because I really liked how its ending had this smoother sound and how that part mixed with earlier parts of the track.

My demo was also bass-heavy, too dark in the vocal range, and overly punchy on some beats, so I did a bunch of surgical volume cuts and EQ on my track before mixing.

Wins: Extended the end of the track a bit by having the “guitar solo” twice. Worked hard on the fades at the beginning and end so the track starts and finishes with just the Slavagoh track.

Losses: Not remixing my recording from scratch to remove that annoying click track. Not using some of the violin tracks laying around from an older mix session. Not saving the session used to master it.

If you’re not patient, it’s easy to mix down and then immediately start mastering the resulting WAV file without keeping track of the changes you’re making. When you do this, there’s no way to duplicate that process in case you need to change something in the mixing session. I kinda did this on purpose though; after 5 years of sitting around I wanted to get this recording to “good enough” and move on. There’s a lot more piled up that needs working on.

Maria Napoleon “Think of Rain”

Louis Philippe and Maria Napoleon put together a fine version of one of my favorite tunes. I usually don’t like covers that mess with the melody, but at the end of the choruses I really love how the vocal playfully jumps to what a high harmony might sing, if Margo Guryan had written one in. I’ll have to check out the compilation this is on, “Simultaneous Ice Cream“.