jtes.net
John Slade – Software Engineer, London UK
Category: Python

I used to develop Python code with tabs for indentation.  I don’t want to get into the religious debate of tabs vs spaces, but the Python community goes with 4 spaces for indentation.  So to allow ease of importing others code and contributing to other projects I decided to switch to spaces.

Updating Code

Update all your files is easy with find and sed:

find -name "*.py" | xargs -n 1 sed -i 's/\t/    /g'

Note: I would strongly suggest you do this on files that are under version control in case something goes wrong.

Vim Settings

Want to use spaces for Python code, but everything else using spaces?  Then add the following to your .vimrc:

au FileType python set expandtab
au FileType python setl shiftwidth=4 tabstop=4

On Saturday 11th Feb 2012, Nathan Humphreys and myself ran a Python Hack Day for a few people at my flat in Brighton.  This was the first hack day that any of us had run or attended so we didn’t know what to expect.  But we learnt lots of things along the way.

To be fair, the hack day was Nathan’s idea originally but I was immediately interested to help and organise it.  We have plans to run a larger hack day in the future, so we decided to start small and hold one in my flat.  We chose Python as a language to use since plenty of people we knew had a basic knowledge in it – plus Nathan and I have been using it side projects for a while now.

Before the day

So the first thing to do was to invite people.  We decided to just keep it to people we currently work with.  My first surprise was the number of people who initially said they were interested, but then pulled out because they weren’t sure they could write any Python code.  Seriously?  Professional software engineers should be able to pick up new languages – and IMHO be excited to do so.  The whole point of a hack day is to learn something new – and being around smart and fun people is surely the best way to do it.

In the end we had 5 people (including ourselves).

The other thing to sort before the day,  was to come up with some potential projects to work on.  There was generally a lack of ideas around, most people just wanted to come along and code something.

Start of the day

So we are good to go, 10am on a Saturday, most people have arrived and there is kitchen full of snacks.  First item is to decide what to work on. No one was really that bothered so we decided on a project that had the most scope – creating a photomosiac web app.  We decide that we would develop this on Google App Engine and split into two teams – one for the web front end and the other for the image processing backend.

The first thing we ended up doing was setup the development environments.  We must have spent the first 2 hours getting python, git, Python Imaging and the App Engine SDK working correctly on all our machines.

Once we started coding everything went smoothly, with plenty of code being written and pushed to our github repo. I had never used git before in a team environment before – only for my own projects where I have 1 developer and 2 branches. I was amazed at how easy it is to merge files and push your changes across the network to someone else.

Afternoon

Following our lunch of Pizza, we made good progress and was ready to start integrating and testing the algorithm in late afternoon.  Then it was time for intense pair debugging to get this working.  After discovering a few oddities with GAE Image functions, we finally got something basic working by 7pm and continued tweaking it further until 9.

Lessons Learnt

After the first hack day, I learnt quite a few things:

  • A 9 hour day is actually quite short, so maximise the available time.  Next time, we will try and select an idea to work on using email, create a skeleton project and ensure everyone can compile and run the project.  And all this before they arrive on the day.
  • Git and github rocks
  • Even in a single day, 5 people can create code that becomes difficult to debug and test.

What’s Next

Nathan and I have plans for more hack days as they are brilliant fun.  Next up we are going to attend some else’s hackathon – Mark Pearson’s Hackathon London on 23-25th March 2012.

Then our other ideas are perhaps an Android one and, if can get hold of the hardware, Raspberry Pi.