Calling C++ Classes from Python, with ctypes…

I recently found myself needing to call a C++ class from within Python. I didn’t want to call a separate process (as I had previously when using Thrift – see Using Apache Thrift for Python & C++); but rather to call a C++ library directly.

Before I go on I should say that there are a lot of different ways to do this is Python – and I’ve picked one that worked for me. Other techniques are available – and opinion seems quite divided as to which (if any) technique is ‘best’.

To start with we have our C++ class, written in the usual way.

Continue reading “Calling C++ Classes from Python, with ctypes…”

Using Apache Thrift for Python & C++

Apache Thrift is a software framework for cross-language: providing what is essentially a remote-procedure call interface to enable a client application to access services from a service — which can be written in the-same, or another language. Thrift supports all of the major languages that you’d expect to use: including Python, C++, Java, JavaScript / Node.js, and Ruby.

Unfortunately, whilst there are quite a few tutorials on how to use Thrift: some of them concentrate on explaining how Thrift is working behind the scenes (which is important, of course): rather than on how to use it. There also aren’t that many that concentrate on using C++. So having spent some time working through some of the tutorials (and the book Learning Apache Thrift), I though I’d have a go at writing something of a practical guide. I’m quite deliberately not going to focus on how Thrift works: if you want that, let me suggest the Apache Thrift – Quick Tutorial. I’m also going to assume that you have Thrift installed on your computer already (again, there are lots of sets of instruction on how to do this — Google will be your friend), and that you’re using a Linux or MacOS computer. You should be able to follow-along with most of this if you’re using Windows: but there will be a few differences, especially when it comes to compiling C++ files.

Continue reading “Using Apache Thrift for Python & C++”

RegEx Golf

RegEx Golf
Inspired by the famous XKCD cartoon that started it and by Google’s Peter Norvig over on O’Reilly.com I decided to play some RegEx Golf myself this Easter…

If you’re not familiar with the game – the idea is to write the shortest regular expression possible that will select every element of a list, without selecting any elements from a second list. But what are regular expressions, you ask? Well, they’re a special sequence of characters that specify a particular textual patter – so you can use the appropriate regular expression when programming to automatically extract specific text from a list, file, or other text. There are some great tutorials on the web if you want to learn regular expressions (and you really should – because they’re great) – for example regexone.com

I didn’t want to use lists of Presidents of the United States (as that had been done) – so I decided to have a go at the age-old challenge: animal, mineral, or vegetable

Continue reading “RegEx Golf”

Google Chromebook

Google & Samsung have announced the details of the first generation of Chromebooks – thin-client laptops running Google’s Chrome OS & reliant on a web connection for all of their capabilities. But can they succeed in a competitive market-place?

The Chromebook is a nice idea. Thin-client (cloud) computing is becoming (if not yet the norm) common-place in many corporate data centres; but (to date) it’s not really been a viable option for the home-user. Chrome OS changes that – by putting a cloud-based OS (and thin-client laptop) into the hands of home users.

The question is – are home user’s ready for cloud computing?

Google claim that the Chromebook can still be used without a constant network connection, because off-line versions of Google Docs, GMail, and Google Calendars. This will redress one of the major concerns – especially in the UK where the prevalence of wifi isn’t nearly as common as it could be. Even a 3G-based Chromebook won’t guarantee a network connection – especially when travelling by train.

The other problem with cloud-computing, is the question of whether people trust the cloud… Web-based email has been around for a long-time now, and (in fact) lots of people use webmail as their primary means of reading their email. This is the first example of cloud-services that most people will have experienced. We trust the internet with our email – since it’s intended to travel over the internet anyway… But do we trust the cloud – be it google or Amazon, or anyone else for that matter with our data? Our spreadsheets? Our banking records? Our letters?

And that’s a real question. It’s not at all clear if people do… Yes there are quite a few advantages to using a cloud (your data is accessible from multiple locations, it’s backed up, and it’s not dependant on any specific user’s hardware); but are these outweighed by the dangers  – and (perhaps more importantly) the perception of danger that comes from not owning one’s own data?

And then there’s the price…

At £350 for the wifi only Samsung Chromebook, these machines aren’t cheap. In fact, apart from the battery-life (claimed to be around 8-hours) they stack up pretty unfavourably when compared to cheap laptops. £350 will buy you a Windows 7 laptop, with hundreds of Gb of local storage; and the ability to run real applications.

Alternatively it’ll go a long way towards buying an iPad or an Android tablet; and it’ll be these, I think, that’ll be the main competitors for the Chromebooks (at least as far as home users go). Given the choice between a portable tablet with all-day battery life, and a laptop – with less capability & (arguably worse usability for many tasks) – are people going to choose the Chromebook?

The US prices for the Chromebooks translate rather nearer to £250 – and at that price (less than £300) the Chromebook becomes a very different prospect; but at £350, its a far harder choice.

Now none of this means that Chromebooks won’t be successful. For business users (especially small to medium sized businesses) already using Google Apps, Chromebook can be a great platform; but for home users – where there’s so much competition – I think it’s going to come down to the price…

Ed Roberts (1941-2010)

I was saddened today to hear (albeit rather belatedly) about the death of the some-time pioneering micro-computer engineer Ed Robterts.  Roberts died on 1st April 2010: aged just 68.

Roberts’ creation, the Altair 8800 was, arguably, the most important personal micro-computer ever made.  It was the machine that made the dream of a personal computer viable…  Yes, of course, the Apple ][ was the machine that brought “personal” computing to the masses – but there wouldn’t have been the Apple ][, had it not been for the market that the Altair created.

Roberts was a true pioneer – leaving behind the industry he created, long before it became the billion-dollar industry it would become; and instead taking up the white-coat of a doctor of medicine…

RIP