Losing it

Europe map according to BBC Weather Foreacst S...
Europe map according to BBC Weather Foreacst Service (Photo credit: Cea.)

This has not been a great week for the “Yes” campaign in the forthcoming Scottish independence referendum.

Rational folk might put the reason why the campaign has hit trouble is because it has tried to fudge some pretty basic economic questions about the implications of Scottish independence and has been caught out doing so.

But, it seems, some leading supporters of Scottish independence have discovered the real reason – the BBC weather forecast.

Bella Caledonia, quite a big blog in Scotland, writes this:

the BBC constantly exposes us to a more blatant misrepresentation. And the insidious nature of this visual deception is totally inappropriate in the lead-up to the independence referendum.

In fact the BBC’s weather map is based on the image of the UK as seen from geostationary weather satellites. It accurately reflects the view from space and with the Atlantic dominating the weather we get in these islands, satellite imaging, and its accurate projection is absolutely central to good forecasting.

But Bella Caledonia know better:

I’ve done a bit of 3D graphics modelling over the years, and could see that the underlying issue wasn’t obvious to those debating the perspective. I wrote to the Scotsman pointing out that the BBC was being disingenuous. When you model a virtual 3D scene you have the freedom to put the camera wherever you like, and also to choose the virtual lens. Looking down from a great height with a standard lens would result in a faithful representation of the land masses. But what the BBC’s modellers had done was to use a wide angle lens and move the virtual camera position much closer to the south of England. This has the effect of making the nearer land masses bulge larger, and those further north to taper off rapidly in perspective.

 But, of course, this is not a “virual 3D scene” at all and the idea that you can “put the camera wherever you like” misses the point: people would surely prefer more accurate weather forecasts based on this spherical projection to less accurate ones which are on Mercator’s Projection.
Enhanced by Zemanta

Patient, heal thyself: what to do after you leave the gym?

English: Frank Sinatra at Girl's Town Ball in ...
English: Frank Sinatra at Girl’s Town Ball in Florida, March 12, 1960 (Photo credit: Wikipedia)

Not that long ago I watched a DVD of The Detective, a 1968 police procedural.

The film is interesting for a number of reasons including:

  • Despite being very successful at the time and with a very strong cast (led by Frank Sinatra but including Lee Remick, Jacqueline Bisset, Jack Klugman and an up-and-coming Robert Duvall) it is pretty much forgotten today;
  • It is, in a sense, the very first “Die Hard” movie as the character played by Sinatra is the same man (in the books on which the films are based) later called “John McClane“;
  • It, for its time, took some quite radical stances on race, sex and sexual mores;
  • And it has a not entirely hostile portrayal of gay men.

It’s the last point I am interested in here because we are shown gay men in what must have, at the time (given the way it is introduced) – seemed the campest of camp environments – the gym.

So, not that much more than 40 years ago we can assume that the gym was the last place that any hot-blooded heterosexual male would want to be seen. Pumping iron was definitely not for the macho man.

An yet it is plain that where the gay men led, the rest – men and women alike – have come to follow.

The revolution in attitudes is fundamental and is surely one that has contributed positively to extended expectations of active life in developed countries (a point worth remembering when reading more doom-and-gloom-obseity-epidemic stories.)

It is also interesting how poor the state and socialised medicine has been at understanding the profundity of this change. Britain’s National Health Service is long on exhortation to take more exercise but practical help paid for out of its £100 billion plus budget to facilitate such behaviour seems thin on the ground. And before someone says moral hazard – surely the whole founding-principle of a free-at-use health system is that we accept this risk of personal corruption as the price to pay for pooled risk?

I do not know what the best way for the state to facilitate such self-care is, but I do think that the current approach: to tell us it is a great idea but do nothing much practical after we leave school at 16, 17 or 18 (and after PE lessons there that most children hate) probably is not the most efficient way of behaving.

And I also think that the self-medication of the treadmill is only the beginning. More, lots more, is likely to happen in the next 46 years.

I am saying this after I have been reading about “grinders” (people who medically modify their own bodies) and “DIYBio” (hobbyist and similar genetic engineering). Both were new terms to me, but they are surely going to be widely discussed and soon – not least because the regulatory regime is plainly a bit of a mess.

Today both these (related) areas have a feel of the wild west, and certainly the “DIYBio” community are infected by a strong streak of anti-regulation libertarian (dis/u)topianism that verges on “X Files” mad-scientist chilling.

But even if the regulatory environment is strengthened or at least regulated, there can be no doubt that such forms of self-medication will – like the gym – become increasingly mainstream in years to come. After all we can hardly suggest it is a good idea to start jailing people for taking medicines they have manufactured to match their own genome (though I dare say someone will try).

(To read more you can do what I did – download O’Reilly’s BioCoder magazine.)

Enhanced by Zemanta

Wanted: a better C++ book

I first taught myself C++ back in 1993 – using Borland’s Turbo C++: a great product I had lots of fun with.

Photo of Bjarne Stroustrup, creator of the pro...
Photo of Bjarne Stroustrup, creator of the programming language C++. (Photo credit: Wikipedia)

After that I moved on Microsoft’s Visual C++ (it was their unilateral cancellation of my subscription that marked a key stage in my disillusionment with Redmond).

In those days C++ was simple – people talked about templates and namespaces but nobody actually used them.

So, when in 2009/10 when I was being taught C++ at Birkbeck I didn’t really pay enough attention – I thought I knew the language but I didn’t.

After that course was over I made a real effort to teach myself C++ properly and wrote some not too bad code. But then Groovy came along and nobody was much interested in my VMUFAT file driver for the Linux kernel and so both C++ and C got neglected.

Now C is like bike riding – if you haven’t done it for a while you are a bit unsteady at first but soon get the hang of it. But C++ is different and now I back to writing in both idioms I miss having a good C++ guide book.

I do have C++: The Complete Reference (4th Edition) but, in my view, this is one of the worst computer books ever written – as it simply reads like a book about C with some bolt-ons.

I also have Computing Concepts with C++ Essentials: but it’s a book about how to program, not a good reference.

What I want is something that tells me how to do things and use things without either drowning me in formal references or treating me like a newcomer.

What is the best option – is The C++ Programming Language still the best? I used to have a copy of that from 20 years ago (perhaps I still have it somewhere in the house) and it was quite good but obviously that edition has long since been superseded.

Any recommendations gratefully received in the comments.

Enhanced by Zemanta

Slogging it out

Wrote around 100 lines of C++ tonight, but don’t feel I am making much progress in building my project: not least because many of those lines were to replace something I’d written earlier in the week.

To make matters worse I keep looking at older code I’ve written and thinking how beautiful it is, rather than the stuff I am just slapping into Vim right now. I tell myself I probably thought the same then too, but right now none of this feels like fun.

The mess is all over on Github (look me up as mcmenaminadrian).

Modern standards of grammar do not make you kill yourself

The great Neville Gwynne make it up as you go along road show rumbles on…

Stroppy Editor

Last night I went to Kings Place to see David Marsh and Nevile Gwynne debate grammar. They both spoke with a certain dry wit, even if they both lost focus at times. I’d read a fair bit of their stuff before, so I didn’t find the evening hugely informative, but it was interesting in any case.

Here I’ll just look at one thing Gwynne said.

He is firmly of the view that everything went wrong in the 1960s, when the teaching of grammar was abolished. This had catastrophic consequences for our language. “When I was eight or nine, everyone knew what a preposition was.” But no longer.

A regular part of his pitch is that good grammar (by his definition) is necessary for thinking, and thinking is necessary for deciding, and deciding is necessary for happiness and society and civilisation itself, all of which are now breaking down because we…

View original post 365 more words

Gay genes and the Daily Mail

Today it has been reported that scientists may have found a genetic link between predisposition to homosexuality and human genetics. I just want to put this here to remind people just how appalling some people’s attitudes to such stories are.

This is an extract from page 29 of the Daily Mail of 16 July 1993.

No further comment is necessary

Abortion hope after ‘gay genes’ findings

Jason Lewis


SCIENTISTS in America claim to have found the first definite evidence of a genetic link to homosexuality.

Researchers at the National Cancer Institute, near Washington DC, say their findings help prove that sexual orientation can be inherited.

Isolation of the genes means it could soon be possible to predict whether a baby will be gay and give the mother the option of an abortion.

Dean Hamer, principal author of the study published in the American journal Science, said the results do not prove gay men were compelled by their genes to be homosexual. But he said the research showed sexual orientation is powerfully influenced by genes inherited from their mother.

‘This is the strongest evidence to date that there is an important genetic component to sexual orientation,’ said Hamer.

Evidence of a gay gene was found by studying chromosomes in 40 pairs of homosexual brothers. Thirty-three were found to share the same pattern variation.

The findings are likely to cause a storm among radical gay and pro-life groups, as well as medical interest groups already concerned about the ethics of research on human genes.

A similar search for a genetic basis for homosexuality in females is now underway, Mr Hamer said.

This latest study strengthens the argument by the gay community that homosexuality is not a matter of choice, but of biological destiny.

George Neighbors Jr, of the Federation of Parents and Friends of Lesbians and Gays in Washington, said…


Enhanced by Zemanta

Computing for teachers….

Announcing Code Club Pro
Training for Teachers
As many of you already know, last Friday we launched our newest Code Club initiative: Code Club Pro – Computing for Teachers. That’s right… not only is it Valentine’s day today, it is also our one-week anniversary. See press articles here: GuardianTelegraph; and check out our new websitewww.codeclubpro.org.
What is it? 

In partnership with CAS and with the support of Google, Code Club Pro will deliver CPD training and resources to primary school teachers. We’d like our teachers to feel confident and excited about the new computing curriculum and computing in general.

Why are we doing it?


As the teachers out there know, the new computing curriculum comes into effect this September. That’s only 6 months away. Eeek! In our experience, many feel they have not had sufficient programming experience or training. The language is totally new and frankly, can be quite off-putting. And that’s on top of changes to the rest of the curriculum. A huge task, by any measure – thank goodness our teachers are up to the challenge! We want to help. It is key that the front-line implementers of the new curriculum and policy – the teachers – should be given the skills and support they need.


How do we feel?


We are excited. It’s a great move toward children thinking like engineers: solving problems, using logic, analysing processes and creating rather than just consuming technology. These skills can be used to enrich other subjects too, like Maths, Science and English. See tef’s blog post here.

It’s quite a big task though! There are approx 200,000 teachers in the UK and we want to help as many as we can. Luckily, Google and CAS have invested in our project, and we have you – our amazing volunteers. With great supporters behind us, we know we can achieve many things.


Happy one week CCP Anniversary all!

Sophie Deen
PM, Code Club Pro

PS: Code Club Pro are looking for an intern. We want someone very smart and are offering heaps of exposure, experience, fun and autonomy, plus the London living wage. Check out the ad here.

 If whilst reading this newsletter you felt a creeping sense of déjà vu, it’s probably because you already read my blog post last week…


(NB: I have no financial or other stake in this, I am merely a Code Club volunteer)

From two years to two hundred minutes

I rewrote my parsing code in C/C++ and a task that was likely to take two years in Groovy/Java while running 18 threads – on a multicore machine with a large amount of memory – (I am not exaggerating about the turnaround time, either) completed in not much more than three hours in a single thread on the same machine.

(The new code has a C main – but the bulk of the code is in C++ which is accessed through an extern “C” interface.)

#include <iostream>
#include <cstdio>
#include "redblack.hpp"

using namespace std;

//Copyright Adrian McMenamin 2014
//C wrap around C++ redblack tree code
//Licensed under GNU GPL verison 2
//or any later version at your discretion

class pageinst
 long instruction;
 pageinst* next;

 pageinst(long inst);
 long getinst(void);
 pageinst* getnext(void);
 void setnext(pageinst* newinst);

pageinst::pageinst(long inst)
 instruction = inst;
 next = NULL;

long pageinst::getinst(void)
 return instruction;

pageinst* pageinst::getnext(void)
 return next;

void pageinst::setnext(pageinst* newinst)
 next = newinst;

class pagechain
 friend ostream& operator<<(ostream& os, pagechain& pc);

 long page;
 pageinst* head;
 pageinst* tail;

 pagechain(long where);
 long getpage(void);
 bool operator==(pagechain&) const;
 bool operator<(pagechain&) const;
 pageinst* gethead(void);
 void sethead(pageinst* newhead);
 pageinst* gettail(void);
 void settail(pageinst* newtail);

ostream& operator<<(ostream& os, pagechain& pc)
 os << pc.page;
 return os;

long pagechain::getpage(void)
 return page;

bool pagechain::operator==(pagechain& pc) const
 return (page == pc.page);

bool pagechain::operator<(pagechain& pc) const
 return (page < pc.page);

pagechain::pagechain(long where)
 page = where;
 head = NULL;
 tail = NULL;

pageinst* pagechain::gethead(void)
 return head;

void pagechain::sethead(pageinst* newhead)
 pageinst* oldhead = gethead();
 head = newhead;
 if (oldhead)
 if (!gettail())
 tail = newhead;

pageinst* pagechain::gettail(void)
 return tail;

void pagechain::settail(pageinst* newtail)
 pageinst* oldtail = gettail();
 tail = newtail;
 if (oldtail)
 if (!gethead())
 head = newtail;

void killchain(pageinst* pi)
 if (pi == NULL)
 pageinst* next = pi->getnext();
 delete pi;

void killtree(redblacknode<pagechain>* node)
 if (node == NULL)

void writechain(pagechain* pc, FILE* fout)
 if (pc == NULL)
 fprintf(fout, "PAGE: %li ", pc->getpage());
 pageinst* pi = pc->gethead();
 while (pi) {
 fprintf(fout, ",%li", pi->getinst());
 pi = pi->getnext();
 fprintf(fout, "\n");

void writeoutpages(redblacknode<pagechain>* node, FILE* fout)
 if (node == NULL)
 writeoutpages(node->left, fout);
 writechain(&node->getvalue(), fout);
 writeoutpages(node->right, fout);

extern "C" {

void* createtree(void)
 redblacktree<redblacknode<pagechain> >* tree;
 tree = new redblacktree<redblacknode<pagechain> >();
 return static_cast<void*>(tree);

void removetree(void* tree)
 redblacktree<redblacknode >* rbtree;
 rbtree = (static_cast<redblacktree<redblacknode<pagechain> >* >(tree));
 delete rbtree;
 tree = NULL;

void* getroot(void* tree)
 redblacktree<redblacknode<pagechain> >* nodetree =
 static_cast<redblacktree<redblacknode<pagechain> >*>(tree);
 return static_cast<void*>(nodetree->root);

//if node for this page exists add to its tail
//if node for this page does not exist, create and add to tail
void insertinstruction(long pagenumber, long instruction,
 void* tree, void* root)
 redblacknode<pagechain> *rootnode, *pagenode, *dummynode;
 redblacktree<redblacknode<pagechain> >* nodetree;

 pagechain dummychain = pagechain(pagenumber);
 rootnode = static_cast<redblacknode<pagechain>*>(root);
 nodetree = static_cast<redblacktree<redblacknode<pagechain> >* >(tree);

dummynode = new redblacknode<pagechain>(dummychain);
 pagenode = nodetree->locatenode(dummynode, rootnode);
 pageinst* nextinstruction = new pageinst(instruction);

if (pagenode) {
 delete dummynode;
 } else {
 nodetree->insertnode(dummynode, rootnode);

void writeinorder(void* tree, FILE* fileout)
 redblacktree<redblacknode<pagechain> >* nodetree =
 static_cast<redblacktree<redblacknode<pagechain> >*>

 writeoutpages(nodetree->root, fileout);

} //end extern "C"

The old code used Groovy’s Map class to index a sparse array, the new code uses a red-black tree to index the same data. The speed up is not just because of the tree’s superior performance, but it surely has a lot to do with it.

I now have to decide whether to re-write the whole of the testing code in C/C++ … I think I am going to have to.

Enhanced by Zemanta

The joy of .CXX

I have a problem.

The rise of the C guru. (LOL =])
The rise of the C guru. (LOL =]) (Photo credit: Dzhus)

I need to parse 220GB of XML to find an OPT reference string (i.e. to profile the memory references of a running application to create a page replacement algorithm that will know which is the most efficient page replacement decision.)

I had one algorithm in mind for this and I wrote the Groovy code but it kept exhausting the memory pool of the VM (as it generated a lot of anonymous memory). Even whacking the VM up in size quite considerably didn’t seem to fix the problem.

So I used another algorithm – and it works. After a fashion. Because even with 18 threads running in parallel on the University of York’s big iron compute server I think it might take around two years to complete. And I don’t have two years.

So I need to find something better – something where I have much more control over the memory allocation code and where I can also be sure of performance.

C is the obvious answer. Or, in this case, C with an interface to some C++ code I wrote a few years ago to build a red-black tree.

The strange thing is that, despite Groovy’s claim that it removes the really tedious bits of code writing by doing away with boiler plate, this weekend I have found writing all that getter/setter code quite therapeutic: perhaps this is a programmer’s comfort blanket?

Enhanced by Zemanta