Skip to main content

Ralsina.Me — Roberto Alsina's website

Driving a Nail With a Shoe I: Do-Sheet

I had pro­posed a talk for Py­Con Ar­genti­na called "Driv­ing 3 Nails with a Shoe". I know, the ti­tle is sil­ly, but the idea was show­ing how to do things us­ing the wrong tool, in­ten­tion­al­ly. Why? Be­cause:

  1. It makes you think dif­fer­­ent

  2. It's fun

The bad side is, of course, that this talk's con­tents have to be a se­cret, or else the fun is spoiled for ev­ery­one. Since the re­view process for Py­ConAr talks is pub­lic, there was no way to ex­plain what this was about.

And since that means the re­view­ers ba­si­cal­ly have to take my word for this be­ing a good thing to have at a con­fer­ence, which is un­fair, I delet­ed the pro­pos­al. The good (may­be) news is that now ev­ery­one will see what those ideas I had were about. And here is nail num­ber 1: Writ­ing a spread­sheet us­ing doit.

This is not my first "spread­sheet". It all start­ed a long, long time ago with a fa­mous recipe by Ray­mond Het­tinger which I used again and again and again (I may even be miss­ing some post there).

Since I have been us­ing doit for Niko­la I am im­pressed by the pow­er it gives you. In short, doit lets you cre­ate tasks, and those tasks can de­pend on oth­er tasks, and op­er­ate on data, and pro­vide re­sults for oth­er tasks, etc.

See where this is go­ing?

So, here's the code, with ex­pla­na­tion­s:

cells is our spreadsheet. You can put anything there, just always use "cellname=formula" format, and the formula must be valid Python, ok?

from tokenize import generate_tokens

cells = ["A1=A3+A2", "A2=2", "A3=4"]
values = {}

task_calculate creates a task for each cell, called calculate:CELLNAME. The "action" to be performed by that task is evaluating the formula. But in order to do that successfully, we need to know what other cells have to be evaluated first!

This is im­ple­ment­ed us­ing doit's cal­cu­lat­ed de­pen­den­cies by ask­ing doit to run the task "get_de­p:­FOR­MU­LA" for this cel­l's for­mu­la.

def evaluate(name, formula):
    value = eval(formula, values)
    values[name] = value
    print "%s = %s" % (name, value)

def task_calculate():
    for cell in cells:
        name, formula = cell.split('=')
        yield {
            'calc_dep': ['get_dep:%s' % formula],
            'actions': [(evaluate, (name, formula))],

For example, in our test sheet, A1 depends on A3 and A2 but those depend on no other cells. To figure this out, I will use the tokenize module, and just remember what things are "names". More sophisticated approaches exist.

The task_get_dep function is a doit task that will create a task called "get_dep:CELLNAME" for every cell name in cells.

What get_dep returns is a list of doit tasks. For our A1 cell, that would be ["calculate:A2", "calculate:A3"] meaning that to calculate A1 you need to perform those tasks first.

def get_dep(formula):
    """Given a formula, return the names of the cells referenced."""
    deps = {}
        for token in generate_tokens([formula].pop):
            if token[0] == 1:  # A variable
                deps[token[1]] = None
    except IndexError:
        # It's ok
    return {
        'result_dep': ['calculate:%s' % key for key in deps.keys()]

def task_get_dep():
    for cell in cells:
        name, formula = cell.split('=')
        yield {
            'name': formula,
            'actions': [(get_dep, (formula,))],

And that's it. Let's see it in action. You can get your own copy here and try it out by installing doit, editing cells and then running it like this:

ralsina@perdido:~/dosheet$ doit -v2 calculate:A3
.  get_dep:4
.  calculate:A3
A3 = 4
ralsina@perdido:~/dosheet$ doit -v2 calculate:A2
.  get_dep:2
.  calculate:A2
A2 = 2
ralsina@perdido:~/dosheet$ doit -v2 calculate:A1
.  get_dep:A3+A2
{'A3': None, 'A2': None}
.  get_dep:4
.  calculate:A3
A3 = 4
.  get_dep:2
.  calculate:A2
A2 = 2
.  calculate:A1
A1 = 6

As you can see, it al­ways does the min­i­mum amount of ef­fort to cal­cu­late the de­sired re­sult. If you are so in­clined, there are some things that could be im­proved, and I am leav­ing as ex­er­cise for the read­er, for ex­am­ple:

  1. Use up­­­to­­date to avoid re­­cal­cu­lat­ing de­pen­­den­­cies.

  2. Get rid of the glob­al val­ues and use doit's com­put­ed val­ues in­stead.

Here is the full list­ing, en­joy!

The Coldest War (The Milkweed Triptych, #2)

Cover for The Coldest War (The Milkweed Triptych, #2)


This tril­o­gy is a tricky read. Most char­ac­ters just suf­fer through hor­ri­ble things.

Al­so, the way the or­a­cle's pow­er works is fair­ly ob­vi­ous, and there are (a­gain) ob­vi­ous coun­ter­mea­sures that could have been tak­en by the oth­er par­ties in or­der to ren­der her
pow­er use­less (ex­am­ple: killing her).

On the oth­er hand, it de­scribes a world that feels as if it ex­ists or ex­ist­ed, which is some­thing I re­al­ly like in sci­ence fic­tion.

Apple uses skeuomorphism, but it's not because they are idiots.

Ev­ery day there is a new post de­cry­ing Ap­ple's taste­less use of skeuo­mor­phism (y­ou know, mak­ing cal­cu­la­tor pro­grams look like cal­cu­la­tors and note-­tak­ing apps look like notepad­s?).

I to­tal­ly agree that skeuo­mor­phic apps are ug­ly and stupid. I said that in 2-t­hou­sand-f­reak­ing-­four. But just look­ing at the lat­est abom­i­na­tion (it seems to be a sound recorder that looks like a ree-­to-reel, of all things) and sneer­ing is worse, be­cause that means you don't have any ideas of where de­sign comes from, and I say this be­ing a per­son with as much taste as a wal­rus.

De­sign comes from peo­ple. There is a grander de­sign be­hind that spe­cif­ic de­sign, which you could call a guide­line, or a phi­los­o­phy, or in some cas­es a zeit­geist. For 50 years, there has ex­ist­ed a con­sen­sus about clean­li­ness of de­sign be­ing a good thing. It start­ed in some spe­cif­ic nich­es while oth­ers went in oth­er di­rec­tions (car fin­s!) and lat­er each area of de­sign has moved, like a pen­du­lum, to­wards clean­li­ness or "spe­cial­ness".

Once you go "clean", and ev­ery­one goes "clean" there is very lit­tle you can do to make your prod­uct dis­tinc­tive, and a ten­sion is cre­at­ed to make it less clean and more "spe­cial".

Google's en­try page used to be ab­so­lute­ly clean. A place to en­ter tex­t, and two but­ton­s. Now it has a menu with 11+ item­s, 3 but­ton­s, and an icon. Ap­ple's OS9 was as­cetic, and now OSX is a sea of boun­cy col­or­ful things shout­ing at you.

The skeuo­mor­phism and oth­er in­di­ca­tions of overde­sign, of com­pli­ca­tion, in ap­ple's apps is not un­in­ten­tion­al, it's an in­ten­tion­al at­tempt at mak­ing the ap­pli­ca­tions spe­cial, ap­peal­ing, and dis­tinc­tive. It is ug­ly and aw­ful, but it is so in­ten­tion­al­ly, be­cause the very con­cepts of ug­li­ness and aw­ful­ness are just a vague con­sen­sus among the user­s, and Ap­ple sure­ly felt con­fi­dence that user­s, ac­cos­tumed to Ap­ple's role as kings of taste, would change their taste to fit. And as far as I can see that is ex­act­ly what has hap­pened.

Users are not the ones com­plain­ing about Ap­ple's de­sign style, oth­er de­sign­ers are com­plain­ing. That sig­nal­s, to me, a dis­con­nect be­tween the taste of de­sign­ers and the taste of user­s. And hon­est­ly, the taste of de­sign­ers is on­ly of vague aca­dem­ic in­ter­est to com­pa­nies try­ing to sell prod­uc­t.

Ap­ple's hard­ware stays min­i­mal­is­tic be­cause they have suc­cess­ful­ly brand­ed it. If you see a squar­ish slab of black glass with a but­ton, you think iPad or iPhone de­pend­ing on size, not "gener­ic min­i­mal­is­tic touch de­vice". On soft­ware, that did not work. There was noth­ing in­ter­est­ing or in­no­va­tive, or dis­tinc­tive in min­i­mal­is­tic de­sign for ap­pli­ca­tion­s.

So they start­ed with col­or­ful gum­drop­s, moved on­to brushed met­al, and then in­to fake stitched leather, be­cause they are try­ing to find some­thing that can be as suc­cess­ful­ly and pow­er­ful­ly brand­ed as "sil­very slim wedge with black keys" is now.

De­sign­ers ap­par­ent­ly seem to be­lieve there is cer­tain spe­cif­ic "clean­li­ness" that is the hall­mark of "good" de­sign, and that ripped pa­per and oth­er skeuo­mor­phic af­fec­ta­tions are signs of bad taste. That is sil­ly and ahis­toric. Clean­li­ness is just a fash­ion, reel-­to-reel dig­i­tal recorders are an at­tempt at cre­at­ing a taste. It's am­bi­tious, and re­spectable.

On the oth­er hand, it is ug­ly as hel­l.

Year Zero

It starts with these two alien­s:

And a lawyer called Nick Carter, who is not this Nick Carter:

If I were to de­scribe the plot, it would make me sound in­sane, which is a good thing. So, I will just let the book trail­er do the work:

Have you ev­er read Dou­glas Adams and wished the plot start­ed mak­ing some sense? Have you ev­er read Ter­ry Pratch­ett and wished there was more than one ex­cru­ci­at­ing­ly stretched joke per book? [1]

Well, if you have, I rec­om­mend you give Year Ze­ro a try. It's hi­lar­i­ous, it has a plot of sort­s, and has at least three dif­fer­ent jokes in it. A work­ing knowl­edge of lame 80s (and 70s) mu­sic helps but is not hor­ri­bly nec­es­sary.

So, I give this five stars [2] and rec­om­mend it to ev­ery one.

Tus Amigos

Sor­ry, span­ish on­ly.

Miren la ban­da.

No ten­go mu­chos ami­gos. Ten­go tres o cu­a­tro, ponéle. Se­guro no más de 10. Ten­go mu­chos cono­ci­dos, ten­go mucha gente que me cae bi­en, habrá al­guno que le cai­go bi­en, habrá otros que me cono­cen. He tenido ami­gos que nun­ca ví, ten­go ami­gos que nun­ca veo, ten­go ami­gos que nun­ca voy a ver porque tu­vieron la mala idea de morirse antes que los vea.

Ten­go ami­gos que quiero mu­cho, ten­go ami­gos que me ca­gan de risa, ten­go ami­gos y ten­go ami­gas, ten­go al­gu­na her­mana pos­ti­za que la quiero co­mo si fuera mi hí­gado, ten­go mi es­posa que es más ami­ga, ten­go ami­gos que quisiera ver más.

Hay ami­gos que no me cono­cen, pero si al­guien te re­gala un li­bro que te cam­bia la vi­da, o una can­ción que te lev­an­ta a la mañana, o un pro­gra­ma de ra­dio que te hace olvi­dar to­das las noches la bosta que fué el día, es­os son ami­gos míos, aunque yo no sea ami­go suy­o.

Hay gente que no conoz­co que me ha agrade­ci­do al­gu­na cosa que hice y supon­go que yo seré ami­go suyo aunque no sean ami­gos míos. A el­los les di­go que son ami­gos míos tam­bién.

No ten­go ami­gos de la in­fan­ci­a, no ten­go ami­gos de la ado­les­cen­ci­a, ten­go al­gún ami­go de mis vein­tipi­co, ten­go más de mis trein­tas, to­davía no ten­go uno de los cuarentayp­i­co. Ten­go ami­gos en otros país­es, ten­go ami­gos acá al la­do. Ten­go pocos pero son vari­a­dos. Ten­go pocos pero son los mejores.

Y cuan­do me muer­a, si me ha­cen la gaucha­da de no morirse antes el­los, ojalá ten­ga una coro­na que di­ga: Tus Ami­gos. Y se la destapen y se la tomen, los putos.

Contents © 2000-2024 Roberto Alsina