Saturday, 29 December 2012

New Year, New Sir...

The new years honours list came out yesterday, for those of you now aware the honours list is drawn up of people who have contributed to the fabric of society, either through academia, deeds or experience shared with all, my own Aunt was appointed to the list as a Member of the British Empire (MBE) for services to her community.

I've always held the tradition, and I call it a tradition because there is no empire any longer, in high regard not because of it representing anything in particular but that  it represents an accolade to the, most part, worthy.

Sometimes items on the list however are contentious, such as Cherie Blair being made a CBE for her work on "Womens Issues"... as far as I can tell she's married to a war criminal, so she shouldn't be on there.  Anthony her husband was the first prime minister to leave office and not be automatically appointed a KBE for these very contentious results of his decisions in office and his successor Gordon Brown was the second to leave office and not be given a KBE gratis as well!

But that's politics for you, a dark and murky world, and so its to a second dark and murky world we turn, SECRETS.

The work during the war at Bletchley Park spark my imagination whenever I hear tell of them, indeed only last week I read a booklet by Tony Sale about his work with Colossus.  However, I also saw the documentary on the BBC last year about the work of one Captain Roberts, forming his part of the Testury breaking the much more complex (than the Enigma, of Robert Harris book infamy) codes of the high command.

The work Captain Roberts and others carried out was so secret and those brave, brilliant, people kept their secret so long it completely skewed the history of early programmable electronic computing such that even now people don't believe we British were there first.

But Captain Roberts makes his mark and finally at the age of 92 he has been awarded the MBE in the honours list, a worthy honour, however, given its grave importance, its secrecy and the fact that he is the last surviving member of the Testury perhaps he should receive a slightly higher honour?  Others on the team received no honour, no recognition, indeed members of the same team died with no recognition, whilst others received only recognition for work after the war, such as William Tutte who was made a Fellow of the Royal Society.

Perhaps Captain Roberts deserved something higher, in my opinion he certainly does.  But quite what would be thanks enough for him and everyone who worked at Bletchley I could not say, behind my own grand fathers (one in the Infantry whom guarded Rudolf Hess, fought on D-Day at Normandy and across France, the other whom served on HMS Belfast from 1942 until long after the war) the men and women working on code breaking were, and remain, the highest heroes to me.


Thursday, 27 December 2012

Guinea Pig

Our last guinea pig just passed away, she was a lovely one, she loved being picked up and fussed, she'd chirp and sing when stroked on her neck, and would come when called with a noise I make through my teeth like a whistle but with no whi...

On Christmas Day she was proud as punch to get the sprout peelings, one of her favourite treats, and she had new hay and feed too which she tucked into.  On boxing day she had some chopped lettuce as an extra treat giving squeaks of delight and carrying pieces of lettuce around happily.

But when we got in from out evening walk with the dogs I went to check her and she was acting strangely, it seemed she had had a stroke.  One side very limp and she seemed confused, brought her in and she had a cuddle and we decided she'd come in, so I sorted her inside cage out, lined it got her blanket and things as well as a new hollowed box, but she didn't seem to want to stay in the box and struggled out into the hay, rolling and lolling.

Over the evening she got worse and by midnight she was not walking, she had a cuddle with me, and even though her breathing was laboured she chirped and tried to sing as a fussed her.

She passed away between 1 and 2 this morning.  And I'm not too proud to say I'm gutted, she was lovely.

Monday, 24 December 2012

Nerd Porn

http://www.ebay.co.uk/itm/VT-100-Terminal-Emulator-Cartrige-Atari-ST-STE-New-Box-/130823670482?pt=US_Vintage_Computers_Mainframes&hash=item1e75b2cad2

I wish I had this for xmas... But I don[t know why... I think I'd try it and then just leave it on a shelf, but I would have it.

HTML5 SSE

AS of about 4pm this afternoon I knew nothing about HTML5 specific code, nor the SSE (Server Sent Events) mechanisms.  I was blissfully living in the past where you had to do client pull to get data onto a browser.

But at 4pm, I started looking for a piece of code, the reason I was looking at this code was work... Remember that project I mentioned I had delivered, well that project was to convey some data from a source machine to a target over TCP/IP, the conduit being a Raspberry Pi, but the target machine was going to be a database, from whence there was to be a website doing alerts straight onto the screen...

This I was all shown before I left work, this was a big deal, my project had taken its time to arrive, this other chap with the web stuff had started before me and was delivering a demo of these alerts on screen from my newly finished feed... He had made a big whoo-haaa about how much work he had done for this... Big deal, the manager was wowing it up and lapping  up the progress.

So, this peaked my interest, so I wanted to see how from basically a web server I could get an alert onto a screen from such a feed... so... Imagining I had the same feed, to a database and then a website... I wanted to see a value go into the database and go out onto the screen...

I had imagined needing some javascript loop on the client to make it refresh some iframe or load values into hidden elements and then transpose them up the DOM into some visual controls.

But, actually... All I needed was SSE, and I had this working, showing me an alert (at least in the javascript console) in about 10 minutes.

<HTML>
<HEAD>
<SCRIPT language="javascript">
var source = null;

function LoadPage ()
{
    source = new EventSource('update.php');
    source.addEventListener ("message", Tick, false);
}

function Tick (event)
{
    console.log (event.data);
}
</SCRIPT>
</HEAD>
<BODY onload="LoadPage()">
</BODY>
</HTML>

Right, so this page opens something in HTML5 an event source and on each time the server pushes an event of the type "message" the "Tick" function is called, and the "event.data" is the string of raw information from the server.  So I want to create this "update.php" page which will send the event:

<?php
header("Content-Type: text/event-stream\n\n");
header("Cache-Control: no-cache");

echo "data: " . "HelloWorld" . PHP_EOL;
echo PHP_EOL;

do_flush();
flush();
?>

And this is "update.php", you see we manipulate the header returns to we're streaming events back, and then we send one event the "data:" line is the event with the string "HelloWorld", but we could stream json, or XML or whatever we like there and our "Tick" function on the web page will handle it.

What the browser (at least what Chrome) then does is it'll poll around again all on its own and you get this PHP page reloaded after 3 seconds, when the PHP page loads, with this code example in the JavaScript console (opened with F12 in Chrome) you see it log "HelloWorld", and then count following events of that type.

I did this in about 10 minutes, and that included copying the examples from another website... I can see great potential for this for the project at work, I can see a dozen or more messages I already transmit being hoisted out of the target server and streamed to a browser with a HTML5 canvas displaying a live read out of the source machine status, and I can see that being a real killer application for the project.

But you know what, the guy doing it has had months to work on this, and he's only just got this eventing stream thing working, something that took me about 10 minutes has taken him days, if not weeks, of his project.  Either he's shirking his time, or he's simply not doing the work.

Sunday, 23 December 2012

Strange Nocturnal Activity

So, this afternoon when the wife was popping out to work, and I was out helping her clear some stuff out the back of one of our cars the neighbour, whom has ignored us for like two months and gotten himself into bed with the local knob neighbour says to the mrs... "Someone's broken into me garage".

I couldn't give a toss about this, like I've said before I've put my neck out helping people around her and had myself verbally abused in the street, so this numb wit can get on with his own shit.

But, interestingly, we leave our gates out the back open, there's tables, metal poles, cages, bike and two cars on our property, sometimes the wife even leaves our car windows open.  We've not seen any problems, nothing missing no issues...

Yet this guy reckons someone has targeted his locked, secure garage?

They could walk through a gate, and have a whole plethora of power tools off of our back, but someone has purposefully gone into his difficult to access garage.

I've purposefully not asked what's missing, if anything, because I don't want to know.  If I don't know and someone asks I can't get accused, that's how I'm sitting on this one.

However, one has to look at this more pragmatically, he's in with the local toss pot, an out of work wanker who's already been discussing doing drug deals out on his rear garden... So, this chat with the garage... mentions to this wanker "I've got X in the garage", wanker waits and boom takes it... Its, pretty simple to see...

There is no crime around here, there are no louts, there are no kids, there are perhaps a few poachers, because its to rural and the nights have been so cold, people don't purposefully come here to commit crime, if they've committed a crime there already here... And I reckon its the wanker, there's no bones about it.  I've already seen him casing  up properties, seen him stopping to talk to random people, and its that common knack with people that's gotten him into everyone's good books, but really, he's casing them up.

But I'm not going to point this out, let them suffer him, whilst I protect my own.

Saturday, 22 December 2012

Preaching... Software

When I talk about preaching, and I'm afraid you'll have to forgive me out there in the world, I think about people standing in a pulpit telling other people to do something (be that believe in a god, follow some ethos or buy a certain brand of snake oil) which is not particularly in their best interest.

In software I think there are many source of miss-information, which try to guide but result in causing harm, I'm sure  many of my own posts are of this exact bent, but at least I warn you I'm trying to meddle (its in the very name of my blog) and I do also warn I'm a bit of a ranter...

But, the particular preaching I'm going to cast down today is the kind in print, and by supposedly high standing persons in C++ circles, I'm going to talk about a book I really hate... C++ Coding Standards by Herb Sutter & Andrei Alexandrescu.

I really don't like this book, I say as much when I reviewed it on the Amazon site, but it seems I am in a minority.  Many people love and dote on this book, they take its lessons to heart, and there are a few good lessons in there, but the more I force myself to read the book the more negative items I find within.

Not least the book itself does not follow its own preaching, how many ministers have we caught taking a tipple themselves after advising others to avoid the bottle?... Well, this book is that exact bloody thing, here's a good example...

"Don't use Macro's"

"Define your own Assert Macro"...

This is, so annoying... Then the assert Macro section itself... Page 130-131 of this damn book... they given an example, and I like to think in a book then the author thinks to give an example they give a good and poignant example.  But they don't... Look at this:

"For example, your whole design might rely on every Employee having a nonzero id_."

Right, so a none zero value to a variable, and they carry on to say:

"you can assert (id_ != 0) inside the implementation of Employee wherever you need to make sure an Employee is sane:

unsigned int Employee::GetID() {
    assert ( id_ != 0 && "Employee ID is invalid (must be nonzero)" );
    return id_;
}"

Right, people read this, and they think, yes... Yes I can do this... But you know what, its utter rubbish, this book is about C++, we can all go look at the C++ type and there's a much easier way to assert that the id_ here has a positive only value, and not only that but they do it!!.... Just the value a bloody unsigned.  Then it can't ever be a negative, its unsigned by definition that means 0 and above!  Gah, here's how I'd do it too...

class Employee
{
      private:
              unsigned int id_;
      public:
              const unsigned int GetID() { return id_; }
};

And my code is a lot better, for example, I can choose to make the value _id public, as the type enforces the usage for us, we can also make our return type constant, as the ID of am employee might very well stay the same so we can track them down.

And this code of mine is not just created off the top of my head on a whim (it was, but read on) no, I was guided by reading a much better primer into better code by Scott Meyer, yet it seems more people I run into put more stock into Herb & Andrei's stuff than Scott's, and I write this here post to put that to rights.

Go read Scott Meyer's books for a better insight into why I gave my counter example the way I did.

Thursday, 20 December 2012

When I were a lad...

As I sat this afternoon waiting for a compile to finish, a really long compile, I was struck by something, the complexity, number of libraries, patterns, algorithms and tools I use to write a program for the PC are far more in depth and wide ranging than I ever imagined whilst training as a programmer.

During my A-Level years, when I first cut my teeth on PC programming - creating programs in Turbo Pascal 7.0, from Borland, and later retro porting them back to Personal Pascal on my Atari ST (because I didn't own a PC and wanted to continue programming), then things were very simple.

I had some memory, usually around 500,000 characters tops, split into - I think from memory the the excellent Borland compiler output/progress - around 34,000 lines top...

This was a big program back then for me, it was a stock control program, emulating the features of just such a program I'd seen being used on a Coop POS Machine and wanted to ape in an effort to make some money.  The program never shipped, it never sold, it was finished and I printed it out and it became part of my project for my A-Level the following year.  But it was a whole program, debugged pretty well, with a DOS based 80x40 character display (so I pretty much wrote my own ncurses before there was an ncurses) and I could supply it to support a serial port driven barcode scanner, or a parallel port scanner and parallel port printer - though no machines I could find ever had two parallel ports for testing this.

I presented this program to two potential customers, small local mini-markets but they just shrugged at the cost of a whole PC just to be a til, "We have perfectly working tils and I can add up on a calculator" was the general feel.  So, my software never shipped, despite being just £100.  Where a commercial scale stock in/out/POS system was in the 10's of £1000's at the time.

And all this system was a mere 34KLOC.

When I went to Uni, in the first year on the of the modules was the history of computing, they should really have made that module be "The History of American Computing" because it took no stock of the input of the Poles pre 1939, nor Britain through the second world war, nor the machines from Manchester and for Lyons post war.  It just lectured on about PDP machines, DEC, IBM.   We were a generation of programmers in the embers of the 1990's still being brought up to think about BIG IRON.

To think about programming for a machine which is going to support hundreds of users, time-sharing, indeed, for a time I worked with IBM machines running AS/400 and then I saw a seed change other large scale servers were well spec'd PC's (I remember the first Pentium III I saw was actually a Compaq machine put into a 4u server wrack and used to run a custom cut of SCO Unix) and these well spec'd machines became the lead for enterprise serving of data.

I worked at the turn of the millennium on, what was then thought to be a hot topic, web-servers hosting application platforms.  Things like IBM Websphere, Apache TomCat and Jakarta.  Creating applications melted from being very specific tuned code, efficient, small, effective, to Java...

IDE's went from being text editors and technical manuals to being code completion driven, supportive environments, programming became easier.  The Script Kiddy was born around this time out there in the world and as a qualified Software Engineer I saw a wave of kids out of college whom had not learned to program Pascal, or even Java, they'd learned to throw together VBA inside Access or Excel, and they were being taken on as Java programmers and not one of them had any idea about proper memory management.

And I have to admit, at the time I fell into the web if lies, I relies on the JVM.  I moved back and forth in different web based programming jobs, working for Gas Companies, not delivering very much for another company doing metering devices before being laid off, and then I did consultancy work for people wanting web sites.

Lucky for me, the .com boom went bust and I had to get a proper job, and that job was C++.  But I was out of practice, and some of the software I created at that time was pretty terrible.  We're taking the time in C++ where there were no libraries to help, no STD, no boost... You were on your own, you want a linked list, well you better fucking write on son.

But, C++ like me, like the PC hardware I write for and use has matured.  I'm sitting now with oodles and oodles of horse power in my machines, this laptop alone has 8 cores and 8 gb of RAM before we even look at the massive nVidia graphics card within its bowels.

And so I find my self reminded "with great power, comes great responsibility" for I'm trying my damnedest to create really good code.  Thread safe, memory leak free, timely and working code, my chosen medium for this is C++.  And I'm proud to have delivered early (yes a whole 3 days early, but early none the less) my latest and first official C++ project in about 5 years.

Its a completely C++11 compliant project, using elements of the STD and boost, and I'm quite proud to say its a nice piece of software, one I'd be happy to hang my hat on.

However, C++ is not the main focus of my employer, this is good and bad, good because in being the only person working in C++ and the only person working on this project I was able to inject my own ideals into the mix, I applied my own work ethic, my own design and my own coding style.  I've been big on a C++ coding style for a while and elements of it have worked so well they've moved into the other languages I use.

This whole C++ project by the way had code totalling (written by me) about 224,000 lines of code.  It uses around 5 major parts of the boost libraries, not to mention linking about many linux libraries, and it uses a plethora of parts of the STD.  It compiles on my slowest machine in around 30 seconds, it compiles on the target hardware my employer owns in about 6 minutes - yes I have nice kit, but they've not bought decent kit in about ten years.

And whilst sat in one of these 6 minute stupors, I got looking at the code files, one of the class support files, this is a large header only implementation of around 100 functions - which I port around rather than libraries as it compiles on Linux, Windows OSX and Android easily - this file alone was over 34.2 kilobytes.  My first computer ever a Commodore 16, only had 16 kilobytes of data.  The first machine I ever programmed could not hold this one code file completely in memory at any one time.

This was in sane.

This thought immediately grounded me, back to thoughts of writing for BIG IRON.  Looking at the code thinking, has any bloat got in there, have I fooled myself into thinking the code base if decent?  Am I not seeing the elephant in the room that there is some fault.

And I realised, this was the teaching I had had all those years ago, from programming myself on the Commodore, I'd then moved to the ST and then to the PC and I learned to program by always taking the work I was doing now back a layer, I did commodore basic on the C16, then Basic on the ST, then Pascal on the PC and then back Pascal on the ST... its a chain.

So now, with a leap I have to take my latest C++ and look back to that first time I was learning C, to evaluate the code not for the machines of today, but to make it run that little bit better over all now as if it were on those limited machines I first worked on.

My first PC was an 80486SX2-50Mhz with 4MB of RAM, the SX chip could not divide or multiply on the chip, it did it as a software shim as additions and subtractions, I didn't know this at the time, I just organically looked for the best solution to a problem.  Like for example checking for a remainder to see if something is odd or even....

int i = 245;
int j = i % 2;
bool isEven = (j == 0);

On a processor able to work out multiplications, with a math co-processor, this is the fastest code, however on an SX it turned out, back then with the shitty compiler I had that actually to remove any digits above the last and examining it were faster...

I can articulate this now, I understand why I did it, I'm not intimidated by not knowing that there was a better way.  But back on a day in 1996 I was very afraid of not knowing why, or how.

Now-a-days you'd just pick up the internet connection and look up such a piece of code and see tens, perhaps dozens of suggestions of how to do that task, but not-one would teach that sometimes you have to write for the bare metal.  Sometimes you have to optimise for the task at hand, for a specific job.

Languages like Java, C#, python and others running in virtual machines/interpreters don't teach you to bend your machine to its best ability, they teach you, or nail you over the back of the head with it time and again, to write code to best fit their runtime, their rules and their reasons.

So, my employer?... Their main effort is C#, their main product is C#.  Its slow, its clunky and its really pushed the hardware to its limit...

If the same system were worked in C++ the hardware being asked to run it might live another 5, maybe even 7 or 8 years.  I told them this a year ago, I've now delivered a highly specialised C++ custom tailored solution just for one set of hardware and unlike my C# projects - which spend a protracted amount of time debugging to suit the C# virtual machine rather than the actual machine we're running upon (which is a constant machine, not changing spec) - which seem to take up the maximum amount of time and even then want more time to get themselves done.

Why am I writing all this down?... 

To be honest, I don't know I just had all this junk on my mind, it has no point, no purpose, if you read it sorry... but sometimes I just need to rant.