Hackety Hack

Hackety Hack, a _why project. Just saw it on reddit. From the site:

In the 1980s, a language called BASIC swept the countryside. It was a language beginners could use to make their computer speak, play music. You could easily draw a big smiley face or a panda or whatever you like! But not just BASIC. Other languages like: LOGO and Pascal were right there on many computers.

In this century, you may have dozens of programming languages lurking on your machine. But how to use them?? A fundamental secret! Well, no more. We cannot stand for that. Hackety Hack will not stand to have you in the dark!!

Good stuff…_why is the perfect combination of creative & do-ative to get something like this done. Go get ‘em tiger.

Ian on Python's Makefile

Rails uses Rake in lots of neat ways. “rake test,” “rake stats,” “rake db:test:clone_structure” are three little examples that I use constantly when I’m working on a Rails project. For whatever reason, I never considered writing my own tasks, until I started looking at Marcel Molina’s excellent Rakefile in his Amazon S3 library.

I end up writing a handful of little scripts to do common chores when I’m working on a project, I’d never thought to wrap them all up in a nice Rakefile. It would be a great tool to have in Python as well. Granted, you could just write a Rakefile and use it in a Python project. There’s nothing wrong with that (in my humble opinion). Lots of people (including me) use Capistrano for deployment, regardless of the base language of the project. The right tool for the job, right? Right.

That said, for something like “a bunch of little tasks,” it would be nice to keep them in the language you’re working on at the time, so there’s less context switching on the project, right? (I guess…I’m still sort of torn on that, I don’t know if it really makes a big difference or not.) A few ChiPy’s ago, I was talking to Ian about this exact issue, “why doesn’t Python have a good rake equivalent?” He suggested I check out distutils, I did, and didn’t like it much. Over the weekend, he wrote up a good blog entry on the topic, and it seems pretty convincing.

So, in short, I’m going to give it a shot. The next time I need to write up some sort of scripty-buildy-thing on a Python flavored project, I’ll try writing it as a distutils function. I encourage you to try it too. If you need any convincing why this is a worthwhile thing, I strongly encourage you to take a long look at Marcel’s Rakefile, that thing has “develop quick and clean” written all over it.

Partitions on Rails

I’ve been following this whole Twitter thing off and on for a few days now, hoping to see some new idea on how to handle very large databases in rails. Not that I need to know at this point in my Rails usage, but it’s interesting.

Someone, presumably the author of the tool, linked to acts_as_partition, which seems like exactly what I think would be right up Twitter’s alley. Partition the database across multiple distinct databases, build some logic that says where things go, and you’re in good shape. Good stuff. If I’m not mistaken, this is very similar to the whole hibernate shard thing.

Good work acts_as_partition guy.

In related news, the module is attributed to the guys at geni.com, which is a pretty cool looking family tree application. It’s nice to see some Ajax-y-ness applied to not-another-to-do-list for once.

Twitter's Been Served

The beast has stirred. DHH makes some good points, 11,000 requests per second (spikes) are going to be hard for any web app to handle. Right? That said, he returns to his ever pleasant self with, “It’s disappointing to hear that they’ve forsaken that opportunity for an arms-crossed alternative.” Yep. If it’s open source, you can’t point out it’s flaws, unless you have a patch ready to go? Is that what he’s saying? Because…well…that’s absurd. Communication of issues is the same thing as kicking someone in the balls, right? Pointing out a flaw…that’s like…totally wrong. Sharing experiences is FUD. Clearly. (there’s some sarcasm here folks, wait for it) shame on you arms crossed Twitter developer. Shame. Shame on you.

Open source…where the source is open, and the mouths are closed.

Twitter on Rails

So, if you have any negative comments about Rails, you instantly get attacked online, right? True, unless you’re a developer for Twitter. Look, I love Rails, I really do, it’s a great framework, it’s fun to use, it’s inspired lots of good improvements in the world of web building, and it’s tremendously useful. (This is me, trying not to get jumped in an alley.)

Anyway, it’s just pretty fun to imagine a super hard core Rails zealot gearing up to comment-slam this frank assessment of Rails, and realizing he can’t, because Twitter is the current internet darling of the Web 2.0 crowd. It’s a gorgeous picture.

As an aside…could the single biggest bottleneck in the article (the database) be improved by clustering? I have to believe they’re already clustered, so I’m guessing he’d like to shard the database (which is a new concept for me). Anyone care to comment on the performance gains of a cluster vs. a bunch of shards?

Why Python 3k Shouldn't Be Ruby (and a mention of Erlang)

Just a quick response to this write up on the lack of growth in Python 3000. Python 3000 really isn’t the giant sea change that I thought it was going to be. Most of the significant work is under the covers, optimizations that will benefit me without me necessarily knowing it. The author of the above post (I’m sorry, I couldn’t find the author’s name), like me, is a fan of Ruby and Python. I think he wants Python 3000 to take on some of the traits we both love about Ruby (extreme flexibility, cleverness, many ways to do it). I know where he’s coming from, but that wouldn’t be very ‘Pythonic,’ it would be ‘Rubyonic.’

One of my favorite bits about being a polyglot is the differences between languages. What’s the point of making Python like Ruby? What’s the point of making Perl like Python? If everyone is sort of doing the same thing, where’s the fun in learning new stuff? I love Python, I love Ruby, I even love Perl. Let’s preserve their differences. Python doesn’t want you to muck around with the syntax, Ruby does. Use Ruby when appropriate, use Python when appropriate. Right?

Speaking of polyglotism, I bought that Prag-Prog Errrrrlang book over the weekend. All variables are constant, and must start with a capital letter. How’s that for balls nuts? Woo hoo! Viva la Different!

RESTful Rails

Dave Thomas posted a better explanation of the goals behind some recent Rails REST stuff today. So, the goal is to write REST first, and have your web face be a proxy for REST, just like a thick client would be. I’ve never thought of REST like that, it’s usually a nice little add-on at the end of a web app. It’s an interesting idea, for sure. I get the concept, it seems all well and good, I’m just not sure I understand what it really buys you. What’s the difference between building a conventional web app first, then adding a REST service on top of it? The suggestion is really just to swap the order out, right? Build your REST service, then your web app consumes your REST service? I get the concept (I think), I’m just not entirely sure why that’s a step forward. It’s definitely a step, I’m just not sure in which direction. My gut says it’s to the side.

This is clearly the start of a conceptual waltz.

A Very Simple Ruby DSL Example

Last night at the Perl Monger’s meeting, I showed some code I’ve been working on at work that implements a basic Ruby domain specific language. I pulled the basic concept together this morning and put it into my subversion repository here.

Building your own little mini-language is all the rage, and it ends up being pretty fun to do. However, finding simple examples can be tough. The example in my repository implements what Jamis Buck refers to as Sandboxing.

A runner script opens the file with instructions written in your mini-language, and eval’s it in the context of your DSL class. My example is of the “hello” language. You can save this to the file hellodsl_example:
[source:ruby]
hello ‘Chris’
hello ‘Camri’
hello ‘Cotton’
hello ‘Tulip’
[/source]
…execute ./hellodsl_runner.rb hellodsl_example, and get this as a result:

Hello there Chris
Hello there Camri
Hello there Cotton
Hello there Tulip

The magic happens in the HelloDsl class:

[source:ruby]
class HelloDsl
def initialize(dsl_text)
eval(dsl_text)
end

def hello(name)
puts “Hello there #{name}”
end
end
[/source]

When you initialize the class, you pass it the text of your dsl file. The text is eval’d. So you text becomes a series of method calls within the context of the HelloDsl class. The class instance, in Jamis’ explanation, becomes a sandbox in which your code is executed.

Chicago.pm Recap

I presented last night at the Chicago Perl Mongers meeting. The theme was introducing Perl people to some other languages. I think it went over pretty well. For each language, I talked a little bit about the basic syntax, library resources, and general community stuff. Then gave one “cool thing” that I think typically really makes a first looker’s eyes go wide. For Python it was list comprehensions, for Ruby it was blocks and adding methods to existing classes.

Python was a slam dunk demonstration wise, it makes sense to people. List comprehensions are so similar to map that it wasn’t really a conceptual leap. It was just something cool. Ruby was a harder sell. Opening up String and adding a is_cool? method got some good reactions, but the block concept just left a lot of heads shaking. Block usage seems sort of odd at first. I remember not really understanding how my_list.each {|i| puts i} is better than for i in my_list do. I explained that blocks are something you just use for a while, and then you realize that they sort of invert the way you think about simple things like iteration. I built a quick closure, thinking that would help, but it didn’t.

I’m giving this presentation again next month out in Wheaton. Anyone have an advice for how to better present blocks? I think it may very well be the sort of thing you don’t appreciate until you use them for a while, but it would be nice to have an example that really shook people up. Any advice is appreciated.