Ode to Em-dash

I’ll cut to the chase: you’re probably using em-dashes wrong1—if you’re using them at all. I’ll use them in almost everything I write. Em-dashes convey an abrupt change in thought in a subtler and more expressive way than a colon. Take a look at the first sentence; I use a colon to force an abrupt idea on the reader, and close the sentence off with a new thought placed in that deserved a spot in the sentence with an em-dash.

Crafting the em-dash seems to be a problem. I’ll give that there doesn’t seem to be a defined standard, but the consensus does seem to sway in the direction I’m about to present. The em-dash (“—”) gets its name because it is the width of the letter “m”, known more commonly as one “em”. Unlike an en-dash (“–”), which is used mainly for ranges2(http://en.wikipedia.org/wiki/Em_dash#En_dash “En-dash @ Wikipedia”)], the em-dash has only one use. If setting the standard were up to me, the em-dash would be set closed between words—like so—and neither open nor replaced by an open en-dash3. There are quite a few long-standing style guides that maintain this is the proper way. There’s a problem though: what do you do with a limited character set, say, ASCII? LaTeX users would argue that “‐‐‐” (triple hyphen-minus) is the correct way, but I’d stick with just two: “‐‐”.

So please, bring back the em-dash. Use it to craft your sentences to be a bit more sophisticated—‘cause parentheses suck.

  1. This is not to say I have perfect grammar
  2. There are [other uses
  3. This one confuses me. What of the em-dash then?

—★—

Apparantly, because I used OpenOffice for a year a while back, I’m a software pirate. A-list blogger Jeff Atwood posted that, essentially, any developer that refuses to pay for software and instead opts for open source alternatives is a software pirate. I’ll give him that it’s a classy way to lose a lot of respect.

—★—

Getting in the Python Mindset

Early in my Python career, I discovered import this. It’s an easter egg of sorts. Here’s the output:

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

It’s not like these concepts are Python-specific. Readability is important, regardless of language choice. Flat is better than nested, again, regardless of language choice; and so on, and so forth. What I love about Python—and I think it’s a community thing—is that people really take this to heart. I don’t believe C++ coders don’t strive for this, but they don’t have a word for it. Pythonists call it the Pythonic way.

It’s a strange concept for a beginner Python coder to understand, more so if said hacker has a background in a more traditional language—say, C++. Experienced coders often say there is only one right way to do something in Python, and that is the Pythonic way. It’s a mindset that isn’t easy to get into; I had trouble myself. I wasn’t writing bad code per say—it did what I wanted to, and often times, was more than speedy enough. It was just—looking back now—cumbersome, verbose and non-idiomatic. There’s obviously a lot of argument to what is the one, right Pythonic way at higher levels, but here’s a few examples.

A C++ coder would apply a function to every element in a list like this:

for (int i = 0; i < spam_length; i++) {
  eggs(spam[i])
}

It’s relatively clean; the syntactic structure of the for loop in C++ is short and doesn’t require much cruft. An inexperienced Python programmer might try to implement the exact same thing like this:

i = 0
while i < spam_length:
  eggs(spam[i])
  i += 1

It almost hurts me to look at that! I would hope that anyone who has been hacking around in Python for even a few weeks would see how many issues there are with that code. Luckily, even a mediocre tutorial or teacher would teach a beginner that there are better ways to do that. The next stage could possibly be:

for i in range(len(spam)):
  eggs(spam[i])

This is a big improvement. It eliminates the redundant i as a counter and iterates over a generated list of integers. A step in the right direction, but this still isn’t Pythonic. Lists (and tuples and dictionaries) and how they are handled are extremely tightly ingrained into how you write code in Python. I haven’t yet encountered a language where there is such a reliance on data structures as almost a part of syntax. The following highlights this well:

for element in spam:
  eggs(element)

That’s it: short and sweet. I should mention I’d never take this approach—I don’t like modifying lists in-place. I would use a list comprehension and generate a new list:

[eggs(element) for element in spam]

Discovering list comprehensions changed everything. So elegant, so clean, yet incredibly powerful if you employ inline if statements or use lambda expressions. You could do it with map and a lambda expression, but map (as well as other functions that I consider to be fairly useful) are being deprecated changed to return iterators with the next generation of Python, so I guess they aren’t really Pythonic! There’s so much more that I haven’t covered and hope to sometime in the future: generators, decorators, closures, etc., and while it sounds like this post is a gushing fanboy’s proclamation against C++, Python borrows heavily from other languages. Taking great features from various languages and putting them into one is a good thing1.

If you see or write a really awesome piece of Python code, I’d love to see it; maybe a nifty little Pythonic twist on a traditional method of getting something done. Go.

Update: It’s been brought to my attention that I actually presented the idiomatic C way, rather than C++ (thanks @scott_s).

Update 2: There’s a (very minor) debate going on over at News.YC as to whether for_each actually is or isn’t the idiomatic C++ way. If you think you know, please let me know.

  1. Python’s decorator syntax is from Java; list comprehensions are from SETL/Haskell

—★—

Apart from the fact that Google’s new App Engine is Python-based, I love how they are offering an overall more unified system than Amazon. Judging by the—for free—very liberal starter package, you could develop, host and deploy an app for nothing until you’re raking in pretty serious traffic.

—★—

Hover Menu

I’ve been a longtime user of moo.fx and then mootools before I was introduced to jQuery. I’ve never written about it, but I was immediately a fan. I love the way the scripts are really as unobtrusive as advertised. I was meddling with it recently, and came across an issue. jQuery’s animate (documentation) function is awesome, but it only animated parameters that accept numeric values. Think fontSize or borderWidth but not backgroundColor.

Mootools has this down. There’s a beautiful demonstration in the documentation that has a menu that cleanly animates both numeric and non-numeric values. A little perturbed, I started writing a plugin for jQuery to solve this before I decided to check the impressive list of already-existing plugins. I found Interface elements.

The solution is beautiful: ifx.js from the plugin completely overrides the animate function but enhances it. There are multiple new features, but the biggest one is that you can now animate across parameters like backgroundColor.

You’re going to need jQuery and ifx.js from Interface elements. The demonstration uses the latest versions of both as of this writing, with jQuery at v1.2.3 and Interface elements at v1.2. Before we continue, go and view the demonstration now.

The markup is just a simple list with a few placeholder elements. I imagine this could be used as a eye-catching menu.

<ul id="hover-menu">
    <li>menu item</li>
    <li>menu item</li>
    <li>menu item</li>
    <li>menu item</li>
    <li>menu item</li>
</ul>

The CSS to style this is again, just placeholder to demonstrate the effect:

#hover-menu {
    margin: 0;
    padding: 0;
}

#hover-menu li {
    display: block;
    margin: 0;
    padding: 6px;
    width: 120px;
    background: #333;
    color: #888;
}

Now the magic happens. First, here’s the Javascript that makes everything work:

<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    $("#hover-menu > li").hover(function() {
      $(this).animate({
        marginLeft:"6px",
        color:"#ff8",
        backgroundColor:"#666"
        }, 200);
    }, function() {
      $(this).animate({
        marginLeft:"0",
        color:"#888",
        backgroundColor:"#333"
        }, 200);
    });
  });
</script>

A few things to point out here:

  • We’re selecting all li elements that are children of #hover-menu. This is so that we can create lists elsewhere on the same page without having the effect.
  • The hover function I’ve used here is stock jQuery, and takes two functions as parameters. The first is what happens on mouseover, and the second is what happens on mouseout. Take a look at the code and you’ll see I am essentially reverting back to the style elements that were originally in the CSS on mouseout.
  • I had a bit of trouble getting the function to animate em units. It works perfectly with px, but if you want to use em you need to increase the value by a factor of 10 (the demonstration does this). I have no idea why—let me know if you figure out what I am overlooking.
  • You’ll obviously want to change all the parameters in both Javascript and CSS to your liking. Again, be sure to animate to your default CSS values in the second parameter of the hover function.

And there you have it, a direct replica of the aforementioned mootools demonstration. I actually prefer this script to the mootools implementation, both aesthetically and pragmatically. I also find that the end result is a little smoother—run your mouse quickly over both and you’ll find that the jQuery implementation handles very smoothly, whereas the animation of the mootols implementation stutters sometimes. Feel free to use the code as you please, and if you haven’t done so already, check out the demonstration. Enjoy!

—★—

Tinkering with NodeBox

I’m no Daniel Shiffman, but I can work my way around Processing well enough. My biggest gripe with it (and hey, I still use it) is that I need to write Java. At the risk of sounding far too alternative for my own taste, I’m just not a fan of Java. It gets the job done for Processing, and thankfully I don’t need to use it elsewhere. It does have the great advantage of being able to be easily distributed via applets, but I’d much, much rather use Python.

I was pretty excited when I heard about NodeBox. It is unfortunately Mac-only, but it’s fantastic. Essentially, it is Processing for Python. The commands are kind of the same, the general feel of the community and the general end-result of my little hacks are quite similar, but there are a few notable differences. While the Processing community has a huge array of third-party libraries, NodeBox has a small, but extremely high-quality set. That’s not to knock Processing’s contributers; I just like how the documentation, download links and examples are all centralized on NodeBox’s main website. I downloaded some of these libraries, and just tinkered around. I hacked together a few examples and sample code, tweaking a few things here and there.

Abstract Swirls

Here’s another. These were generated using the following code:

colors = ximport("colors")
boids = ximport("boids")
cornu = ximport("cornu")

size(500, 500)
bg = rect(0, 0, WIDTH, HEIGHT, draw=False)
colors.gradientpath(bg, color(0.125, 0.2, 0), color(0, 0, 0))
colors.shadow()
nofill()

relativize = lambda x, y: (x / (1.0 * WIDTH), y / (1.0 * HEIGHT))

flock = boids.flock(10, 0, 0, WIDTH, HEIGHT)
n = 15

for i in range(n):
    flock.update(shuffled=False)

    points = [(boid.x, boid.y) for boid in flock]
    for j in range(len(points)):
        points[j] = relativize(points[j][0], points[j][1])

    t = float(i) / n
    stroke(0.2 + t * 0.4, 0.4 + t * 0.3, 0, 0.5 * t)
    cornu.drawpath(points, close = True)

Easy to read Python! There will be some NodeBox specific stuff you might not recognize, but the entire thing works so simply. Apple-R, and it runs a new, completely random trial (handled by boids). I ran the script a few times, picked two of the best in a five trial run and uploaded them. I liked it so much, I tweaked the resolution and made myself a wallpaper out of it. Here it is. It’s 1280x800, the right fit for my Macbook. If you use this, shoot me an email. If you want a specific resolution of that wallpaper, contact me. I guarantee it will be the only one like it in the world!

—★—

Cool, I’m live! Quite a few hiccups to begin with, but everything seems OK now. The feed still might be a bit wonky, and unfortunately you may only find out if you’re reading this…let me know.

—★—

Introducing Jabba

I’ll be the first to admit I’ve really neglected this website. So now, I introduce Jabba. The name doesn’t really have much significance except for that I love Star Wars. I’ve moved over to Wordpress 2.5, written a theme from scratch1, and completely changed my outlook on this website.

I planned initially on merging my Tumblr account into this website and integrating the “tumbles” into the main website, but I decided against it. Instead, I’ll update both, as the focus of each is different. My Tumblr account is going to focus on the funny and quirky stuff I find around the Internet, and this will focus primarily on more in-depth writing, more reviews, and posts that deal with something a little more thoughtful.

One big change is the lack of comments. I had lots of trouble with comment spam—I honestly have no idea how the A-listers deal with it—and I just don’t have time to deal with it. The comment threads weren’t exactly burning anyway, so if you want to talk to me, use the contact form and send me an email. I’ll try to reply as soon as I can, promise.

I’ve said it plenty of times before, but I really want to stick to a regular posting schedule. I’d love to be able to pull off one in-depth article a week, with a sprinkling of smaller thoughts in between, but I don’t know if that’s feasible. What I do know is that I’m going to finally start writing posts in advance—at least, more so than I’ve been doing for the past few years.

For my fresh start I am going to ditch one-hundred and thirty-three posts. I will, more likely than not, pull in a handful of favorite posts, but for the most part, everything is going to be fresh. It’s not a decision I took on lightly; there’s a lot of me dating back just over three years, but I hope that everything on this site from now onwards is going to be the highest quality of content that I can produce. This has another negative consequence: I lose what comments I had. I apologize to everyone who poured their thoughts into a textarea.

Expect this site to have a few bugs for a while2, but I’ll try to smooth them out and keep adding new features. Thanks to everyone who’s been reading (and commenting) this long!

  1. In the past, I usually heavily modify pre-existing themes. This is the first time I’ve written a theme from scratch.
  2. Who am I kidding—forever!

—★—

The Rise and Fall of Animated Cinema

I’m a huge fan of animated cinema. I’ve watched—and enjoyed most—films from Snow White to Ratatouille, and while I’ve seen the majority of that list out of the context of the original release dates, I feel I’ve got a pretty strong grip on the technologies, reactions and social impact these films had from my research. Whether this opinion is shared by others is irrelevant to me, but I feel that animated film hit a decline with the advent of three-dimensional rendering; I just don’t think there has been another Jungle Book, Lion King or Aladdin yet.

For the purposes of this article, I’m going to assume that Pixar and DreamWorks are essentially the same—I realize there is a big difference, but it doesn’t affect my point a whole lot, so I’ll refer to the two corporations collectively as Pixar. Yes, I picked my favorite.

Gun to my head, I’d have to say Aladdin is my favorite animated film. There are some heavy contenders; the aforementioned Jungle Book, Lion King, Ratatouille and other classics like Fantasia are phenomenal films in their own right, but Aladdin stands a cheeky monkey taller than the rest. I don’t know if it is the almost perfect score, the breathtaking visuals, the pull-you-in world or the quirky and charming characters and plot that gets me, but a smart guy would say it is a little bit of them all. I sit on the edge of my seat every time I watch the thrilling race to leave the Cave of Wonders on Carpet and I feel a chill every time I see Genie under the command of Jafar. Disney magic?

Lion King

I think there are two big things that Pixar films lack compared to Disney’s two-dimensional cartoon film days. The first is the music. There is nothing that’s going to change my mind away from the fact that The Lion King has what is one of the greatest and most relevant film scores of not just animated cinema. The opening sequence of the film sends shivers down my spine every time. As much as I love Ratatouille or The Incredibles, these films couldn’t capture me with what was really just a generic, run-of-the-mill soundtrack. The Shrek series of films1 tried hardest to fill what seems to me is a gaping void, but except for the hilarious Welcome to Duloc, I didn’t enjoy much.

I don’t know why the musical as a concept was ditched—it’s not like it wasn’t working. Adjusted for inflation, Shrek 2 is the twenty-ninth highest grossing film of all time, a remarkable achievement. However, it still stands behind Snow White (tenth), 101 Dalmations (eleventh), Fantasia (twentieth), Lion King (twenty-fourth), Jungle Book (twenty-seventh) and Sleeping Beauty (twenty-eigth). Aladdin pulled in at eighty-four, with other very recognizable old-school classics appearing throughout the list. Music was a big part of these films—not only did it serve to create a soundtrack, but it did what Bollywood is now famous for: escapism. Sure, there are talking vehicles in Cars, but they don’t pull you in quite the same as a lion cub, meerkat and warthog singing about having no worries. I don’t think it’s too much of a stretch2 to say that this is essentially brainwashing little kids, but the concept worked on adults, albeit differently. A hardworking parent takes their child to see Lion King and doesn’t have to think: she can just sit back and sing-a-long to some of the catchier tunes—she can just relax.

Ratatouille

That brings me on to my second argument: the characters. Try as I might, I just don’t find any Pixar-animated character to be as in-depth, sincere and well-thought out as Aladdin, Simba or Baloo. I can’t find a Pixar villain that compares to Jafar or Shere Khan. Syndrome (of The Incredibles), for example, is a weak and under-developed villain. Lightning McQueen (of Cars) is a dull character with no real vigor or plot-driving characteristics. It seems that animated films went through a quick change from where they originally depicted characters you could put a plot around to plots with characters shoehorned in. I find it ironic that most, if not all fairy tales are named after the character they depict.

It’s hard to pin down just what exactly the fault of Pixar is here—and again, let me emphasize that despite their shortcomings, I adore many, many three-dimensionally animated films—but I’d say that for the most part, the characters aren’t human enough. I understand this being a bit rich coming from a self-proclaimed Lion King and Jungle Book fan, but even in those films, the characters were truly human. Maybe not so much for The Jungle Book, but The Lion King could pretty easily be adapted into a story about people. Pocahontas, Mulan, Cinderella and The Little Mermaid already are. The only Pixar films which feature humans in any sort of lead role are Ratatouille and The Incredibles, and even then those films barely scrape through that metric. I’m not quite sure when we, as audiences, decided that humans just aren’t good enough for animated films anymore, but clearly somebody did, and the decision seems to be quite consistent throughout the last few years and what little we know of tomorrow. Bambi is one of the most timeless animated films of all time, but sixty years from now, can you see Madagascar being held with the same regard? I can’t, but the film still grossed over half a billion dollars.

Maybe I’m just old-school that way. The new-age films aren’t doing badly by any metric, and I do enjoy them (as I’ve mentioned multiple times), but I would love for Disney to surprise me with the courage to pull off a Hayao Miyazaki3 and create a hand-drawn film with great, human characters and silly songs. Bah, I’ll take Wall-E for now, I guess.

  1. I definitely feel that these were some of the weaker films of the entire lot—how the second and third became popular is a mystery to me.
  2. Alright, maybe.
  3. Remember *Spirited Away*?

—★—

It came up in conversation, and I worked out that there is one Nintendo DS for every seven people in Japan. Japan has an estimated population of 127,433,494 as of 2007, and 18.11 million DS’s have been sold in Japan. That’s 1 DS for every 7.03 people. Awesome.

—★—

« Previous PageNext Page »