Archive

Uncategorized

A lot of people have asked me for advice on learning to code. What should I learn first? How long will it take? How can I get a job as a programmer? The answer to most of these questions is “it depends.” But there is one question that I can answer definitively. Should I learn to code? The answer is yes.

No matter what your day job is, how old (or young) you are, or what your level of commitment might be, any exposure to programming will have a notable impact on your life. Learning to code is like learning to speak a new language. With a relatively small amount of effort — just learning a few phrases really — you’ll find that a whole new world has opened up to you.

In the next few paragraphs I’ll try to say some stuff that’s relevant to as many people as possible.

My first recommendation for learning to program is to learn HTML. HTML is the language of the web. It’s relatively simple, and very forgiving of mistakes. It’s a great way to ease yourself into a very fundamental aspect of programming: syntax. Before you can make any headway, you have to learn to read and write syntactically correct code. htmldog.com has some great introductory tutorials on the subject that walk you through creating a simple web page. After a few hours you will have an understanding of a core piece of technology that billions of people use every day and which has completely transformed the world in the last two decades.

Once you have a bit of HTML under your belt, you can move on to a simple procedural programming language like python. Python is a great programming language to start with because it lets you focus on the more conceptual side of programming without having to worry about the nitty gritty details of how computers really work on the inside. What makes python especially great is that it’s not just for beginners. Some of the biggest sites on the internet were programmed in python. The most popular example is YouTube. The Beginner’s Guide on the python website has a very thorough list of resources for learning python. Ten years after reading it, I still recommend the book I used to learn python, which is available online for free: How to Think Like a Computer Scientist, co-authored by my first computer science teacher: Jeff Elkner.

If you’ve managed to navigate your way through HTML and python, then you are well on your way to accomplishing any goal you are willing to pursue.

Now a word about motivation. Programming can be hard. Programming can be frustrating. At some point you will find yourself staring at your computer screen for an hour, not being able to figure out why your code isn’t working the way you expect. This is par for the course and a normal part of the learning process. I’ll leave you with a few tricks to getting through these rough spots.

  1. Try not to program alone. Two heads are better than one and 99.999% of software is written collaboratively. Working together makes problem solving a lot easier and you’ll learn more in the process. There is an entire programming methodology that is premised on two people working together. It’s called Pair Programming and you should do it.
  2. Have a project. It’s incredibly boring to spend all your time doing tutorials and reading books. It doesn’t matter how big or small the project is, it’s just there to act as a test bed for all the new things you are learning. A great first project is making a personal web page about something you are interested in, or even just coding up your resumé in HTML.
  3. Get involved in an open source project. There are tons of projects out on the internet that other people have started and which desperately need your help to fix bugs, build new features, or even just write documentation. Working on an open source project is a great way to improve your coding skills because you can learn from the code that’s already been written. If you are reading this and already have an open source project that you are working on, add a link to it in the comments.

At the request of many people, I’ve moved the code from my Easy Facebook Scripting in Python gist into a proper Github repository and made a python package for it that has been published to pypi. The api has changed a bit so be sure to check out the documentation in the README file.

In the next release of fbconsole, I plan on adding these additional features:

  • Handling of expired access tokens
  • Logout function
  • Video upload support

If there are any specific features you’d like to see added to fbconsole, file an issue on Github.

Last Thursday, we decided to flip the switch on the brand new version of Divvyshot, which I’ve spent a good chunk of the last 6 months working on. With the help of Michael Yuan’s brilliantly simple design, and Sam Odio’s unwavering tenacity, I feel confident in saying that Divvyshot is the easiest and most beautiful way to share photos on the web today.

So let me take a moment to tell you exactly how Divvyshot is breaking new ground for online photo sharing by going through some of our user interface decisions. We spent a lot of time avoiding some existing user interface paradigms, which though commonplace on the web, are clunky and unpleasant. Here’s a sample.

Just Say No to Paging

Most websites that display lots of information use paging to split up the information into distinct chunks. When you search on google today, if the result you are looking for is not in the top 10, you have to click through to the second, third, or fourth (sometimes more) pages. Paging is used to improve page load times as less data is being sent over the internet, but it has the undesired effect of breaking up the natural flow of your eye from top to bottom. On Divvyshot, we display lots of data; sometimes thousands of photos on a single page, but instead of forcing you to click through 10 or 20 pages of 100 photos each, we automatically load more photos as you scroll down the page. Using the load more on scroll model the user has the best of both worlds: a page that loads quickly, and an uninterrupted browsing experience. It’s fast, simple and intuitive. Even your mom can do it.

Edit Forms? Who needs them?

Many websites force users onto a separate webpage for editing content. If you are making big sweeping changes to the content or entering in a lot of data (think website billing information) having a separate page can clean things up. But if you just want to change one little piece of information (like correcting a typo), you have to go through an unnecessarily lengthy process of clicking on an edit button, waiting for the edit form to load, typing in the new data, clicking the save button, and waiting to be taken back to the first page you were on. That’s a lot of clicking around and waiting for such a minor change. On Divvyshot, editing little bits of data is completely integrated into the user interface. Want to rename a photo? Just highlight the text, type in a new one, and hit enter. The new name is saved immediately, without the need for any page reloads or excessive clicking.

Page Refreshing is Old School

Divvyshot is by no means a static website. Things are constantly changing as new events get created, new photos are uploaded, comments are being written, etc. Rather than having to hit the refresh button every 30 seconds to see if your friend has uploaded the photos from the party last night, Divvyshot automatically updates the page when there is something new to look at. You can literally see new photos stream onto the page as they are uploaded by someone on the other side of the Earth. Even though I implemented this feature, it still catches me by surprise every time something new pops up onto my Divvyshot page. I can’t help but think, “that’s cool”

Uploading Files in the Year 2010

Uploading files to the web has been a painful process for a long time – especially if you need to upload multiple files. Often times the user is provided with a few file input widgets which they can diligently click on to select files, then hit the send button and wait patiently as the data is uploaded to the web synchronously – remember not to hit the refresh button or you might submit your files twice! Uploading files with AJAX in the background is also a painful experience requiring the awkward use of iframes, and still requires those pesky file input widgets.

Java applet uploaders were at one point the answer to multifile upload, even allowing you to drag and drop files like a normal desktop application. But java applets take forever to load and sometimes just don’t work for reasons that are difficult to debug. When’s the last time you updated the version of java running on your machine?

Then there is flash, which now provides a hook for selecting multiple files. When combined with a JavaScript bridge, you can whip up a pretty good multifile upload experience using something like SWFUpload. Unfortunately, flash is not quite a panacea, bringing its own problems to the table. Anyone here use linux?

Despite a long history of less than stellar file upload patterns, there is a light at the end of the tunnel. That light is HTML5. With the latest version of Firefox, it is now possible to build a truly beautiful and intuitive upload experience. Firefox 3.6 supports dragging and dropping of files onto any drop target, the selection of multiple files from a file input widget, and the reading of that file data in JavaScript for asynchronous uploading. Other modern browsers like Chrome and Safari should follow suit with their own implementations in the near future. Divvyshot has embraced this and other cutting edge browser technology to take user experience to the next level. Check out this quick screen cast showing just how drag and drop uploading works:

We’re very excited about Divvyshot. If you haven’t checked it out already, it’s definitely worth a look. We also love to get feedback. Email human@divvyshot.com or check out our page on uservoice to submit a feature request or vote on others.

django-piston is a mini framework for creating REST APIs. One of the big reasons to use django-piston rather than rolling your own framework is that it supports OAuth authentication “out of the box.” Unfortunately, documentation on how to enable OAuth authentication is largely lacking. Here are the steps I went through to fully hook up OAuth support in my django-piston powered REST API.

  1. Add piston to installed apps and run syncdb
    This step isn’t necessary when using piston without OAuth support. However, if you want OAuth support, piston defines a few models that are needed to keep track of the OAuth tokens and consumer keys. Adding piston to INSTALLED_APPS will register these models.
  2. Add an oauth challenge template at oauth/challenge.html
    For some reason, this template does not come with django-piston. When an unauthenticated request is made to an API protected by OAuth, the contents of this template will be returned. In theory, the template should describe what OAuth is and how a client programmer can get access to the API using OAuth. In practice it doesn’t really matter what you put there, you just have to have the file to avoid TemplateNotFound exceptions.
  3. Hook up OAuth token urls
    OAuth requires the web service to provide three urls through which OAuth can aquire the proper tokens and authorize a user. Piston provides views for these functions which will create the proper tokens and integrate with Django’s auth framework. Here is how my url conf looks:
    urlpatterns = patterns(
        'piston.authentication',
        url(r'^oauth/request_token/$','oauth_request_token'),
        url(r'^oauth/authorize/$','oauth_user_auth'),
        url(r'^oauth/access_token/$','oauth_access_token'),
    )
          
  4. Add an authorization template at piston/authorize_token.html
    This template is for the page the user will be directed to when they authorize the client application. It should be a simple form asking the user to confirm that they want to give the requesting application access to their data. Piston actually comes with this template but it unfortunately lacks a submit button! You also want to write your own template so that it can be better integrated with the look and feel of your site. Just to get things going, here is a sample that works:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
      <head>
        <title>Authorize Token</title>
      </head>
      <body>
        <h1>Authorize Token</h1>
    
        <form action="{% url piston.authentication.oauth_user_auth %}" method="POST">
          {{ form.as_table }}
          <button type="submit">Confirm</button>
        </form>
    
      </body>
    </html>
          

    If you want to further customize how this particular page works, you can specify an OAUTH_AUTH_VIEW setting to tell piston which view to use. For example:

    OAUTH_AUTH_VIEW = 'api.views.oauth.authorize_oauth'
    

    You’ll want to take a look at piston.authentication.oauth_auth_view as a reference when writing your own view.
  5. Add your first OAuth consumer!
    You can either do this programatically in the shell, or using django’s admin interface. If using the admin interface, you’ll have to register the piston.models.Consumer model with the admin.

I’ve had OAuth up and running now for a few days and am very glad that users will no longer have to give API clients their username and password to access their private data. It was a bit of a pain to set up but I think it’s worth it.

After 18 months at Keas Inc. I have made the very difficult decision to move on to a new (ad)venture.

I am very excited to announce that as of today I will be working at divvyshot.com, a very new Y Combinator backed startup currently based in San Francisco.

At Divvyshot I will continue my self education in all things Web; front to back, top to bottom, inside and out. My primary job will be writing code, and lots of it. There will be more details later, but right now I have to go write some code.

z3cformdocumentation

I’ve just been playing around with Sphinx, the new cool documentation generation tool for python. It takes a bunch of restructured text documents (like doctests!) and converts them into a slick looking website that will literally blow your mind. I was able to create a fairly complete documentation site for z3c.form in about an hour. Check it out, and let me know what you think. The URL is http://docs.carduner.net/z3c.form/.

Some nice features of Sphinx are:

  • Full documentation search
  • Module index
  • Documentation cross referencing
  • A lot more that I haven’t had the chance to play with

My U-Haul and Me
I’ve spent the last several weeks being extremely busy. I’m afraid anyone waiting for the updates to the z3c/zope tutorial may have to wait a little longer.

These are roughly the steps that I took to get through the last several weeks:

  1. Drop out of school halfway through my junior year – yes, I’m officially a college drop out, but far from being a “deadbeat.”
  2. Fly all around the country/world looking for a job. I don’t even want to think of my carbon footprint right now.
  3. Meet Adam Bosworth (who is “just a simple country boy from Vermont”) and get an awesome job at an awesome startup with awesome coworkers.
  4. Rent a truck and drive 18 hours from Eastern Washington to Sunny San Francisco (although it was pouring rain/snow/sleet the whole way).
  5. Find a great apartment in a great neighborhood (Downtown Berkeley), and generally “live it up.”

Overall, I’d say I’m pretty happy about life at this particular moment.

One of the SchoolTool developers, Ignas, created a buildout script that generates ctags for any python egg and all of its dependencies, to be used with emacs or vim. Seeing just how useful such a buildout script is, I decided to package it up and release it as an egg under a new package name: z3c.recipe.tag. Here is the rundown on using it (direct from the README.txt):

Dependencies

Before running a tags enabled buildout, you must install the
appropriate command line tag generation tools: exuberant-ctags and
id-utils. In Ubuntu, you can install these with apt-get::

$ sudo apt-get install exuberant-ctags id-utils

How to use this recipe

Suppose you have an egg called “MyApplication“. To use this recipe with
buildout, you would add the following to the “buildout.cfg“ file::

[tags]
recipe = z3c.recipe.tag:tags
eggs = MyApplication

This produces a script file in the bin/ directory which you can
then run like this::

$ ./bin/tags

This script produces files called TAGS (for emacs) and tags (for vi) in the directory from
which you ran the script. You can then use this file in your editor
of choice.

I’ve just been playing around with Google Trends to see how the various open source web frameworks are stacking up against each other.

The chart below shows the trends for zope (blue), turbogears (red), django (orange), and ruby on rails (green). Clearly zope has been in a steady decline since these other web frameworks started showing up. Could it be that their websites are so much better than zope.org and that they have so many more tutorials and documentation (doctests do not count!) than zope? I think the answer is yes. I hope this changes.
trends-aggregate.png
If you are looking at this blog post another couple years down the road, try doing the same google trends query and see what it looks like now.

I’ve continued to make some progress today on the z3c.* packages tutorial. I added a section on skinning your application using z3c.layout, z3c.pagelet, and z3c.template. There is also code highlighting, thanks to pygments and their rst directive. For the next update I’m hoping to add a section on z3c.menu (which is now z3c.menu.simple) and eventually I might even get to z3c.formjs.

I also added a brief introduction, which I’ve included below:

In the last nine months or so, not long after Philipp von Weitershausen published the second version of Web Component Development with Zope 3, Zope 3 underwent a massive change and restructuring. The application once known as Zope 3 split into a hundred peices in favor of “Zope 3 the framework”. Each component of Zope became a separate package distributed via eggs with ever-complex dependency trees. Another big change for Zope in the past 9 months has been the creation of numerous community maintained packages which are not considered “zope core”. These are the z3c.* packages. Written predominantly by rebelious Zope 3 hackers looking to make Zope even more powerful than before, the z3c.* packages quickly took center stage. Unfortunately for the rest of us, those who knew how to use the z3c.* packages were too busy being incredibly productive and successful that they never wrote any new books, tutorials, or easy to follow documentation. This document aims to assuage the woes of those still doing things the old way by providing a humble introduction to z3c.*.

So check it out at http://docs.carduner.net/z3c-tutorial/ and leave any comments you have on this blog post (or email me (or both)).

Follow

Get every new post delivered to your Inbox.

Join 65 other followers