Tuesday 22 February 2011

Use the tools at your disposal

Sooo, I've had an interesting chat today, with a fellow programmer... and it got me thinking, the gist of the chat was that we had a series of interfaces all cobbled together and finally getting a review to replace them with a better structure... but this "better structure" was going from 8 to 12 modules all higgly-piggly put together.  During the conversation I described the stack of modules as "a pile of rickety plates".

So, I started to advocate the use of inheritance, so instead of splitting functionality out horizontally into 12 different modules, it would all boil down to one, or two, and then you would derive from them to inherit the base functionality and add new at each stage... meaning you didn't have to worry about coding, and testing, each module in one go, you simply have to test one the highest level abstraction...

And you know what, I got looked at like I was showing a dog a card trick:


"Inheritance, what is this inheritance of what you speak?"  I could murder some of the people in the programming game these days I really could...

I'm going to melt this guys brain tomorrow by showing him auto_ptr, instead of the risks of delete.

Wednesday 16 February 2011

Test Drive Chrome

So, I just signed myself up to the Chrome Notebook pilot scheme, it has been a long time since I've had to sit and justify myself on line in 140 words of less.

Especially after having had to follow a series of questions which had very little to do with the kind of net activity I perform.  As such I can only assume I have a snow balls chance in hell of getting hold of one of these devices.

I mean, in the "justify yourself" section I did feel like putting, "How about because I'm in the UK and you clearly don't expect to hand any out to us poor foreign follow-ons", for the vast majority of the questions my answers were "other", but nothing on the screen was asking me to explain what those "other" options were.

For instance, in the generic category of user, I selected "developer", but then all the items in the list related to usage of a computer were related to web usage.  Not really development.

I mean, when the Chrome OS comes along, I really do hope there are a range of compilers for the system, first off I'd like to see C++ (being a bit of a fan boy of that language), but later I'd like to also see some sort of porting of .NET (just like mono for Linux) to the Chrome platform, simply because of the power of .NET as a way to prototype other applications.

I'd also like to develop on the Chrome OS to investigate its graphics abilities, to understand its file handling and security subsystems.  Mainly to see how it might hold up as a gaming platform or a mini-web server in its own right... But absolutely none of that came across from the questionnaire as posed.

And of course, the final nail in the coffin was that in the "Address" section it insisted I select a U.S. State... even though I had opted for the country of "United Kingdom".... and they can't blame my using an incompatible web browser for this annoying faux-pas as I was, and am right now, using the Chrome browser... I love google kit, I just hate that questionnaire.

So good luck to anyone who fills in the answers and to those who get a look at Chrome OS and the netbooks I hope we get lots of insights from you....

If anyone at google is interested and tracks this blog down (cus they can from the info):
  * I use an O2 XDA smart Phone
  * I use BBC iPlayer as my main source of on-line TV
  * I use SkyPlayer as my main source of on-line movies
  * I listen to music with Spotify
  * I spend over 8 hours each work day solidly connected to the internet
  * I spend all my personal time (save for time driving) connected to my wireless
  * I operate Windows, Linux and c/PM based computers
  * I prefer to utilise Chrome as my Internet Browser
  * I spend most of my personal time on my computers performing development tasks in C++ and C#
  * I spend all of my working time on computers performing development and debugging tasks in C++ and C#

My wish for the Chrome OS is to investigate its ability as a development environment, its fitness for documenting as a generic C++ platform, its ability as an entertainment platform (game/media display) and finally to have a damn good look at it in general.

The promise asks me to use the Chrome Notebook as my main computer, well, it looks to me that there is no documentation of the platform being able to act as my main platform... it could however take the role of one of my desktops and two of my laptops as my main portal to the internet and entertainment... 

However, I am not your typical internet junkie...

Wednesday 9 February 2011

Using a Computer (A Personal Insight)

There are a few things I hate in life, soggy chips is one of them, vinegar is another... but enough of the chip shop variety of pet peeves, here's my main entry in the list, it is one which socially, economically and professionally I get slapped with time and time again, and this is people who think they know what they are doing, but don't.

Or more specifically people who think they know what they are doing with a piece of computer equipment, or software, but don't.

Many people in the UK talk about "exams getting easier", about things not being as tough now-a-days as they were, and computing this is most certainly true.  When I was born the PC was not really a realised entity, it was not until my little brother came into this world three years after me that IBM realised that they could get a big cash cow in the form of the IBM PC.  At the time I stayed with graphical computers, like the Commodore series (16+4 and 64), and then the venerable Atari ST (which is still here ready for use next to me as I type on my all singing all dancing PC).

But those long dark days of the 8bit and 16bit computing, the days tinkering with Commodore Basic and STOS and the understanding performance issues on a computer really set me up for the dawning of the current age of computing, I saw and struggled with unwieldy software, I saw and struggled with bad API [application programmer interfaces] to actually get this computers to do what you wanted, back in those days you could not just plug into the internet and download software to do a task for you, you had to go into magazines into infinitely minute font listings to see if someone out there had a disk you could buy which might do the job you wanted.

So you wrote your own software.  I remember the first software I ever "sold" was written in Personal Pascal for the Atari ST, and it was a semi-multi-user database for recording kills in Frontier Elite II.  The user had to write down their kills with pen & paper [can you imagine telling someone this today, in say warcraft?] then when you had done playing Elite II you loaded my program (they were programs then, not 'applications' or 'executables', the ST used the .PRG extension not .EXE - ahh, the good ol' days) and once loaded they entered all their kills, it listed them for them, gave them a tally of each craft type they had killed and let them save the list and mail it back to me on a second floppy disk, so it could be tallied with everyone else's list and I would send them their list back on that same floppy disk, and then they could see where they stood in the mix with all the other players in my rota.

Can you imagine anyone doing this in that exact manner today?  No, people today want instant kicks, they want to flip a switch.  And it was just such a someone, someone whom I remember as a child looking at my Atari like it was some sort of alien death ray and me like I was some two headed monster for understanding this piece of kit, who flipped some switches this week and ran into my ire.

This person was setting up a family tree on the internet, but as an experienced computer user; one aware of security risks and such; I didn't want to be included as more than a cursory glance on said chart.  However, this person wanted dates of birth, maiden names basically all the key identification information which would allow someone to get a spanking new American Express in my name.

So, I declined to want to be involved....

Holy mother fucking god, I wish I'd not bothered and just went to commit financial fraud upon myself (for a laugh).  This person out there clicking away on the internet really didn't read my reply, so I received this awful scree about her knowing what she was on about and basically that I should shut up.

So, I clicked all my knuckles, thought solemnly about going around her house to pull her around her own front garden by her hair, and then settled down to just say "hey, just me you may not know but I had a degree in this stuff, so I'm just giving you a heads up because you may not have realised you were risking breeching everyone privacy by publishing this info.  You have peeved me off, so either realised you have peeved me off, or go boil your head.  But if you're interested yadda yadda yadda" and I reeled off a bunch of information sources for her, sources which are not documented on-line at places like www.ancestry.co.uk, no I told her about placed like "grave books" which reside at cemeteries in the UK listing all internments and told her of two lesser known family internments, and then told her to check out the census information.

I thought my reply was a simple, did you know, and here you go.  The second scree of utter drivel I've received had made me block this person from being able to contact me, and remove her mother from my contacts list too.  I can only assume the self-righteous pious facets of this girls personality come from her mothers side of her family, as they certainly don't come from the side we share.

And this set me thinking, why does my saying "I have a degree in this" really goad people?  You don't go to your GP and argue with them when they tell you what's wrong with you... You don't take your car to a mechanic and then stand having a blazing row about whether your exhaust has fallen off or not.

So why do people who use a computers (and whom mostly have only started using them recently) sit there and tell those of us with actual hard earned experience and knowledge the what for and why to of computing?

I mean, they've not had to sit and be jibbed about being a geek, a nerd or a hacker, they've not been laughed at when they've listed their interests as "Computing".  Because they've only come to the computer as a play thing, as a communication device, as a portal.  As a mature piece of consumer electronics.  They have basically jumped on the band wagon late, and let are still trying to degrade and insult the knowledge and experience of those of us whom were on the wagon before the electrons were flowing so nicely.

And, it's basically utterly fucked me off.

I think these people need to stop being able to buy a computer off of the shelf, they need to have a computer users license first.  They need to pass a basic literacy test as well, because I'm sick and tired of meaningless babble that some people take for well constructed text.  Of the two scree's this girl sent me, I have to say the second was far better, she even managed to use one comma in the right place... just the one, but the effort was there... that's what you have to appreciate.

So anyway, are things getting easier with everyone and their dog using the computer as a device to mix up life?  Yes, but these people need to realise they are standing on the shoulders of all those dweebs, geeks, nerds and hackers who made is possible.  And when one of those founding fathers sends you an e-mail you rant at them at your own peril.  Because you're the one who will need them, long before they need you.

Monday 7 February 2011

C++ Forward Dependencies

Forward declarations in C++ can be the best thing ever, they let you decouple the declaration of a class you're working on now from the implementation of another which you happen to want to use; but havn't got around to writing yet, something like this:

#include
class B; // This is a forward declaration
class A
{
private:
B* m_PointerToB;
public:
A (const B* p_InstanceOfB) : m_PointerToB (const_cast(p_InstanceOfB))
{ // I know this is declared inline, but just for this explanation
} // don't worry about it
void Output () { std::cout << "Hello World" << std::endl; }
};

So I can carry on declaring and implementing this class, without worring about B.

However, there is a problem with all this, if your forward declares are in different namespaces and you're trying to include the classes which are forward defining one another from different header files, what do I mean?

Well, I declare Class A in a header and implementation file pairing e.g, a.h and a.cpp, they might look like this

-- A.h ---
#pragma once
#ifndef CLASSA
#define CLASSA
#include
namespace SpaceA
{
class B;
class A
{
private:
B* m_InstanceOfB;
public:
A (const B*= NULL);
void Output ();
};
}
#endif
-- A.cpp
#include "A.h"
namespace SpaceA
{
A::A (const B* p_PointerToB) : m_InstanceOfB (const_cast(p_PointerToB))
{
Output();
}
void A::Output ()
{
std::cout << "Hello World" << std::endl;
}
}

This all works fine, you can compile and even run an instance of Class A around a little, the next day however, when you come along and implement Class B properly, some rather odd, and pretty badly explained (by the compiler) messages will pop out at you.

These messages will ellude, vaguly to the problem that B is not a B.  And they will usually be listed against the compilation of tile A.h but I've also had A.cpp and B.h show up as the erroneous file the fingers of failed compile are pointing at.

So, lets look at the header for B, before we go any further:

-- B.h --
#pragma once
#ifndef CLASSB
#define CLASSB
#include
namespace SpaceB
{
class B
{
static void Describe(const B*);
};
}
#endif
-- B.cpp --
#include "B.h"
namespace SpaceB
{
void B::Describe (const B* PointerToB)
{
std::cout << "Pointer to B is at ref " << PointerToB << std::endl;
}
}

If you compile now, you'll still not see an issue, you'll not get a repot of a duplicate declaration, because the two declarations are in different namespaces, i.e. they are not just "B" and "B" they are infact "SpaceA::B" and "SpaceB::B".

What we need do now is imagine we're on the third day of this (lets face it arduously hard coding task), and we go back now to link more class "B" related functionality into A, thus:

-- A.h (version 2) --
#pragma once
#ifndef CLASSA
#define CLASSA
#include
#include "B.h"
using namespace SpaceB;
namespace SpaceA
{
class B;
class A
{
private:
B* m_InstanceOfB;
public:
A (const B*= NULL);
void Output ();
};
}
#endif
-- A.cpp (Version 2) --
#include "A.h"
namespace SpaceA
{
A::A (const B* p_PointerToB) : m_InstanceOfB (const_cast(p_PointerToB))
{
Output();
}
void A::Output ()
{
B::Describe(m_InstanceOfB);
}
}

And here things go wrong, if you miss the "using namespace SpaceB" on line 6 of your new A header file, then you will get a message that "void Describe (const B*)" is not declared for class B.

Lots of you will be shouting "obvious", but some of you will be happy that someone out here on the internet has pointed this little foil out, but the bigger problem here is that you fix the name space as above or thus:

SpaceB::B::Describe(m_InstanceOfB);

And you suddenly get another error, this time you get a message that type "B* can not be cast to type B*", some compilers will be a little more specific and report "const SpaceA::B* can not be cast to const SpaceB::B*" [two of the three compilers I tried did this latter option].

And unless you're eagle eyed you might be foxed by this error for a while, the problem is of course the amgiuity you have left in your code from the forward declaration of B in the file A.h.

You could remove the forward declare and #include "B.h", but this might introduce a cyclic include, and most certainly will be a build dependency we can avoid (avoiding build inter dependencies is good - so long as you test your code properly - but that is another topic).

So avoid any problems including or making a new build dependency we simply need to move the forward declare into the correct namespace, thus:

-- A.h (version 3) --
#pragma once
#ifndef CLASSA
#define CLASSA
#include
#include "B.h"
namespace SpaceB
{
class B;
}
using namespace SpaceB;
namespace SpaceA
{
class A
{
private:
B* m_InstanceOfB;
public:
A (const B*= NULL);
void Output ();
};
}
#endif