Father's Day    Posted:


In November, I will have proof of my manliness. No beard or axe can compete with the wee Jewell that we're going to be responsible for making stay alive.

Comments

Duplicate Keywords When Using Keyword Argument Unpacking in Python    Posted:


Python has a feature often called "Argument List Unpacking," which can be found in several other popular languages under the names "splat" (ruby), "Apply" (LISP, Scheme, general use):

>>> def all_my_args(arg1, *args):
...     print arg1  # first arg
...     print args  # list containing the rest
...
>>> all_my_args("first", "second", "third")
first
('second', 'third')

And this same method can be applied to dictionaries by using the ** operator:

>>> def all_my_args(arg1, **keyword_args):
...     print arg1  # first arg
...     print keyword_args  # dict containing the rest
...
>>> all_my_args("first", second=2, third=3)
first
{'second': 2, 'third': 3}

You can then "pack" dictionaries and handle them to functions as arguments:

>>> my_args = {"second": 2, "third": 3}
>>> all_my_args("first", **my_args)
first
{'second': 2, 'third': 3}

Now, remember that all arguments can be keyword arguments, as the order of argument parsing matters: regular arguments are first, then variable arguments (*args), then any keyword arguments (whether named explicitly via keywordname= or implied as a packed dictionary with **keywordargs). Let's expand the above function to emphasize the concern:

>>> def describe_blob(name, shape, **attributes):
...   print "Name:", name
...   print "Shape:", shape
...   for k,v in attributes.items():
...     print "{}: {}".format(k, v)
...
>>> describe_blob("Jack", "round", size="huge", weight="ugly")
Name: Jack
Shape: round
weight: ugly
size: huge

This seems really cool at first, because it lets the user of the function provide any sort of keyword they want to use to describe the blob. Unfortunately, it can cause some problems:

>>> describe_blob("Jack", "round", shape="lumpy", size="huge", weight="ugly")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: describe_blob() got multiple values for keyword argument 'shape'

Multiple values were found for 'shape', but I only specified one: "lumpy". Well, it turns out that the second position argument was internally called "shape" as well, which broke the function call. You can learn this through introspection, but that's not something one wants to do before every function is called:

>>> import inspect
>>> inspect.getargspec(describe_blob)
ArgSpec(args=['name', 'shape'], varargs=None, keywords='attributes', defaults=None)

Even if the argument list that is acceptable is described in the function's docstring, the arguments are often named in a way that's descriptively useful to developers of the function, not consumers of the function.

Ultimately, it's safer to just pass this as a dictionary, even though it seems cool to use the unpacking:

>>> def describe_blob(name, shape, attributes):
...   print "Name:", name
...   print "Shape:", shape
...   for k,v in attributes.items():
...     print "{}: {}".format(k, v)
...
>>> my_blob_attributes = { "brain": "mushy", "height": 3, "shape": "duplicative" }
>>> describe_blob("Jack", "round", my_blob_attributes)
Name: Jack
Shape: round
brain: mushy
shape: duplicative
height: 3

Comments

Starting with Nikola    Posted:


I've been itching to try out this new breed of slick and fast static site generators, and after a lot of trial and error, I've set up Nikola <http://getnikola.com/>. I'll expound on the full details later, but at this point it's really slick. I have a git repo that is the source for the site, and I run a command to generate post skeletons, then I edit them, then I commit, and a commit hook does the build and deploy.

It seems like a lot more work than you're used to - log in to site/wp-admin, click "new post", and type - but it's really pretty graceful and quick, and the end result is a tight static page whose serve speed is entirely dependent on my ability to push out bits over http. If I'm not happy with my result there, I can easily toss it up to amazon or somebody.

Comments

A Brief History    Posted:


The below text has been copied from the 'about' page.

Around the turn of the century, I registered this domain. I had no specific plan. I secured cheap hosting through the generosity of a man whom I later failed to pay. I wish with all my heart that I could remember who this man was, so that I could give him my first born. I started a simple blog, which at the time was called a weblog. It was no feat of ingenuity, but it was certainly before Facebook or Tumblr - in fact, impending popularization of sites like LiveJournal were a common source of contention, as I bemoaned the death of true web authoring due to the low barrier to entry that these amazing services provided. But I digress -

I immediately started a site called "Disclosed Information," which basically follows the model that Gawker et al now use, where I wrote brief editorial commentary on things that I found interesting, and provided links and area for comments. I expanded and took on several other editors. I peaked at around 50k uniques a day. That's some serious shit in 2000. I didn't have marketing or SEO. I ran a cute stupid site with some friends. It was fun. I sold 2 branded coffee cups.

That died off quickly, though, as the upkeep was unbearable. I didn't want to make a living there - it was just an experiment. I didn't have the business acumen to pull it off anyway. And really, I was just copping off the slashdot feel while adding some non-geek social awareness.

I took the main site down, and converted it to a proper personal weblog. This was far more gratifying! I had endless summer nights of fun sitting around with a pirated copy of Photoshop making site wireframes, then implementing them as CSS2 sites. I toyed with open-source blog software, which was truly in its infancy at the time. There was no Wordpress. For a long time, I actually used b2, which was a quiet predecessor from the original Wordpress author (if memory serves correct).

I longed to turn this into a profession, so I started writing my own blog software. I had some good ideas, and actually used it with great success for the following few years. The project is probably in some sourceforge graveyard still.

I used the blog as an outlet to express my other hobbies. I took up photography and making music, wrote book and movie reviews, documented how I learned to play Go. I wrote about my personal life and opinions. I wrote fiction without editing. I was utterly earnest and true, caring nothing for my audience. This was my writing, and you're not paying, and I don't need you, so let's do this.

In 2008, I fell silent. That makes sense - who the fuck created a blog after 2008? Only people selling something. But that just coincided with where I was in life at the time.. I was getting a little older, getting married, getting serious about my career. I think I made a Facebook account.

Looking back on the archives I have of those days, I truly and deeply miss that expression. I'm grateful to have records of it, and hints on the things that inspired it. Reading my archives reminds me that I can do things. I expected to be ashamed, or at least a little embarrased, but I'm fucking proud. I want that back. So here I go. No promises, no regrets.

bob@disclosed.org, February 11 2014.

Comments