Tuesday, 7 May 2013

The Server is wonky...


I'm back at work, first day back from being so ill, and it is nice to see a computer and keyboard free and clear of clutter for me to get working with.  However, I've run into that ethereal problem... something one the network is not playing ball.

The something today is the main source control server, which whilst I was checking out started to kick me off... Midstream, three attempts later and frustration mounting I e-mail IT.  I've not talked to the general server bod, because last time I asked him about this exact problem - Monday before last - he fobbed me off with a load of Windows Server gibberish which didn't wash with my informed self.

But, being a good boy, and ex-IT minion I did the leg work for them I pinged the server, checked my connection, rebooted all virtual and physical machines and tried from another machine first.

Turns out the problems, all of them, are real, I can't connect to the main source control server, the main server bod was not aware of the problems and indeed I could not connect to the server.  The reason being, on the first day of the week IT let themselves install all the Microsoft hot-fixes and patches to the server... without letting anyone know.

And, this being a Microsoft server, of course it doesn't tell any of its users - *cough* customers! - what its doing, it just reboots with installs and that's the end of that.

So that was why I've sat with my thumb in the air waiting for something useful to happen for the past hour... IT policy, sometimes a ball-ache, sometimes a balls up.

Sunday, 5 May 2013

Coasting to a halt...

I have had a hell of a week, it started badly with a pressing feeling growing in my chest all last weekend, so much so that by Tuesday morning I had a boiling heavy feeling in my chest - which forced me to hassle my doc into seeing me last Tuesday afternoon and was promptly informed I was about an inch from major pneumonia in my left lung.

He gave me a shed load of drugs and I spent the next forty eight hours in agony, and let me tell you folks, it was agony, fluid in the lung made it so painful, and being the left lung I could not rest the weight of it pressing on my heart.  And if I lay flat the weight was on my spine, that was more agony.

A massive fever, which broke Friday morning around 4am has seen me slowly recover.  I even took a gentle walk this evening.  But I'm now awaiting the inevitable backlash of having used anti-biotics & pain killers... Basically I'm about a half day from shitting my arse out.

Apart from that I did do some coding, for work and for pleasure.

I took a look at the C++ tutorial from Linux Format - and then closed the magazine and sagely decided not to comment - as a professional programmer and C++ fan - could they have tried to present a more ugly disjointed unfavourable and plainly boring introduction to the language?... The chap writing it even commented there are no media libraries for the language... Dude, don't you know EVERY major game on nearly ever major platform has a beating heart written in C++ and has had since Half-Life!

I have also played a few rounds of War Thunder - and made a level in the Russian Tech tree - which cost a pretty penny to buy all the accompanying planes and upgrades.  But, they've still not fixes the earning ability, its all very well some commentators saying "you have to earn the cash for a new rank" and "it was too easy to earn cash before", but at a little under 3,000 cash for a mediocre game, 4,500 for a better game.  Its an utter ball ache - still - to gain over 100,000 just to buy a tier 7 plane, but then you get splashed for ammo wracks, robbed for putting the plane you just paid through the nose for into service and finally fucked over trying to earn anything with your first 10 free repair fly outs!

Tuesday, 30 April 2013

Derp that Programming!


I've just spent the best part of my morning setting up a developer on a project at work, this would go unmarked, except I remember setting the same developer up on the same project about three years ago, and they did produce a module for this project back then... Yet it seemed today that their head was empty...

And I mean, empty... this person, I was telling them to click on things and they were like looking down at their mouse... "A click eh, how..a...ah... Ah I see, the button thing, yes".

I was specific and pretty slow, "plug in the USB device and copy filders x y z off of it".... two hours later.... "have you copied those folders?"... "Ah, no, the USb device has not appeared in the computer list, I've took it out and put it back in again twice"...

I walk over, press F5 and voila, there it is... "Right, I'll get copying now"...

Now, this person is meant to work with me on a tight time scheduled project... I don't hold high hopes.

Monday, 29 April 2013

Don't Interface just Encapsulate!

One of the major projects at my place of work came into my sphere of influence recently, and importantly it came to me with no restrictions on what I could do with it.  Unfortunately, so far, all I've been doing is sorting out horrible implementation and code weirdness.  Now, I can't go into specifics, my employer would not thank me, however, I can and intend to document one of the major problems.

This is a problem born out of the project developer - the guy who sat down and thought it up then set his fingers to the keyboard - being out of date, you see this chap has never had a formal introduction to object orientated programming.  He has a semi-idea of the uses of OOP, but he's never really put it into decent practice.

I always knew this, speaking to him at times I with an OOP eye would see things one very clear way, a clarion thought of how the structure of the class hierarchy would, and perhaps should, layout.  However, I would get a dull eyes stare back, something like a dog being shown a card trick.  I've used that statement on this blog before so I won't continue, what I will do is given an example of what I found and removed from one of the most major critical systems.

The system forms a set of classes, each have to contain the same flags and values as the others so they're mutable, but each is a different class.  So, say you have a "Person" and then you have "Staff", "Drivers" and "Servants" derived from them.. You could easily see these as objects.

What I was not expecting was a very strange use of interfaces... So, enough talk, some code, and this is C# folks... I'm sorry!


public interface Person
    {
        string Name
        {
            get;
            set;
        }

        int Age
        {
            get;
            set;
        }
    }

Given this, you can now implement this interface in other classes, and those classes will be forced to use define those elements... Right.  So, this code:

public class Driver : Person
    {
    }


Fails, with the messages: "Error 1 'Driver' does not implement interface member 'Person.Name'" and "Error 2 'Driver' does not implement interface member 'Person.Age'"... And I can see what the chap who wrote this was thinking... It went down something like this... "GREAT, Now everyone trying to use my Person interface is forced to define Name and Age"... And that is what Interfaces are for, but that's not what these classes are used like, what they need is to encapsulate a name and age which are already defined.

In the interface above each and every class has to define the function, but that means there's a copy of the same code being written over and over and over, that's useful if you need those overrides to define different behaviour, but this person class, just like the class in the software I was working on, are used for the same thing each and every time.... This makes repeating the code over and over wasteful, and hard to maintain.

What should have been done is encapsulation, the base class should provide the functionality and then the derived classes just  have it, they inherit it, the base class encapsulates the common functionality and then the derived classes don't have to worry, you've written one set of code for the equivalent of this interface and instead of rewriting it you just put the inherit into your derived class...

class Person
{
     private string m_Name;
     public string Name { get; set; }

     private int m_Age;
     public int Age { get; set; }
}

class Driver : Person
{
}

So, I showed this the chap in question, and  you know what he said... He got quite shirty in fact... "Well I can't stop people just creating instances of the "Person" class, that makes my derived classes pointless!"

Oh yeah buddy, let me show you the way...

class Person
{
     private string m_Name;
     public string Name { get; set; }

     private int m_Age;
     public int Age { get; set; }

     private Person () { }
}

class Driver : Person
{
}

With a private constructor now no-one can create the Person class itself - create private copy & move constructors too for good measure!

The silence which ensued was palpable, about twenty minutes later, after staring and staring the guy came back with this:

class A
{
    private string m_Value;
    public string Value { get; set; }

    private A () { }
}

class B : A
{
}

B bInstance = new B();

"Right, now I got that, but Value is undefined in B, I need it to have a default value"... I swear to you now, I stared past his left shoulder and just shivered as I did this for him:

class A
{
    private string m_Value = string.Empty;
    public string Value { get; set; }

    private A () { }
}

class B : A
{
}

B bInstance = new B();

"No no" he screamed with glee, giggling, "I mean a value so I know its a B!" or whatever, so I did this:

class A
{
    private string m_Value;
    public string Value { get; set; }

    protected A (string p_Value)
    {
        m_Value = p_Value;
    }
}

class B : A
{
    private static readonly string c_Name = "BValue";

    public B ()
       :
       base(c_Name)
    {
    }
}

The silence was all encompassing by now, and I left him to it.  I had by the end of my programming session - before I went for my afternoon break - created around 12 versions of his derived class from the new base and totally removed his interfaces which were so ugly.  I don't think he'll forgive me, but the code was a lot smaller and easier to read, and in my opinion more correct.

The only reason the chap did not get to the same conclusion as me was a lack of understanding of the object model & hierarchy, a professional programmer foxed by this, and a more senior programmer than me... Really makes me wonder why I'm earning so little!

Thursday, 25 April 2013

WarThunder Economy Still Broken

Last night I had an interesting time playing WarThunder, I did write a post to this effect earlier, but its gone missing.  But I made Rank 11 with the help of some large slices of XP (300,000 worth from an achievement) but made little to no cash... I think I went from approx 680,000 lions to just over 700,000 earned in over 10 flights... So, 20K, in ten fights that's an average of 2K per flight and that matches my recollection pretty easily.

However, I just happened to wonder into the WarThunder forums and into the 1.29 update, and I noticed the image used by the "Borisych" member of the team... The image is:

You can go check this yourself here.

But, before you do, do you recognise the image?  Its from the film Snatch, the actor is one Alan Ford playing the part of "Brick Tip".  At this point in the film he strolls into the pawn shop, which is covered in dead body and after receiving that cup of tea from his body guard explains he is an 'orrible cunt.

Well, Borisych, of the WarThunder team, with the state of the lion earning ability of your once great game, yes, yes you are a cunt.  Well done.

Wednesday, 24 April 2013

Check your English


I've spent a serious amount of my morning explaining to people that my software was working fine, and there was in fact a hardware error.  All to no avail, as it seems the first report of the problems was worded badly and not in my favour.

"We were having the problem with the XXXX not working on Xelous's Test App.

This morning I turned off the power, re-seated the board and they’re now working."

So, with my software unchanged, they played about with the hardware and voila it magically works... This is not a software problem, but its worded just enough as to inflect that there was a problem with it "not working" in my application.

Now, you can take a look at the time of my blog post last night/this morning and see I was working on this all night and fixed it... So to see this report this morning annoys the shit out of me, no-one else was working at gone 1am, no-one else gave a shit, but suddenly they're all experts and pontificating about the problems "in the code"... It was a fucking hardware problem!

Hating it today, proper hating it.

Corrupting my Heap

I've had a hell of a few days, the family thing has droned on, but I'm fast washing my hands of the situation - they can go masturbate in their own mess as far as I'm concerned, this makes the wife and I the bad guys, but logic will one day prevail, most likely when my mother can't interrupt people and pontificate utter bollocks in her rude manner.

Anyway, what about this Heap Corruption?  Well, what a debugging session I've just had, it lasted nearly 3 hours - that's a long one for me - especially with my C++ code.  That's not to be big headed, but I have evolved my coding style and used the libraries (boost & std) in the manner I do without issues all the time, so to suddenly find a bug - one corrupting the heap - was a bit of a nasty sting.

I can't go into specifics, due to the nature of the work I was carrying out for my employer, but here's the gist...

A function was bound with boost::bind... And was called back from another location in the code at regular & mutually exclusive intervals, so on a timer... Here's pseudo code:

#include <memory>
#include "TimerFoo.h"

using namespace std;

void baa (const bool& p_Error, const bool& p_Cancelled)
{
   if ( ! p_Error && !p_Cancelled )
   {
      // DO SOMETHING
   }
}

unique_ptr<Timer> l_MyTimer = unique_ptr<Timer>(new Timer(boost::bind(&baa, this, _1, _2)));
l_MyTimer->Start(5000);

Right, and after waiting the 5 seconds the baa function would be called, and suddenly my application would crash horribly, inside the boost libraries.  Either in the function pointer headers, or even in the unique pointer header of the std.  It was an utter mess.

And the call stack gave no clues about the problem, it neither helped workout quite what had run.

The problem turned out to be a problem inside the "DO SOMETHING", which was calling into the psapi and trying to use the TCHAR pointer somewhere incorrectly.  I removed that code and its all fine again - but so scary a crash.

It has spurred me to want to update my personal coding standards and include the rule "If you have a boost::bind bound function, and suddenly your code crashes, rem out that function's body and re-run".  This is essentially how I found the above bug, I removed the whole guts of the callback and voila the code ran, but with the heap corruption it was hard, nigh impossible, to see what had actually gone wrong.