Wednesday, 26 September 2012

Software Engineers Never Get a Specification.... Deal with it!


As a software engineer, I'd love to get specifications for the software people want me to write for them.  Unfortunately in this world of mobile wizardry and the eponymous "Apps", people don't want to sit down and help specify what they want, they want to just give general ideas of what they want and they believe I'm able to discern everything else for myself.

This one-sided "just do it will you" attitude has forced me to turn the tides on people, in the last three projects I've worked on I've been left to do what I wanted from start to end and then had numerous, onerous, tiresome complaints that what I've delivered (though good) wasn't quite what they wanted... I've politely, and not so politely, pointed out that if they don't actually feedback, or even start off, with a good idea what they want.  And if they work with different goals than I work with, and both they and I see the interaction with the end customer differently, then even though we work for the same company we can't reach the same conclusions nor attain the same common goals.

All for naught however, as it always just seems to circle back around to "its your job to create this software, get it done"... my whimpers asking them to define "this" go unheeded repeatedly.

So, the worm has turned, I've today released an internal tech demo of a new software element, its just one element of a three part series, and this is only a mock up of it... The challenge is to get a "feel" for user interaction on a display.

We have a touch screen, we have graphics... But we have no idea actually how people interact with our system... We don't do time and motion studies, we don't even sit in the distribution point and watch, we just sit and assume people would interact with the machine how we would... And they don't.

There's nothing ground breaking about this piece of software, nor my releasing it... what's revolutionary and what's pissing those who should have spent some time specifying how it works to me off is that... Everything in it, EVERYTHING, is configurable through an XML file...

The margin width, the speed of the touch screen, the area of the images, the images themselves... Everything on this thing is configurable... So its really all up to them to decide if how it acts is how they want it to, they can turn up the deceleration, turn up the touch response, tone down the area a finger on the screen represents... they can mould and fold this configuration around all they want.

The upshot has been two fold.. Firstly, and brilliantly, for the first time ever I'm getting meaningful feedback on the behaviour, I'm even getting told that some metric is missing, or some feature needs representing and what range it needs to support!

The second fold is not so good... The less able members of staff, that is those whom like to criticise, are taking their analysis to a whole new, abstract, level... Instead of doing what was asked, i.e. to try the application, which is a mock up, out... They're opening task manager and monitoring how much CPU it takes and looking at aspects of it totally unrelated to the idea of "give it a try"... things which are NOTHING to do with interacting with the application... And when I say "This is a mock up, just tell me how you think it feels, I need that human feedback of how it works, how it comes together"... they reply... "It comes together as taking 20% more CPU than we can allow"... That's not human feedback, that's not how it interacts... That's in fact got sweet FA to do with the task at hand.

And I'm starting to file these latter people into the unhelpful bin within my minds eye...

Tuesday, 25 September 2012

Coding Standards - Naming Variables


Warning, when you have code and within that code are elements you are naming thus:

        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.Label label9;
        private System.Windows.Forms.GroupBox groupBox1;


You need to stop, look and think... You may know that "Label1" is for the stock inventory level, you may know Panel 1 is the background... You may know this for days, weeks or months... But over time you will forget, its not important enough to you to name them properly, so its not important enough you remember what they do... And this is a downward coding spiral.

Its much better from the offing to spend seconds to give them a meaningful and purposeful name upon creation, so that you can identify them easily from crash reports, or designs, or just people plain old pointing at them in the future... And its the future thats more important, because remember it may not be you coming back to revisit or maintain code later.

Some poor schmuck finding this kind of naming and poor form will as soon as anything point the finger of blame at you, to cast your name as mud and to deride all your efforts; whether warranted or not; as useless trash.

So, don't look a fool, don't be a fool, name things in your code properly... Gui elements, Locals, Members, Globals and Constants they are the currency of your program, so pay them some respect.

Friday, 21 September 2012

Twenty Seven


I'm beginning to believe there's something special about the number twenty seven... I've just been into the listing of my blog posts, and on the first page of listed posts, several (that is more than one, less than all) of them have exactly twenty seven views... This would be unremarkable if I had 27 followers, or had 27 friends... But I don't... And I don't...

The posts are seemingly unrelated too, the internet in its infinite wisdom has seemingly guided 27 random people to several random posts on this back end of the world blog of mine... Go figure.

Wednesday, 19 September 2012

OpenGL - Gaps between Triangles


A strange problem posed itself to me in Linux last night, infact in OpenGL in general - this problem happened on OSX, Ubuntu, Fedora and Windows Vista for me... Here's the low down...

I've created a simple 3D view contained area in OpenGL



Into this I want to place items, buildings, people whatever... So, I start to define a rectangle, which is going to be a wall...



As you can see, on it I place my text texture, so I can tell left (red) from right (blue) and top (yellow) from bottom (white) to make sure my texture loading and texture coords are correct... But I can see that damn line between the two triangles... Yet I'm using the same vertices for the corners, there should be no gap.

Switching from glBegin(GL_TRIANGLES) to glBegin(GL_QUADS) I can still see a single line between the triangles, so its not my coordinates or triangles... What the heck can it be?

Now, I'm using pretty old OpenGL here, really really old stuff, so for 2012 the information available on the ground is pretty slim, there's alsorts of suggestions out there and no real documentation as to what is causing this...

In desparation I started to play about with the blending settings, to no avail, then I started to play with the smoothing mode:

glEnable(GL_SMOOTH);

glHint(GL_POLYGON_SMOOTH, GL_NICEST);

glEnable(GL_POLYGON_SMOOTH);

glShadeModel(GL_SMOOTH);

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

None of this seemed to work... So I started to play with the multi-sampling...

glEnable(GL_MULTISAMPLE_ARB);

Still no joy....

But.. Disable the smoothing AND enable the multisampling and everything starts to work:



// Set Rendering smoothing
//glEnable(GL_SMOOTH);
//glHint(GL_POLYGON_SMOOTH, GL_NICEST);
//glEnable(GL_POLYGON_SMOOTH);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_MULTISAMPLE_ARB);

I can now start to add brick textures and make my boxes into buildings...


RAII - Please for the love of god....


I'm going to just vent here folks... In programming, if you have a class which HAS TO HAVE all its members initialised, DO NOT just expose an empty constructor...

Here's what I mean...

#include <string>
using namespace std;

class A
{
   public:
   
      int _id;
      string _name;      
      
      A (const int& id, const string& name)
        :
        _id(id),
        _name(name)
      {
      }          

};

There's a class right, one assumes there's only one way to initialise a copy of this class?  The constructor giving implicite values, yes?... Good.

So when you want this pattern, make sure it works just how you expect, hide the other constructors... thus:

#include <string>
using namespace std;

class A
{
   private:
   
      A() {}

   public:
   
      int _id;
      string _name;      
      
      A (const int& id, const string& name)
        :
        _id(id),
        _name(name)
      {
      }          

};

This stops blank copies being generated, on compilers which automatically create the defautl constructor public!

Likewise in C#, do the same... If you have a data class:

class B
{
    public int _id { get; set; }
    public string _name { get; set; }
    
    public B ()
    {
    }
    
    public B (int id, string name)    
    {
    _id = id;
    _name = name;    
    }
    
    public string NewToString ()
    {
    return string.Format("{0}-{1}", _id, _name);
    }
    
}

That class is no big deal, the int and string are implicit values, they have inplicit values upon creation.

B b = new B();
Console.writeline (b.NewToString());

All works fine, but if we add a user class in there, or any other class which can be null... then we have to be more careful...

class StudentRecord
{
    public string _name { get; set; }
    public DateTime _dob { get; set; }
}

class B
{
    public int _id { get; set; }
    private StudentRecord _student;
    public string _name 
    {
    get { _student._name; }
    set { _student._name = value; }
    }
    
    public B ()
    {
    }
    
    public B (int id, string name)    
    {
    _id = id;
    _student = new StudentRecord();
    _name = name;    
    }
    
    public string NewToString ()
    {
    return string.Format("{0}-{1}", _id, _name);
    }
    
}

What happens now?.... Well the code will crash:

B b = new B();
Console.writeline (b.NewToString());

Will throw a null reference exception in the call _name against _student, as it is not implicitely defined during creation when using the default constructor.

What we should really do is utilise the "Resource Allocation Is Initialisation" (RAII) concept and only allow a new B to be created with the defined values.  And we should do this to all classes, whether they have implicit values or user defined classes within.

How do we do this?  By stopping the default constructor being used:

class B
{
    public int _id { get; set; }
    private StudentRecord _student;
    public string _name 
    {
    get { _student._name; }
    set { _student._name = value; }
    }
    
    private B ()
    {
    }
    
    public B (int id, string name)    
    {
    _id = id;
    _student = new StudentRecord();
    _name = name;    
    }
    
    public string NewToString ()
    {
    return string.Format("{0}-{1}", _id, _name);
    }
    
}

Now, the only way for the programmer to get using this wrong is to mess about with the code!

It stops all those annoying "What the Hell just happened" during runtime, and some poor other schmuck doesn't have to do running around working out where your code went wrong because it missed an assignment, such as this, very poor code:

class B
{
    public int _id { get; set; }
    public StudentRecord _student { get; set; }
    public string _name 
    {
    get { _student._name; }
    set { _student._name = value; }
    }
    
    private B ()
    {
    }      
    
    public string NewToString ()
    {
    return string.Format("{0}-{1}", _id, _name);
    }
    
}

B b = new B();
b._id = 0;
b._name = "Tom";

Which would need to be:

B b = new B();
b._id = 0;
b._student = new StudentRecord();
b._name = "Tom";

Horrid horrid, its bad code, bad coding practice, and using excuses like "This class will be removed later" doesn't really wash with me, because code has a half life you can never predict, you don't know how long your code, or your class, will be around and used and release it in a bad form today, it'll bite you again and again... Release it nicely, with rigourous defensive programming and you'll find yourself not being hassled by it.

Tuesday, 18 September 2012

BBC iPlayer Volume


What the fuck is it with the BBC iPlayer not keeping the volume level how you've set it between videos?...

I mean you visit their site and are instantly blasted out your seat by a volume level of 7... So you scurry to turn it down how you like it (or up if you like) then swap show and BOOM its back up to 7 again.

So very very annoying.

Monday, 17 September 2012

Sweets for Programming - I


Over the next few weeks, I'm going to be setting up my desk a little better and working more code time at home, in the evenings... Consequently I've decided I need to do something constructive towards my coding productivity at home... I need to pick a sweet to suck on, something to let my mouth idle whilst I mull over complex coding problems.

In America, as I understand it, chewing gum is the vogue, however, gum results in the need to spit, stick or in emergencies swallow its tacky remains.  I prefer a sweet, so that I can suck it to oblivion without worrying.

So, the first sweet I'm picking is the Polo... I love Polo's... The hole, the fact some crumble, whilst others are hard as diamond, they're minty, and great... They also come in a variety of flavours, and the first I've picked is the Spearmint Polo...



I'll let you know how I get along.