Skip to main content


Showing posts from 2013

Making a Piña Colada in Haskell: It's All About Concurrency

I was reading The Pragmatic Programmer this morning, and it got me to thinking about Haskell.Consider the following "function" for creating a piña colada:Open blenderOpen piña colada mixPut mix in blenderMeasure 1/2 cup white rumPour in rumAdd 2 cups of iceClose blenderLiquefy for 2 minutesOpen blenderGet glassesGet pink umbrellasServeIt's very easy to understand and very linear.Now consider the following diagram that conveys which parts can be done concurrently: This description of the recipe is quite a bit more complex, but it's a lot more obvious which things can be done concurrently.There are a lot of approaches to concurrency. For years, we've relied on our CPUs to give us some implicit concurrency. The CPU can look at the code at a very micro level and figure out which assembly instructions can be done concurrently because they're working with different parts of memory, etc.Threads and processes also provide concurrency, but they're at a very differe…

Books: The Soul of a New Machine

I just finished The Soul of a New Machine by John Tracy Kidder. In short, I loved it!Computers have changed since 1981, when Tracy Kidder memorably recorded the drama, comedy, and excitement of one companys efforts to bring a new microcomputer to market. What has not changed is the feverish pace of the high-tech industry, the go-for-broke approach to business that has caused so many computer companies to win big (or go belly up), and the cult of pursuing mind-bending technological innovations. The Soul of a New Machine is an essential chapter in the history of the machine that revolutionized the world in the twentieth century.This is an oldie, but a goodie. It even won the Pulitzer prize. The whole drama is still very relevant today. It reminded me a lot of Hackers: Heroes of the Computer Revolution and Steve Jobs' biography. It definitely had elements of both, so if you enjoyed those, you'll definitely enjoy this one.

Is the Modern Smartphone a Computer?

Of course it is!If you look at the history of computers, the modern smartphone has all the same characteristics that computers have had since at least the 50s and 60s. It has a "central processing unit". It has memory. It has input/output facilities. It runs system software as well as application software. It has a mechanism for persistent storage.If you think about the big revolutions in computing, things become very obvious. First we had mainframes. Then minicomputers. Then microcomputers. Then personal computers. Now we have smartphones. Each generation is smaller in size than the previous generation. And each generation is larger in ubiquity than the previous generation.In the days of the mainframe, there was a talk about ubiquitous computing where one of the speakers predicted millions of computers. One of the audience members thought to himself, "That's the stupidest thing I ever heard. Why would anyone need millions of computers? It's not like they're…

My Wireless Sucks!

The WiFi at my house has been somewhat slow and unreliable lately, so I decided to look into it. I did a lot of experiments with Speakeasy's Speed Test. I also upgraded my wireless access point from a Linksys WRT54GL to a ASUS RT-AC56U, although that wasn't strictly necessary. I fixed it to the point where my DSL connection is once again my bottleneck. Here's what I learned.First of all, the "wireless neighborhood" I live in is very different these days than when I first setup my wireless access point. When I first set it up, I only had 1-2 devices connected to it, and there were no other wireless access points in the neighborhood. These days, I have 3 wireless devices connected to my TV, 7 Nexus 7s, 2 laptops, 2 phones, and a Rasberry Pi all connected to the same access point. Furthermore, there are 5-7 wireless access points in my neighborhood (which is still low compared to some neighborhoods). Since wireless bandwidth is a shared resource, I'm sure there&…

Books: Programming Elixir

I started reading Programming Elixir by Dave Thomas, the same guy who wrote "Programming Ruby" and who co-authored "The Pragmatic Programmer". So far, I'm really enjoying it!Here's a quote from p. 24 that I think is particularly compelling:This is a book about thinking differently; about accepting that some of the things that folks say about programming may not be the full story.Object-Orientation is not the only way to design code.Functional programming need not be complex or mathematical.The foundations of programming are not assignment, if statements, and loops.Concurrency does not need locks, semaphores, monitors, and the like.Processes are not necessarily expensive resources.Metaprogramming is not just something tacked onto a language.Even if it is work, programming should be fun.Of course, I’m not saying that Elixir is a magic potion (well, technically it is, but you know what I mean). There isn’t the ONE TRUE WAY to write code. But Elixir is differen…

Pimsleur Spanish Phases 1-3

I just finished Pimsleur Spanish phases 1-3 which I bought on In short, I thought they were fantastic!Each phase consists of 30 units, each about 30 minutes long. Hence, I did 90 units altogether. That sounds like a lot, but I did almost all of them while driving to and from work when I worked in Mountain View. I streamed them from my phone through my stereo using bluetooth.Before I started, I already had a decent grasp of Spanish. However, I started Pimsleur Spanish from scratch. I'm normally a very visual learner, and Spanish is a pretty easy language to learn visually since it's so phonetic. However, I needed something to do while driving upwards of three hours a day, and this fit the bill. I really like how conversational it is. It constantly pushes you to say new things in new situations using your existing knowledge of vocabulary and grammar.I know that some people have said that they thought Pimsleur Spanish was a little boring compared to Rosetta Stone. Ho…

Some Random Thoughts on Haskell

It seems like all my Python friends are playing around with Haskell lately, so it's been on my mind a lot lately. Since I'm a language guy, Haskell has always fascinated me. I wrote my first article on Haskell in 2006 (Everything Your Professor Failed to Tell You About Functional Programming), and I think it's a beautiful, interesting, awe-inspiring language. However, I've never really achieved full mastery of it. Since I've been thinking about it a lot lately, I thought I'd share some of my thoughts:Haskell is well known for being very concise. The functionality / lines of code ratio is very good. However, if I compare Haskell code to Python code, one thing is clear to me. Haskell squeezes in a lot more function calls per line of code than Python does. We have this idea in programming that the number of lines of code that a programmer can write in a given time period is relatively constant regardless of language. However, in my experience, I can write lines of…

Books: Two Scoops of Django

I just finished reading the book Two Scoops of Django. It was highly recommended to me by members of the Bay Area Python Interest Group. It covers Django best practices. In short, I loved it!It's not an introduction, tutorial, or a reference for Django. In fact, it assumes you've already gone through the Django tutorial, and it occasionally refers you to the Django documentation. Rather, it tells you what you should and shouldn't do to use Django effectively. It's very prescriptive, and it has strong opinions. I've always enjoyed books like that. Best of all, it's only about 300 pages long, so it didn't take me that long to read.Having read the book cover-to-cover, even though I'm fairly new to Django, I kind of feel like I know what I'm doing at this point--at least a little ;) I was afraid when I started using Django that I wouldn't have that feeling until I had used it for a couple years.So, if you're using Django, I highly recommend it!

Books: American Gods

I just finished reading American Gods. It won the Hugo, the Nebula, and the Bram Stoker award, but I read it because it was number 10 on NPR's Top 100 Science-Fiction & Fantasy Books and because my buddy Sam Rushing recommended it.In short, I really, really liked it! I didn't think I would like it at all until about chapter 3, but after that, I couldn't put it down. It's like a mix of "O Brother Where art Thou", "The Guardians", Edgar Allan Poe, John Steinbeck, and "Pulp Fiction". My only complaint was that it was a bit too violent and sexually explicit for my tastes. Aside from that, it's a very enjoyable read.

Python: dicts vs. classes

I like to "keep it simple stupid" when I'm coding Python. I use classes, but I don't try to shove everything into classes. When all you need is a dict or a list, use a dict or a list. However, I'm coming to think that if you have a bunch of objects that look like the following:books = [{ "authors": ["Neil Gaiman"], "title": "American Gods", "isbn": "9780062113450" }]Then it might be time to use a class rather than a dict. In this case, I'd create a class called Book, but I'd put Book instances into a simple list.

Python: One More Example of How PyCharm is Psychic

I had the following line in my Python code:if self._lookup_unallocated(current_allocation_state, key) > 0:I wanted to change it to:unallocated = self._lookup_unallocated(current_allocation_state, key) if unallocated > 0:Hence, I highlighted the expression, right clicked, refactor, extract, variable. It did the refactoring and automatically guessed that I wanted to name the variable "unallocated"! Presumably, it guessed based on the name of the method I was calling. Nonetheless, it's like it read my mind!

Books: Treading on Python

I just received my copy of Treading on Python! I was the technical editor :) There are two things that are great about this book. First, Matt Harrison's a really good Python programmer, and his writing is very crisp. Secondly, the book is really short! It's weighs in at a mere 183 pages!So if you're reading this, Matt, congratulations, and thanks for letting me part of your book!

Books: Programming the Rasberry Pi: Getting Started with Python

I just finished reading Programming Raspberry Pi: Getting Started with Python. I really liked it! Actually, it was really quite amazing at how much ground Simon Monk could cover in a mere 158 pages. The whole way through, he kept things really, really simple. My favorite example of this was when he built a simple web scraper that didn't even use regular expressions, let alone an HTML or XML parser! He managed to do it using nothing more than a bunch of calls to find()! It's not what I would write as a production programmer, but as a way of getting a total newbie started? Wow!I bought this book for my oldest three children, ages 7-11. They haven't read it yet, but I have high hopes that this will be the book that teaches them Python.

Use "perfect" as a verb, not as an adjective

I'm slowly making my way through the PyCon videos on, and one of them that I particularly liked was Alex Martelli's "Good enough" is good enough!He made a statement that really hit home for me. He said that we should use "perfect" as a verb, not as an adjective. That is, we should always be striving to perfect our software, without ever hoping or expecting that it will ever be perfect.I think that's a really good message, and it applies to many parts of life. I occasionally suffer from perfectionism. That one phrase has made a profound impact on my life because I no longer worry about things that are not perfect. Rather, I am happy when I can make things slightly more perfect.And let's not forget that Worse is Better anyway ;)

Twitter is Hiring Right Now

We need Scala, Java, Ruby, and Python programmers. Here is the full list of openings. If you're interested in applying, tell me which position(s) you're interested in and shoot me your resume. I'd be happy to answer any questions you have. As usual, I highly recommend the book "Cracking the Coding Interview".

Python: I Like Django

I like Django. I didn't used to. However, it's become more powerful, more flexible, and better documented since the last time I looked at it. I can now see myself really enjoying using it.

Drawing Sierpinski's Triangle in Minecraft Using Python

In his keynote at PyCon, Eben Upton, the Executive Director of the Rasberry Pi Foundation, mentioned that not only has Minecraft been ported to the Rasberry Pi, but you can even control it with Python. Since four of my kids are avid Minecraft fans, I figured this might be a good time to teach them to program using Python. So I started yesterday with the goal of programming something cool for Minecraft and then showing it off at the San Francisco Python Meetup in the evening.

The first problem that I faced was that I didn't have a Rasberry Pi. You can't hack Minecraft by just installing the Minecraft client. Speaking of which, I didn't have the Minecraft client installed either ;) My kids always play it on their Nexus 7s. I found an open source Minecraft server called Bukkit that "provides the means to extend the popular Minecraft multiplayer server." Then I found a plugin called RaspberryJuice that implements a subset of the Minecraft Pi modding API for Bukkit s…

"Await" in Python

In Guido van Rossum's PyCon 2013 keynote, he presents "a new, interoperable approach to asynchronous I/O that is being developed for inclusion in Python 3.4." Part of his proposal is a way to use "yield from" in a manner similar to await in C#. Let's just say, I'm super excited about it!

Irrduino: A Sprinkler System Built Using Arduino, Android, Google App Engine, Python, and Dart

Cross-posted from Dart News & Updates.

Developers frequently ask me if Dart is ready for the real world. Well, of course, that depends on the application. Check out this short video in which Joe Fernandez and I not only show that Dart can be used in the real world, we also show that it can be used to take the tedium out of watering your lawn!

The Dart code for Lawnville was originally written in January of 2012, a mere three months after Dart was launched as a "technology preview". That was six months before Dart's M1 release, so it's been updated a few times along the way. However, the code really hasn't fundamentally changed that much since the beginning.

Perhaps the most interesting piece of code is the use of a Queue (from the dart:collection library) to schedule watering tasks. You can click on different parts of the lawn, and the droid will fly over and water each section for a short amount of time: _actionQueue = new Queue(); ... _actionQueue…

Dart on a Chromebook: Success!

I finally have a viable approach to editing Dart directly on a Chromebook running ChromeOS! The usual approach to developing Dart code on a Chromebook is to use Chrome Remote Desktop to connect to another development machine. However, I wanted an approach that would let me develop in Dart while offline, for instance if I'm giving a talk on Dart and my internet connection goes down.

Crouton is a set of scripts based around debootstrap that bundle up into an easy-to-use, Chromium OS-centric Ubuntu chroot generator. Using Crouton, I was able to create a chroot running a basic Ubuntu setup. Within the chroot, I was able to install a JDK and then Dart Editor. Everything works, as you can see in the picture. I can switch back and forth between XFCE and ChromeOS's desktop using a key combination, and everything still runs at native speed since it's just a simple chroot.

I got everything working on my wife's Samsung Series 5 Chromebook running an Intel Atom processor. I have a …

Dart with Google Web Toolkit

Cross-posted from Dart News & Updates.

In this episode of Dartisans, I'm going to show you a variety of ways to use Dart with Google Web Toolkit. I know that there are a lot of GWT developers out there who would like to give Dart a shot, but they aren't sure how because they already have a large, successful app that's written in GWT. I'm going to show you ways to integrate Dart into your existing GWT application without having to rewrite it from scratch.

To do this, I've built a sample application that uses both GWT and Dart. I'll show you how to setup a development environment so that you can work with both technologies. Then, I'll show you a variety of ways in which you can get GWT and Dart to interoperate, such as:
Using GWT and Dart to manage different parts of the same pageUsing Dart to retrieve JSON from a Java servletUsing window.postMessage and JSNI to pass messages between GWT and DartUsing JavaScript, JSNI, and Dart's js package for synchro…

Personal: My Buddy is Looking for a Python Job

I have a buddy named Jeff Stewart who just graduated from St. Mary's College of California, which is where I'm from. He's fresh out of school and looking for his first programming job. He knows Python, Java, C++, etc. Here's his resume. I've code reviewed his code; he's smart, careful, and hard working.

Dart: My Experience Porting to Library v2

Updated: January 25, 2013: I ported the rest of my code. Hence, I updated the list below.I ported all of my code to Dart lib v2. Here's what I had to do to get all of my projects to work:Timer is now in 'dart:async', not 'dart:isolate'.Element.elements is now Element.children.LocalWindow is now Window.window.webkitRequestFileSystem is now window.requestFileSystem.Completer.completeException is now Completer.completeError.Future.handleException is now Future.catchError. Furthermore, it no longer receives a "bare" exception object. It receives an AsyncError object. Use AsyncError.error to get the original exception object.You have to use .then() and .catchError() in a single chain such as produceFuture().then((value) => null).catchError((e) => null). If you do this as two separate calls on the same future, the wrong thing will happen.innerHTML is now innerHtml.window.webkitNotifications is now window.notifications.Map.keys and Map.values return iterat…

Esto es Dart

Cross-posted from Dart News & Updates.This is a blog post for Spanish-speaking developers who may be interested in learning Dart. Please pass it along to any Spanish-speaking developers you know! En su libro El programador pragmático, David Thomas y Andrew Hunt recomiendan "aprender al menos un lenguage nueva cada año." Bueno, es un nuevo año, y creo que ahora es un buen momento para aprender un nuevo lenguage. De hecho, si usted todavía no ha aprendido Dart, no hay mejor momento!El año pasado, empecé a estudiar español para poder compartir con todos los hispanohablantes del mundo mi introducción a Dart traducido al español. Después de pasar dos días delante de un micrófono tratando de no sonar como si tuviera canicas en mi boca, les presento a Esto es Dart! Espero que les guste.In English:In their book The Pragmatic Programmer, David Thomas and Andrew Hunt recommend that you "learn at least one new language every year." Well, it's a new year, and now's …

More Dart HTML5 Goodness