Tuesday 6 July 2010

Spam Leaking In

Lately, this blog has been targeted by spammers. To be precise, Chinese speaking spammers with Google/Blogger accounts. It appears that somewhere in China (or Singapore?), individuals are creating Google/Blogger accounts for the express purpose of being able to put spam into comments on blogs like mine that require users to have such an account in order to comment.

I know this is not Google/Blogger's fault. But it would be nice to have an option to not just reject a comment, but also flag the commenter as a suspicious account for Blogger to investigate. Maybe one day.

In the meanwhile, to my spamming 'friends', I say: STFUAPO!

Addendum: in light of the fact that spam comments have continued, and I'm tired of seeing them appear in my inbox for moderation, I've limited comments to blog members (i.e. me.) Anyone wanting to comment for now will need to email me instead.

Friday 11 June 2010

Game: Set and Match

I love Python. Have I mentioned that before?

I learned programming first as a student teaching myself BASIC on an Apple ][. When I got to Uni, I was initiated into the ways of FORTRAN and Pascal. I got to grips with C, and later as a teacher, I became familiar with Javascript and PHP. I've even spent some time tackling Java and C++.

But is wasn't until I started seriously looking at Python as a replacement for Pascal in my teaching programs that I started to appreciate the differences between various languages and how this affects the way I program.

And I find programming in Python to be a real joy. I find it flexible and easy to read, but replete with functionality. As a language to teach to students, it fills my requirements beautifully.

I'm sure that others will prefer different languages (and I have spent a little time on Ruby, and I can see its appeal), and for various reasons. I'm well aware that performance-wise, there are many languages that execute faster than Python. I came across an example of this only the other day. Andrew Choi is a computer scientist, who is also a jazz enthusiast, like me. He's written programs to generate jazz accompaniment in MIDI. One program was originally written in Python, but then Andrew rewrote his program in OCaml and achieved a massive increase in performance.

So would I consider switching to OCaml? Have you looked at OCaml?? OCaml is what you get when you let a programming language be designed by a committee.1 I'll stick to Python.

An example of what I find so nice about Python: I posed a problem to my students the other day about looping over a list and clearing out duplicate elements so that only a single instance of any particular element remained. The students came up with a couple of ways of doing this, but their approaches, as you might expect, involved looping over the lists. But Python (typically) provides more than one way to tackle this problem.

Consider a list with duplicate elements:

>>> L = [1, 2, 3, 2, 3, 2, 2, 3, 1, 5]

Python lets you remove the dupes from this list using a single line of code:

>>> L = list(set(L))

That's it! Don't believe me? Try it for yourself.

I hadn't really looked at Python's set type before, I think mainly because the resources I've relied on to learn about (and teach) Python have made little mention of it, which is a bit odd, given how useful set operations are. (Though that may be the mathematician/database developer sides of me coming out.)

Need to match up the common elements in two lists (call them A and B)? The answer is as simple as this:

>>> common = list(set(A) & set(B))

How simple is that!

Did I mention that I love Python?



1. With apologies to Mark Twain.