Archive for December, 2007

Python talk for WYLUG, Ruby envy, Haskell Joy.

December 27th 2007

I am just getting a talk ready for WYLUG on python.

I sent Dave the following blurb:

Why I love Python:

A talk on the programming language Python, in 3 parts (feel free to
leave in the interludes if you have had enough)

Part 1: Past, Present, Future.
A bit of history and the design of the language, a look at all the
implementations available today, quick tour of built-in and commonly
used modules and future plans.

Part 2: Language overview
A quick tour of the language: builtin types, control structures, using
modules etc

Part 3: Recent Magic.
Some relatively recent changes that make programming Python even more
pleasurable.
Decorators, Generators, List comprehensions, Iterators, Functools and
anything else I can fit in.
Again a whirlwind tour, but you should be impressed and want to read
up on these some more

I have been revisiting some of the Python talks I have watched over the last few years for ideas and will update my ComSci page with links.

I stumbled across some excellent video from RubyConf, particularly the Rubinius one. Rubinius is a ruby VM partially written in Ruby, taking some lessons from Python and Smalltalk. Some of the stuff he bigs up (compiling to bytecode automatically comes to mind) Python has had for ages, but the self hosting aspect is cool (not as cool as PyPy though). Rubinius seems to be doing what Avi Bryant suggested here, learn from the Smalltalk guys and the papers from the Self team that Sun spun off and later bought back to do the hotspot VM for Java. Interesting times for dynamic languages, target the JVM, CLR, self host and generate code in other languages while always writing in the same fun language. I say Ruby envy only because I think the Ruby community does a better job of looking cool and exciting people than the Python one.

Now Haskell joy. After describing working through Yet Another Haskell Tutorial to the 2 friends doing it with me as “not an obviously pleasurable experience” I had a great moment on the train the other day looking at partial application.
(\y -> y*3)
is Haskell for the anonymous function that takes y and multiplies it by 3 (I wish I had LaTeX here to draw the lamda calculus). What I like is that you can also write that as
(*3)
While this example is trivial, what is happening is interesting. The compiler knows * is an infix operator that takes 2 arguments and that is has been supplied one and “partially applies” the function, making (*3) (a function that takes one argument). One more thing is changing prefix and infix operators around using ( _ ) and ` _ ` , for example:
3 * 5
(*) 3 5

map (*2) [1,2,3]
(*2) `map` [1,2,3]

I hope this second example is clear, map usually is a prefix function that takes a function and a list and returns a list with the result of applying the function to each element (the return value here would be [2,4,6]). This flexibility is neat and is starting to make Haskell a joy to hack in.

Merry Christmas,

Posted by tom under haskell & Python & Ruby | No Comments »

Microfinance and Peer Lending

December 15th 2007

No blog post for a week, perhaps I am not as self important or tenacious as I think I am.

I have been meaning to read Muhammad Younus’s book “Banker to the Poor” for a while, I had not heard of him till he won the Nobel Peace Prize. He helped found the Grameen Bank, a bank that lends small amounts of money to poor people in Bangladesh who have no collateral (called Microfinance for obvious reasons), and later the Grameen Foundation. Access to collateral is obviously really significant in your success; I know a great way to have a guaranteed income of 80k a year (less tax), put a million quid in a savings account at 8%.

Peer Lending is another topic that is becoming popular, particularly as we experience the so called credit crunch. Zopa in the Uk and Prosper.com in the US are interesting ways for lending and borrowing money. This is often described as “cutting out the middle man” but obviously this is just being a middleman that skims rather than grabs. Sometimes you directly loan money to an individual, sometimes the risk is spread for you. This risk spreading reminds me of Collateralized Debt Obligations; the source of much of the cheap credit now available and an accelerant of the recent crunch, also claimed to be a big factor in the supposed Great Moderation we are experiencing (along with supply chain innovations like Just In Time Inventorying). The web is obviously an enabler for this sort of idea and I think the market forces mean users are getting a better deal than they otherwise would. This happened in gambling with BetFair and SpreadFair (which is owned by Cantor Fitzgerald and run out of Canary Wharf, a very good friend of mine works there).

Markets are good (at least sometimes).

A more traditional way for people to access capital and services are non profit organisations like credit unions and friendly societies. I recently joined the Leeds City Credit Union and am pleased to say I got a loan off them at 9% APR to consolidate the credit card debt I still have from my time at university, debt free in 5 years (I am going to overpay and try and clear it in 3). You can access cheaper credit if your credit history is pristine, but my time in India at the beginning of the year after quitting teaching made mine a little tarnished and I do not begrudge them the small difference as all profits are given to members as dividends. They provide a much needed service to less well off people banks could not care less about and help them avoid horrendous door-to-door lenders like Provident. “The Provvy” absolutly disgust me; I got a letter through the door with a picture of a christmas tree and an offer of £500 for only £15 per week. This is for 56 weeks though, so you pay them £840, which is an APR of 183.2% which they are not shy (due obviously to regulation) about telling you on their site. My first instinct was to feel sympathy for people for whom this is the only option, but clearly it never is; go to the credit union or start saving in June for Christmas. I am back onto my standard rant about whether people are undereducated or wilfully careless about their own wellbeing in the long-term in favour of instantaneous gratification, which I hope should stop in adulthood. One shit year while you paid off your loan and one shit year while you saved would allow you to spend twice as much each year, to me that is a no-brainer.

Quite link heavy today, may save you some googling.

Posted by tom under Economics | 2 Comments »

Second Python User Group meeting

December 7th 2007

I gave a talk at the second python user group in leeds on Wednesday. It was called “Anatomy Of A Python Program – How Much Can You Do In 0.1 KLOC?”. It is based on Peter Norvigs Sudoku solver. I had been thinking about doing it for WYLUG, possibly as a second talk after an intro to python. The slides were the same, but instead of looking at cool features of python that make the code so concise we critiqued it a bit and spoke about the style and possible speedups. The slides for the talk is here, but as I did not add any notes, you would be better off just reading Norvigs article (though the Javascript slideshow is cool, press t to toggle views)

The slideshow was made using rst2s5 and I am amazed how well it works. Restructuredtext is from Pythons Docutils and is a simple markup language designed to be readable as plain text, see here for details. Below is part of the code for my presentation

Continue Reading »

Posted by tom under Python | No Comments »

Get Nexenta Now

December 4th 2007

I have blogged about Nexenta before, Solaris kernel with Ubuntu userland. It is great if you are familiar with Debian/Ubuntu and want to play with the features in the solaris kernel (DTrace and ZFS got me excited). I was complaining that the www.gnusolaris.org site was quiet and then saw www.nexenta.com , their commercial offering (looks neat, but I prefer free). Turns out there is some work going on for a full release of Nexenta (GnuSolaris is a cool name but both are registered trademarks apparently, and it should probably be called Gnu/SunOS anyhow), see the Launchpad page.

If you want to experiment, this is your best bet (the homepage only has alpha7 from ages ago on there). I think this is exciting stuff and so does the new Debian project leader .

Come on Nexenta, go 1.0.

Posted by tom under Nexenta & OpenSolaris | No Comments »

GNU PDF

December 3rd 2007

In the great tradition of minimising the barrior to only using free software the FSF have announced GNU PDF. This is a fully feartured PDF library for apps to view or create PDFs so you should see an Acrobat killer in your favourite distro sometime.

We use Acrobat in work and don’t get anything like our moneys worth, we basically use it to annotate PDFs that come back from translators and print to PDF. I have used PDFCreator for one of those tasks, but the other is more of a hurdle.

PDF is a pretty good open standard. I would be very glad to see a GPL3 library that fully implements all its features.

Posted by tom under linux | No Comments »

RubyQuiz 148 – Postfix to Infix

December 1st 2007

I have been meaning for some time to tackle the RubyQuiz problems in Python.

The one from yesterday (#148) is quite interesting, taking postfix notated expressions and returning an infix version.

For example
2 3 5 + * -> 2 * (3 + 5)

I spoilt it a bit by reading Reverse Polish Notation on Wikipedia, which gave away how to evaluate the postfix expressions.

Here is my python code to evaluate postfix expressions
Continue Reading »

Posted by tom under Python & RubyQuiz | 1 Comment »