Naildrivin' ❺

➠ Website of David Bryant Copeland

My Book’s in Beta!

Build Awesome Command-Line Applications in Ruby

Control your Computer, Simplify your Life

Woot!

My Book is in Beta! Whoohoo! It’s all about writing amazing command-line apps in Ruby. This isn’t about hacking together UNIX commands, or bash scripting…this is about making apps that are easy to learn, easy to use, easy to write, and that will delight their users. Seriously, stop making crappy command-line scripts, read my book, and start kicking ass.

It’s been a long time coming. Please stop now, and go check it out. I started this almost a year ago during PragProWriMo, where I wrote (almost) every single day in November of 2010. When I saw that Travis Swicegood (one of the few who made it all the way through) had gotten his manuscript accepted, I cleaned up a chapter and submitted and the Prags accepted!

I’ve spent my time since then writing, re-writing, re-organizing, and working hard to get this thing done. It’s in beta, meaning that you can buy the e-book and read the work in progress. It’s almost complete, just a few chapters to go, and by reading it in beta, you can give me valuable feedback to make the book even better.

Check it out now!

DC’s New 52 Review

I’ve always liked superhero stuff, but was never into comics as a kid. Reading Wikipedia summaries of the insanity that is the DC universe’s continuity makes me never want to touch the stuff. Now, it seems, they’ve thrown all of that out and started things fresh. Though it’s not a reboot. Whatever.

Why I’d Never Work for Google, Twitter, or Facebook

Just got back from OSCON 2011. There were some really interesting talks, and “the big three” were all over the place: Google, Twitter, and Facebook. I attended the Twitter talk on how they moved from Ruby to the JVM, as well a talk by Rob Pike (of Google) on Go. I use Twitter and Google a lot, and enjoyed hearing about how they work (Facebook, on the other hand, I use begrudgingly).

My first reaction to these talks was “Wow, it sure sounds like a lot of fun to work at these places!” From inventing programming languages to using Scala to scale a massive architecture, it sounds like developer shangri-la. Until recently, I was slinging Spring MVC code in vanilla Java. Sucks for me, right?

This is lazy thinking, and I haven’t fallen victim to it in quite a while. Ask yourself: “Why would Google spend the time and money to get Rob Pike to work for them and invent an entirely new programming language?” Ask: “Why would Twitter spend the time and money to design and deploy an elegant, scalable architecture using the JVM and Scala?”

An awesome new programming language, or an impressive, scalable architecture is not an end to itself. These are tools that serve some other purpose.

In the case of Google, Twitter, and Facebook, that purpose is to serve ads.

Although Steve Yegge’s keynote features him “quitting” his project at Google (which he describes as “sharing cat pictures”) to work on some higher calling (still within Google), he’s just trading one ad-serving system for another.

Google+ isn’t about sharing cat pictures, it’s about serving ads. Twitter’s massive network of 140-character bits of information isn’t about connecting people across the globe or to view current trends in worldwide thinking, it’s about serving ads. Facebook isn’t about entertaining yourself with games or sharing interesting links, it’s about serving ads.

So, why are the best and brightest in the industry busting their asses to work at these places? If all you care about is watching performance metrics increase, or playing with something new, or just watching lots of tests pass, I guess it’s nice to get paid well. But, how can this be truly fulfilling? For me, it wouldn’t be. I need the tools I’m building, the products I work on, and the architecture I’m helping to create to all serve something I’m interested in.

I’m not saying that my code needs to save the world or support humanitarian causes, but it should at least be something that I like, or I would use, or that I care about.

And I can’t fucking abide advertisements. Honestly, I don’t know anyone who does. Except, apparently, a lot of really smart software engineers.

I Spent a Dollar on Something That’s Free

Co-worker sent out an email today, letting everyone know about a handy Mac app called cdto. You drag it to Finder and, if you click it, it will open a Terminal window where the current working directory is the folder you’re viewing in Finder. Pretty handy.

Why Not Use Bash?

At RubyNation, I gave a talk on Making Awesome Command Line Applications in Ruby, which I’ve done a few times, and is what led to my currently-in-progress book on the subject.

One of the assertions I added to the talk, based on my work on the book is the specific advice to not start off in bash…use Ruby. This was questioned by a member of the audience (who I realized later was Blake Mizerany of Heroku/Sinatra fame, i.e. someone far more knowledgable than me about CLI apps, Ruby, and shell programming).

My answer was about as eloquent as a middle-school debate team closing argument and amounted to “Me hate bash.”

One Week of Using My iPad for Personal Stuff at Work

On Jan 3, I tweeted:

All personal stuff only on iPad; no twitter, email, or RSS on work computer. Will it keep me more focused?

Essentially, what I decided to try doing was to bring my iPad to work every day, and use it for Twitter, RSS, and personal emails. The only “personal” stuff I would be doing on my work machine would be IM, simply because the IM experience on iPad is not very good, and the immediacy of it would be lost on a computer that’s not right in front of me. I don’t do a lot of personal IM’ing anyway, so this seemed like a good compromise.

2010 in Review; What’s Next for Me in 2011

Yesterday, while waiting for guests to arrive at my mostly-annual New Year’s Eve party, I found a txt file I created called 2010_goals.txt. It’s contents:

  • speak at at least one more user’s group
  • speak at some sort of conference
  • deploy an App to the iPhone App Store
  • Deploy a Rails 2 app to Heroku

Static vs. Dynamic Typing: A Matter of Keystrokes?

In Java, I almost never make type errors. The type errors that are possible in Java fall roughly into two categories:

  1. Using an object of the wrong type (this is caught by the compiler)
  2. Casting an object to a more specific type at runtime (this can only be caught by tests or users :)

I’d make error #1 on occasion, but the compiler catches it. As to #2, before generics, I can count on my hands the number of times I got a bona-fide ClassCastException at runtime. After generics? Never.

I don’t mean just that I didn’t experience these runtime type errors, but that they didn’t even make it to the compiler. If you think about how Java syntax works, it’s no wonder:

    List<String> someList = new ArrayList<String>();
someList.add("Foo");
someList.add("Bar");
  

I had to type almost the exact same thing twice. After about 2 days of using generics, my muscle memory literally prevents me from making type errors. To even simulate one requires a pre-generics library call, or some herculean efforts. An arguable win for static typing, if at the price of verbosity.

Of course, in Ruby, I make type errors all the time, especially when using new libraries I’m not familiar with. Ruby libraries rarely document the types of things (though they are frequently liberal with what they will accept). The solution here is just better unit tests. And that’s a pretty good thing. So, a slight negative for dynamic typing that leads us to a better tested system, reduced verbosity, and better productivity once the learning curve is dealth with.

This pretty well illustrates the tradeoffs between dynamic and static typing. Case closed, right?

Enter Scala. With Scala, I make type errors just as much as I do with Ruby. The only difference is that the compiler catches them. Here’s the Scala equivalent to the Java code above

    var list = List("foo","bar")
  

Notce how I haven’t specified a single type? It’s nearly identical to the Ruby version:

    list = ["foo","bar"]
  

These examples are obviously simplistic, but in a more complex system, Scala’s type inferencer tends to be one step ahead of me. While it’s handy that I have a compiler to catch these type errors, the fact remains that, despite Scala being a statically typed language, I’m making far more type errors than I would in Java.

This seems kindof odd, but I think it’s ultimately a win: I get the brevity and productivity of a dynamically typed language, but the safety of the compiler catching my type errors for me.

Scala puts a subtle spin on the “static vs. dynamic” debate, because you aren’t annotating your types nearly as much as with Java, but you still get all the benefits. I’ve certainly heard many criticisims of static typing, but having the compiler check types for you wasn’t one of them.

Of course, sometimes you do need to tell Scala what your types are, but, they seem to be exactly where you’d want them anyway:

    /** get users with the given name and age */
def getUsers(name:String,age:Option[Int]):List[User]
  

This says that we take a requires String and an optional Int and will return a list of User objects. To give the same information in Ruby, you’d need to:

    # Gets the users with the given name and age
#
# name - a String
# age - an Int or nil if not searching by age
#
# Returns an array of User objects
def get_users(name,age=nil)
    ...
end
  

(Sure, you could leave off the comment, but do you really hate your fellow developers (and future you) that much?)

Now which language is more verbose? Perhaps the static/dynamic typing debate is really just about entering text?