fuzzy notepad

dictproxyhack, or: ActiveState Code considered harmful

This is a story of how nothing in this story is my fault.

I’ve got a coworker who’s super into Clojure, a Lisp-like that runs on the JVM. In particular he’s super into how it’s got notions of mutability (and, thus, immutability) all throughout.

More than once he’s lamented that Python lacks a frozendict—a dictionary type that can’t be changed. Dictionaries tend to crop up a lot in Python, and in a very large codebase, it’s very easy to end up with this scenario:

  1. Some function somewhere generates a dict that’s only used by one caller. The interface is obvious since the keys and values are created right there in one place. No problem.
  2. Other code comes along, notices this handy function, and starts using its return value. Some of this code may pass the ad-hoc dict up to callers, too.
  3. Some of that other code needs more things added to the dict, but computing the extra data is expensive, so arguments are added to the function that optionally turn on certain keys.
  4. Some code needs even more things added to the dict that are outside the purview of the original function, so they add helper functions that take the ad-hoc dict and add more things to it.
  5. Since this has all now happened multiple times throughout your codebase, someone addresses the problem by writing adapter code that infers the original dict from some other object describing its structure, thus saving everyone from writing all these functions that return dicts.

A lovely spaghetti dinner. It’s now nigh impossible to trace what the dict contains or where half of it came from.

Returning an object in the first place would have avoided much of this, but when you’re sitting at step 1, that seems like a lot of effort just to return half a dozen things from a function you wrote to another function you wrote. Swapping out dict() for frozendict() is easy.

My opinion on frozendict had never grown stronger than “I guess that would be cool”, so I never sat down and wrote the class, and there must be enough subtleties that nobody else at Yelp has either.

Then today, PEP 416 came to my attention. This PEP proposed adding a frozendict type, but was rejected last year as being largely unnecessary. What’s interesting about it is that the rejection ends with almost a footnote suggesting that perhaps dictproxy ought to be exposed to Python-land, instead. And indeed this was done, and it exists in Python 3.3.

I bought a new laptop

Wow, where the hell have I been.

That whole “dying cat” thing ruined most of my April, and I spent most of May dealing with various other life crises, and then June scrambling to catch up. I’ve started and abandoned maybe half a dozen posts in that time that I will totally maybe finish someday. In the meantime, here’s something aimless and specific to me about how I bought a thing. Par for the course, then.

The controller pattern is awful (and other OO heresy)

Almost a year ago now, Jack Diederich gave a talk entitled “Stop Writing Classes“, in which he implores Python programmers to stop creating classes just for the hell of it, and specifically calls out the common pattern of a class with only a constructor/initializer and a single method—which should, of course, just be a function.

A few weeks ago, Armin Ronacher wrote a rebuttal entitled “Start Writing More Classes“, which argues that classes are essential for both writing extensible code and smoothing over crappy interfaces. (Hm. Now that I look at it again, if you read the post backwards, it almost sounds like he’s suggesting writing a class to smooth out the crappy interface you get from using too many classes…)

I’m having some trouble here, because I agree with both points of view. There must be a way to resolve this contradiction, a message that resonates with everyone.

I think I’ve found it.

Stop writing stupid classes.

Suzanne Venker is a robot alien in disguise

It’s my best guess. It would explain some things.

She has written another charming opinion piece and I can’t resist butting my big dumb head in to object to a few things here.

(The article was originally accompanied by a thumbnail of a happy couple in typical wedding garb kissing with a cool skyline background. Minor oversight: both of them were women, which sort of contradicts the article’s title in a number of hilarious ways. Strangely, this illustration has now vanished!)

Look at my cat

In early December 2011, I bought a digital SLR.

In mid December 2011, I bought a cat.

You can see where this is going.

Styx is a Sphynx, one of the hairless breeds. (Wow! Just like Dr. Evil’s cat! I have never heard that before! You are so clever!) Mel already had a sphynx, Twigs, and he pretty much sold me on Sphynxes being the best cats ever. Though I think Styx might have more of a Devon Rex personality and body shape, based on Mel’s cat breed book.

I’ve accumulated a mountain of cat photos, but only a few of them have seen the light of day. Let’s fix that! And please do pardon my shoddy attempts at composition and framing and white-balance and post-processing and otherwise trying to take photography more seriously than Instagram.

Catchin’ ‘em all

Look at this sweet guy Mel got custom-made for my birthday. There’s context here, but it’s big and complicated, so let’s just say it’s a life-size stained-glass Chandelure and is totally fuckin rad. (That’s an official life-size Eevee, for scale.)

Having a bit of trouble finding a place to keep a three-foot-tall plush, though. He’s got a hook near the top of his flame, but hanging him from the ceiling doesn’t really help since he hangs down to chest level.

Caldera is so cool.

While I’m at it, my collection expanded considerably after our two-week vacation in Japan, and I finally got around to adding a new shelf to hold them all. So, here’s what my room looks like now…

Pinkie Pie is not mine.  No, really. Left side of a big ol' shelf we stuck over my desk. Right side of the big ol' shelf over my desk.  There are a few guys in the background you can't see very well from below. All legendaries.  This is technically a closet, but it has no doors or track, so my desk sits partly inside it. In case the Celebi doesn't make me enough of a nerd, this clock can also show hex, binary, octal, and Roman numerals. The two biggest Eevees are different life-size releases.  Far right Eevee talks!  And something here is out of place... This is where the magic happens.  If by magic you mean sufficiently-advanced technology.

I’m not too proud to admit that I might have a problem: where can I possibly fit more shelves?

A new use for StackOverflow

It’s hard to get a feel for a new tool. Is it any good? Does it do anything I can’t already do? What’s the community like? Tough questions to answer without diving in and using it for a significant amount of time—and then you risk not liking the answers you get.

But fear not! I have discovered a new and brilliant way to discern the novel features of a tool, the vibrance of its community, and its range of users all at once. In mere minutes.

Look at its ten highest-voted questions on StackOverflow.

I’m totally serious. Watch.

CVs and file extensions

(This article has been translated into

Thanks!)

Like many employed engineers, I get roped into the hiring process from time to time. I don’t actually screen résumés, but I do grade some code tests, and the résumé is sent along with it—in case I find myself desperately seeking an explanation for receiving five hundred lines of JavaScript arranged as haiku.

In glancing over these résumés, I’ve observed a pattern: I’m far quicker to judge the file extension than the contents. It’s easy to lie or exaggerate in a document, but habits are far more difficult to hide. If you’re the kind of person who reaches for Microsoft Word, you’re still going to do that when writing a résumé.

I expressed this to Twitter, and not only did I get several people asking what formats I preferred, but I’m drowning in a deluge of suggestions for ridiculous résumé formats. Let us collect some here.

(Disclaimer: I don’t speak for my employer yadda yadda.)

docx: What the hell is this? Are you even a programmer? I haven’t had an office suite installed for years and I don’t plan to start now just to find out what dumb school you went to. I may open it as a ZIP and glance over the text nodes in word/document.xml; hope there’s no important formatting in here.

doc: This isn’t much better, and your office suite is ancient besides, but at least I can throw this at antiword and have a good chance of being able to read it.

pdf: Okay, sure. I apologize in advance for the horrendous mangling your hand-crafted masterpiece will experience when it encounters everyone’s HR systems from 1993.

pdf with only glyph strokes and no text information: Fuck you.

pdf clearly generated from LaTeX: Instant boner. Are you sure you’re in comp sci and not math? Maybe you want a LISP shop.

tex: Hired.

rtf: You’re either an idiot or as frustrated with the lack of light document formatting formats as I am. But it doesn’t matter because I still can’t read it.

txt: NICE, as long as it contains either RFC-style genuine plain text, Markdown, or ornate Unicode box-drawing decorations with emoji insets. Suggestions for appropriate monospace fonts a plus.

odt: This is still a pain in the ass for me to read, but kudos for trying, and double kudos for using a file format no HR department on the planet will recognize.

ps: Nice try, but I’m not a printer. Cross your fingers and hope Inkscape gets it right.

html: There is something very fundamentally wrong with emailing HTML as an attachment. If you’re so familiar with HTML then maybe you should get, like, a website.

xls, ods: Allow me to respond with this chart of how much I hate you.

xps: You are out of your goddamn mind. I’m intrigued.

xml + xsl: I’ve had enough XSLT for one lifetime, thanks.

link to a shared document on Google Drive: It appears you work for Google and they won’t let you have a real computer, only a Chromebook. They’re probably paying you more than anyone else can, so it doesn’t much matter whether we make an offer.

py: Putting your entire program in a single file is poor form. This should be a bdist egg.

exe: Acceptable only if this is a crack for expensive obscure software released in the past 15 days. I will also be judging you based on the sweet trance music that plays while it’s running.

swf: Unless this is a vim swap file, get the fuck out. If it’s a vim swap file, you direly need to delete/recover some old files, and then get the fuck out.

iso: I’m aware of precisely one psychopath who has created a disk image that boots into the OS he wrote and displays his PDF résumé. No other form of .iso submission is acceptable.

c: goddammit kevin

jpg: Now you’re just fucking with me. A text-heavy image should be a PNG.

anything that 0-days my machine: You can have my job.

Dimorphism

Today I went to the drug store. I bought nail clippers, a nail file, and a nail buffer. All existing nail clippers in this house have been transmuted into cat toys and subsequently batted into the void where lost cat toys go.

The cashier asked, with a knowing smile, “For your wife?”

Well, naturally, because dudes don’t have fingernails. That’s why guys have all the jobs where fingernails would be a hindrance or hazard, like programming or rock-climbing or making more money.

I told him “no, for me” with a sigh, and only later realized that he’d think I was sighing at myself rather than him. Whoops.


I twatted something similar last night, while looking on Amazon for lounge pants (which, let’s be honest, are just pajamas). The same category tree exists for both men and women, yet there is quite an obvious difference between men’s loungewear and women’s loungewear. Or even, hell, men’s socks and women’s socks.

I just want neat abstract patterns in nice colors. Instead, I get:

  • Solid dark blue, solid black, solid dark black
  • Plaid, usually prominently featuring the above colors
  • Bad tessellation of a beer logo
  • Stock artwork of Stewie Griffin saying something from a Family Guy episode that first aired in 1999

Y chromosomes must self-destruct in the presence of saturation, or something.

Crash!

So someone hit my car last week.

It was parked on the curb, right in front of my house. (We have four cars and a packed garage, so.) I heard a super loud smack, but thought someone had dropped a large appliance on the sidewalk until Mel appeared in my doorway with someone hit your car.

Outside I scurried in pajamas and slippers (working from home is awesome) and I beheld the scene you see inset. The driver was very apologetic, and luckily unharmed. She’d been fiddling with something on her dashboard and wasn’t even looking at the road, so she hit my car at full speed. The photo is framed as it is because my car had been parked with its rear wheel on that grate, and with the parking brake on. That’s how far she knocked it. (Speed limit on this street is 25, by the way.)

I felt kinda bad for her, but at the same time, that this even happened is terrifying. I don’t know if a human being would have survived the same impact. She said she’s “normally such a safe driver”—I guess she’s only a dangerous driver sometimes, then, and it turns out those are the times when you hit things.

Called 911; couple police cars came to direct traffic around her and file an accident report, and a flatbed tow truck took her car off. I had to leave my car “parked” in front of a fire hydrant overnight, because the rear axle was bent so much that it doesn’t move at all.

My car was towed to a local shop the day after; they called me back earlier this week with an estimate around $7400. The driver’s insurance is paying for absolutely everything without question, though, so I shouldn’t be out a dime over this. I have a rental in the meantime.

This is actually the second time this has happened; early this year I was street-parked on the other side of the street, and I awoke to find a conspicuous dent in the driver’s side door. And when I say “dent”, I mean it spanned the bottom of the door up to the window; looked like a shopping cart had hit it at an angle while going 40. I’d only slept for a few hours the night before, and Mel had been awake through the night, but neither of us heard or saw anything. Don’t know what happened or who did it. I thought it would be a simple fix, but the shop had to replace the entire door, I had to pay a few hundred deductible, and my insurance went up. Super.

I’ve never hit anything, never gotten a ticket, never even been pulled over. I live in a fairly sleepy town, not on a major road. And in two years my car has been hit twice, while parked at home. I’m just gonna start parking on the lawn.

Here are some photos of my poor darling car. Consider this a test of this fancybox plugin.

A little bit Rusty

Yelp had a hackathon a couple weeks ago. These affairs are mixed blessings for me: a fixed chunk of uninterrupted time to work on a single project is great, but I tend to have at least a dozen ideas that I want to do all at once, none of which can be reasonably “finished” in a scant 30 hours, and most of which are obscure enough that nobody can work on them with me.

For example, during this most recent event, I wrote a roguelike. In Rust.

Long-time readers may recall that I’ve attempted to write a roguelike before, in Python, but fell prey to architecture astronomy. This time would be different! Because I would only have 30 hours. Also because static typing limits my options, thus making it easier to overcome choice paralysis. (It’s a working theory.)

But first: a bunch of people have asked what I think of Rust, and now I’ve actually written something approaching a real program in it, so let’s start there.

Lasik

This is a thing I got yesterday. Not 24 hours ago, even.

Mel had it done last December and started dropping hints that I should also get it done pretty much that day. I stalled and dawdled forever, but I’ve been experiencing a lot of eye strain lately and was due for an eye exam anyway, so I finally made an appointment for Wednesday.

Not that Mel was continually bugging me to do it or anything, but when faced with the prospect of doing something terrifying, spinning it to myself as something someone else wants doing is a convenient brain hack.

Yes, terrifying. You see, I don’t like things i my eyes. I don’t like water in my eyes. I had never opened my eyes underwater until a couple months ago, and it still feels like a superpower to me. If I get an eyelash in my eye, I have to find a mirror and manually guide it out because it bugs me so much. And now I was facing a medical procedure that involved shining a laser into my eyes. A laser! You know where you’re supposed to shine a laser? Anywhere except into your eyes.

Everyone at the clinic told me reassuring things, like that it’s a cold laser, or it doesn’t hurt, or it’s over pretty fast, or whatever. No, no, you don’t understand. It’s not that I don’t like things in my eyes because some rational underlying fear. I just don’t like things in my eyes, the same way I don’t like sharp things under my fingernails, or I don’t like spiders. I don’t like it. It’s creepy and I want to run away from whatever it causing it.

Okay, this story seems to have gotten a little off-track. Let’s rewind.

Issues

I love tinkering with things, but in the absence of external stimuli (like, “it’s my job”), I’m pretty bad at finishing things. Instead I gradually accrete a ball of projects, todo lists, XXX comments, half-written blog posts, and mental notes-to-self. Eventually the mental load becomes overwhelming and I freak out at how many recreational things I “have” to do.

So I spent much of last weekend trying to alleviate this, by dumping various todo files and the contents of my head and tabs that have been open for months and half of my Workflowy into issue trackers. I know, duh, but I always get out of the habit of using them, and then it seems like more effort to get back into the habit than to just jot down or remember one more thing. Maybe this time it’ll stick. I have far more brain to be dumped, but what’s left is generally more detailed planning that won’t come into focus until I sit down to seriously work on the corresponding project. The real test will be whether I keep filing tickets as they come to mind. And actually, like, assign them to myself. And do them! Whoa.

I’m also making an effort to make my code more accessible to anyone who wants to contribute to it; I’ve been using git and GitHub for ages and attracted a couple pull requests, but I’m pretty lax about even build documentation. I wrote a few READMEs to alleviate this, and will be writing some more as I touch repositories that lack them.

Oh, if you give half a crap about what I hack, I’ve thrown together a projects page listing some of the things I’ve started attempting to build. Or you could just look at my GitHub, really. Feel free to contribute, or tell me how I’m making it hard to contribute.

And I totally cut down on the number of distinct categories I was using for this blog, so when I start posting more than once a month, categories will be useful for sifting through posts!

Heteroglot: #15 in COBOL

Introduction

Many moons ago, I started a ridiculous quest to solve every Project Euler problem, in order, with a different programming language. I called it “heteroglot“.

Partway through that, I gave myself the additional unwritten rule that the next language would be selected by polling the nearest group of nerds. This has resulted in math problems solved in such wildly inappropriate languages as vimscript, MUMPS, LOLcode, and XSLT.

It’s been a while since I did one of these, but I still remember that the next language I’m stuck using is COBOL. I don’t know who suggested it, but I hope he chokes on a rake. ♥

I figure if this is interesting to me, it might be interesting to someone else. So let’s learn some math and/or COBOL.

Stripe CTF 2.0

This is a thing I did. It was a cracking contest held by Stripe (who run a pretty neat service, btw), and it ended today. I was third to beat level 7 and twentieth to beat level 8, so here is the tale of how I came upon the solutions.

I haven’t reproduced the entirety of each puzzle below, because that would suck, but if you’re lucky maybe you can still sign up and follow along. If not, Stripe has promised to release the puzzles (and solutions) tomorrow. I think.

Quick doesn’t have to mean dirty

From TechCrunch:

Anyway, my sympathy for PHP’s deviltry is because I appreciate its ethos. Its just-get-it-done attitude. Or, as Melvin Tercan put it in his recent blog post, “here’s to the PHP Misfits. The pragmatic ones who would pick up anything – even double-clawed hammers – to build their own future. Often ridiculed and belittled by the hip guys in class who write cool code in Ruby or Python, but always the ones who just get shit done.”

He’s on to something there. The best is the enemy of the good, and shipping some working PHP code is approximately a million times better than designing something mindblowing in Haskell that never actually ships. I fully support Jeff Atwood’s call to replace PHP once and for all–but I hope that everyone realizes that eliminating its many, many, multitudinous flaws won’t be enough; they’ll have to somehow duplicate its just-make-it-work ethos, too.

This is a recurring sentiment: developers telling me, well, yeah, Python may be all cool in your ivory tower, man, but like, I just want to write some programs.

To which I say: what the fuck are you people smoking? Whence comes this belief that anything claimed to be a better tool must be some hellacious academic-only monstrosity which actively resists real-world use?

But, hey, I’m sick of talking about PHP. So let’s talk about Python. In honor of the 90s, let’s make a guestbook.