Monday, 15 July 2019

Willful Ignorance (C++ Templates)

I had a moment last week where I was a little down on my C++, you see I'm a very old programmer, by programmer standards, and my experience with C++ stems from a time before templates, this may amaze and delight in equal measure as template use is so ubiquitous today, however I've been using find & replace style boiler-plate code in the form of both macros and code-gen for literally decades.

Templates however have not been my go to option, because of that weight of experience.  I actually find picking apart heavy template code quite hard going at times (I think a lot of us do).

But I was down as a valued colleague (Hi D if you read this, you know it's you) described this approach of mine as "willful ignorance".  And he was right, I have to put my hands up and admit he's right.

As such I took a look over my old state machine repo on github and realised there was a bunch of boiler plate stuff I was doing with both macros, or not doing at all, which could easily be made to leverage templates.

Watch this space...

Thursday, 27 June 2019

C++: make_unique friendship

I've previously posted about adding a friendship to the shared_ptr base class to allow a public static function containing a "make_shared" to access private constructors....

Well, here's the partial move I've started to make in my own code bases to do the same with a unique_ptr.

#include <iostream>
#include <memory>

class Item;
using ItemPtr = std::unique_ptr<Item>;
class Item
    static ItemPtr Create()
        return std::make_unique<Item>();

    const int& Get() const
        return value;

    friend std::unique_ptr<Item> std::make_unique<Item>();

        : value(42)

    int value;

int main ()
auto i = Item::Crete();
std::cout << i->Get() << std::endl;

The secret sauce here is the friend, making the "make_unique" function a friend allows it to access the private constructor.

We could water-tight the "Item" class here by deleting the other constructors...

Item() = delete;
Item(const Item&) = delete;
Item(Item&&) = delete;
Item& operator=(const Item&) = delete;
Item& operator=(Item&&) = delete;

This way we stop any assignment to the type or construction except through the static "Create" function.

Nothing truly amazing here, but I challenge you all now to go add a parameter to the constructor... const int& incomingValue... perhaps and add it to the "Create" and try to set "value" to 100 instead of 42.

The template deduction for the type becomes a total mine-fiend, as the compiler wants to marry  up the "Type&& ..." underlying the parameters rather than treating it as a pure standard forward.

Saturday, 22 June 2019

Problem Neighbours - mY RanT FOr SanITy SaKE

Ooooommmmmmm.... I will remain calm..... Oooooommmmmm..... Neighbours eh... Everybody needs good neighbours, just a friendly wave each morning, helps to make a better day...

Yeah, not here.  So, we moved, just six months ago, on moving day the guy selling to us had what at the time seemed like a grand pantomime, he seemed to relish in stepping out the house for the last time and declaring the neighbours on one side to have been the worst neighbours he's ever had.

At the time we thought, Christ... and I even touched base with my solicitor whether this; whatever it was; should have been disclosed.  But it was not listed anywhere, querying there was no legal dispute it seemed to just be two folks not getting on.  Indeed, the neighbour in question popped around a day later to welcome us and gave us a potted plant, we exchanged christmas cards and thought nothing more of it.

Except, slowly over time, we started to see cars slowly encroaching on the drive...

Let me explain, we're in a block of three, a cul-de-sac off the main road, three houses in a row, with one tarmac area, the house to my left owned their whole front right out and we have an "easment" to cross it... Not a right of way per-say, but an easement such that anything related to the operation of my house I can cross their front... I then own the whole middle segment aligned with the neighbour to the left and my right hand wall... straight line.  Dead simple.

This line cuts right in front of the other neighbour, the problem neighbours, garage doors.

So, it's poor design, they're meant to store their cars in the garage, pull them out, shut the door and drive off... They're not meant to park on my drive in front of their garages.

However, these problem neighbours, before we even moved in decided to repurpose this double garage into a workshop, I had no idea of this when buying, none at all, the cars were not parked where they now were, but there seemed to be a status quo... So long as these parking neighbours didn't push it, we accepted them parking there and I left it with them as such when we spoke whilst I was out pottering and sorting the front garden.

Fast-forward two months, and suddenly they wanted to put a huge camper van there.  To their credit they came and asked if we minded, as rightly it would be a pain blocking the common access road to the whole close.  Fine, it parked there, but I said "this isn't a permanent thing, just a few days whilst you have these special visitors"... Fine, and it went, no problem.

You see, this cul-de-sac is on an incline, we're in the middle, nice neighbours to the left are down hill, problem neighbours are up hill... They say shit rolls down hill, but the problem with this incline is that their cars are at eye level as we sit in our nice new front room, literally there, no sky, no view just the underside rear of these cars which shouldn't be there... Which we're doing them a favour of letting them park there.

Fast forward again, and randomly this big blue VW van like people carrier appears.  This thing totally blots out what little view there was, just puft, no view... and it was a dark blue, so there was no reflected light either... It was a nice sunny day, but a miserable view.

Now, this turned out to be a visitor to problem neighbours, they stayed a few days.  I hark back to the other camper van and I you can see I gave an inch but suddenly it felt like a mile was taken.  So I waited until these visitors had gone, no-one wants to be embarrassed, and I quietly went to speak to the neighbours.

Well, never have I had such a drama.  The guy started to wail and grabbed his forehead "I don't need this stress, I saw all my mates shot in the middle east, I don't need this"... I was like, how the hell did I get from "can you refrain from parking that huge camper here" to combat casualties in the 1960's Lebanon or Sinai (he's not English BTW, this chap is Norwegian) plus he's hard of hearing, so I'm not sure he heard what I was saying at all with his own voice echoing in his ears.  It was a very simple request, just to make sure that the previous permission for the visiting camper, it was clear, didn't extend any further, that I didn't like it.

After all, it's my land... And this seems to be the crux of the problem, they want to use their garage in an unintended way, their solution then isn't to park somewhere else, it has been to park on my land.  Now, okay, I don't use that land and yes the width of it they have an easement over which they may pass, but it's a right of way, not a right of occupancy.

But the drama didn't stop there, this chap went to the other neighbours, the nice ones... Crying.

Now, he's in his mid-70's... and apparently sobbing that he's upset someone (we'll get back to that theme later).

My take away was he's got some form of PTSD, and I planned to speak to his wife when I saw her, she's always seemed more level headed, Poe faced and a bit stuck up, but sounded reasonable, and she's not hard of hearing and English so I thought there'd be no deafness nor language barrier.


She appeared about an hour later knocking on my door, and her words about the visiting camper were... "Do you know how much that cost?"...

Like I was meant to be impressed!... Conspicuous consumption does not flatter the beholder love.  It was a dirty great tin can on wheels with a white plastic roof (can you tell I'm not interested in cars?) and even if it was say a Lamborghini sat there, it'd still have been sat on my land, in my eye line and not either of their (the neighbours) car which we'd had allowed.

Her then immediate reaction was to turn on the other neighbours, the nice ones, who happened to have a caravan on their front that day... "What about that caravan?! You've not told them".

No, because firstly the caravan was on their drive, in their car port, it was not blocking nor on any part of my land at all.  Second the neighbour herself had said, "It'll not be there long, I can't stand it being there, its only here before we go away at the weekend"... Which was all fair enough.

Problem neighbour didn't like that though, she stomped off... I called after her "Sorry"  I wish I hadn't, I should have stuck to my guns.

But I spoke to my solicitor about this, he said "keep it a civil matter, the moment you involve me you'll have problems if you ever want to sell.  But send them a letter, explain what you don't like, what you will tolerate".

So I did, I explained my intention was not to upset him, I explained though that it's quite ugly, not our cup of tea, that they are over our boundary and we accepted their two cars only as a neighbourly favour.  I didn't want to be petty and just summarily ban them.... I kind of wish I had now.

I suggested, maybe if they convert half the garage back and put one in, at least swap them over so the larger car is further away from my window.  And if they ever wanted to talk to us please do.  That they can park their two cars, but not visitors and if ever they, or we, put the houses on the market the cars to move immediately.  As I didn't want this to be inherited as a problem down the line.

That letter was handed over a month ago... What's happened since has been subtle signed of rebellion, so they did swap the cars around so the larger darker one was further away from the windows.  But then they started to drop the other one back... Not pull it to the garage doors as they had done... Just a subtle "fuck you".

Then, they started to slowly drift the cars pulling up towards the property, rather than sticking; as they had for so many months; to the far fence.

And then the drama yesterday... and just now....

So, both our rabbits have had operations and one of them stopped breathing and went blue, the vet needed permissions signing to act, I gave verbal permission and went to go sort things out... I was so frantic.  I called my wife to come back from the dog walk she was on and we'd swap, she'd stay with the dogs and I'd drive to the vets.

The wife came in, and said "you can't get out"... There was a giant van parked there... Blocking my entire front.

Now, I immediately recognised this van, it's a battered old 1990's ambulance with a hand painted sign about being a mean green machine.  It was just sat there, it belongs to a guy at the top of the street who has two such monstrosities.

I got my shoes, grabbed my keys, and went to knock on the problem neighbours door... I knocked... And rang the bell, and knocked... Nothing... 3 minutes seems like an eternity... Five minutes and I can vaguely hear voices down their far side alley, so I call down "coo, it's me from next door can you move your van"... Laughter, more chatting... 6 minutes seem like a very long time, I rang the door bell.. Remember I know the guy is nearly deaf, these voices sound male, so I call again... "Hello, can you move your van"... Nothing.

My wife calls to me, "they're in the back garden, call over our fence".

So I pop down and get up and call over, there's the owner of the van say chatting with the wife (she must have a very manly voice for it to sound like that) anyway, I ask him to move it "can you move your van"...


"because I need to get out"

"Who needs to get out"

"I do"

"Alright, in a minute"

I'm getting mightily annoyed now....

"No, now, I need to go out now"  I don't want to say "cus my bunny is maybe dead" that's not macho enough, but this prick just gives me this fucking stare

"Who wants me to move?"

"I do, me"

"And who are you"

"Just move the van now"

He's grunting and grumbling but he steps into the conservatory on the back of next doors, and does the most stupid thing, he grabs his crotch with his left hand and makes the wanker sign at me with his right, like I can't see him... Clearly their opinion of me is that level, the owner of the house she sits there impassive, she doesn't say anything, she doesn't say "sorry" to me, or "please go move it" to this is a visitor to her house....

I see this gesture and I call "don't make that sign at me"

"Fuck off" he screams, literally, as he gets in his van "this is a right of way, fuck you"

"This is not a right of way, this is private property you are not delivering or doing anything other than block me in, this is my drive, my land, and if you make that gesture at me again you will regret it"

"Fuck you, I'll fucking knock you spark out"

"You will try, now move this shit heap off my drive"

"Fuck you, show some respect for your neighbours, how long have you lived here?!"

"Six months, and you have a whole empty road to park on, but park here blocking me in, you show some respect, now move it"

"I'll fucking knock you spark out talking to me like this, who do you think you are"

"The owner of this land, and you try and hit me you will regret it"

I don't think this floppy haired idiot has ever been stood up to before, he seemed quite willing to mouth, but had no trousers on, I meanwhile really, really wanted to break some part of his scrawny little know nothing body.

He finally moves, but I've not got my phone, so I turn around to get it and the vet is calling, I take the call.  Bunny lives, just she's blue but alive.

I quickly go speak to the neighbour, in the hope of pointing out this was exactly what was on that civil letter sent not a month before... her instant stance "it has nothing to do with me, Andy is having a hell of a bad time at the moment" and she's putting up her hands... I really don't care what kind of time he's having.  And a visitor to her house, blocking completely the neighbouring property, on a contentious issue they've already had a letter about and then said visitor being abusive and threatening the owner and person in the right.... Nothing to do with her.  Right, got your level.

I'm starting to see where this worst neighbour mantle awarded them comes from, because they are, they're awful passive aggressive people, stuck up and not a little spiteful.  I've told numerous visitors to park on the road, this guy as well should know that, he lives on the same street!  But oh no, "it's a right of way", his van was empty, he was in their back garden chatting... Fuck that, tired of it.

I left her there, went to the vets.

As I'm coming back from the vets I call through to the nice neighbours, after the pantomime of him going crying to them before I wanted to just nip any miss communication in the bud, not least as this abusive wally has two clapped out vans blocking both his drives to his wife parks his car on nice neighbours drive when they're away; which they are now.

Nice neighbour immediately said this Andy is an idiot, he's fallen out with multiple people over his time on the street.

As for the problem neighbours, she wouldn't be drawn on them, but admitted that this whole issue had come up with the people who sold this house to me, the moment they moved in these problem neighbours were take take take, push, push, push.

So, this morning, I'm actually again back from the vets, bunnies in their carriers on in each hand.  And the problem neighbour block, the deaf one, pulls up.  I wait a moment and say morning, and I say "That unpleasentness with Andy yesterday".

Before I can continue... "Its nothing to do with us".

"He was a visitor to your property, it is to do with you"

"It has nothing to do with us" and he lifted both arms palms towards me and motioned to bat me away like a fly.

I called after him "That's it now, I've tried to speak to you twice, clearly I can't speak to you, I shall not try again".

What else can you do with people like this?

I am very tempted right now to tell them to get the solicitor involved and just injunction them from parking on my land, they have a double garage use it.  And to reinforce legally that this easement is not a right of occupancy, and to clarify it's not a right of way.

So an easement is a permission that I have to give to let them cross my land, for the function and purposes of the running of their house, so deliveries and their own access to their border and garage front.

It's not a permission to park.

Now, on moving day the drama kicked off when the deaf problem guy did try to tell me the border was elsewhere from where it is, he tried to tell me it was dog legged off another wall and so he owned this piece of land his cars are over onto.  I immediately nipped that in the bud, and clearly they went back to review their own legals as he even verbally admitted "I am a long way over onto your land, are you sure you don't mind".... Stupidly I said, I didn't.

In hindsight, I wish I'd have said it annoys the shit out of me, because that's where we are now, that niggling annoying thing you can't yourself easily solve.  Legally they don't have a leg to stand on, they're on my land, on my terms, they've violated the civil request in a most uproarious fashion and then want to wash their hands of it.

If they'd say "I'm so sorry he spoke to you like that, he is in a bad place, I'll have a word with him" then that'd have been much better, pacify both parties, as you try to do, instead passive aggressive "nothing to do with us"... Like it's a sport, they're goading you on that little bit.

The ultimate step for me is to speak to my solicitor, give them a date to move the cars and my reclaim and affirm the land as mine.  That puts me in a difficult situation regarding selling down the line, we were not thinking of selling, only just getting here, but this situation is enough to put you off.

We shall see, but this is one of my rant posts, an insight into the passive aggressive or out and out yobbish behaviour of the British public.

Monday, 17 June 2019

C++ : "ignored-qualifiers" warnings are a bit wrong

It has been a while hasn't it... I'm very busy, sorry.... But here's an item, the const qualifier on return types in C++... So, I'm of the same mind as Scott Meyers that you should const everything you can whenever possible, and one place I always const is on return codes from functions where I don't want the result to be mutable, like this:

const bool OverTen(const int& p_Value)
return p_Value > 10;

I don't want the caller to this function to modify the result, that bool they get back, I want it to be constant, I want them to use that bool for that one purpose.

This compiled fine, until you compile with -Wextra, where you then get -Wignored-qualifies and the message:

warning: 'const' type qualifier on return rype has no effect

But I want it to have an effect, I want that to be immutable, it's a constant boolean.  It could be anything, a constant error code value, I don't want someone to fudge over an error by setting it to some other value!  I want it to be constant.

It not being constant allows crusty code like this:

auto test = OverTen(2);

if ( NefariousProgrammersBirthday() )
test = true;

if ( test )

I'm sure you can see where this is going.

but, but but, you're going to argue that I'm assigning to auto, I'm not using "const auto".  Well that's my point, I want the warning to tell the programmer that they're assigning my const return type to a non-const auto, that they should be using "const auto" and hence close this loop hole.

Instead the compiler warns you that your API, the return being const, has no effect.  It should have an effect, the return is constant and it should be hard to get rid of that constness.

For instance if one had to const_cast like so:

auto test = OverTen(2);
if ( NefariousProgrammersBirthday() )
test = const_cast<bool>(test);
test = true;

Well, that jumps out at you, as would

auto test = const_cast<bool>(OverTen(2));

or even

auto test = (bool)OverTen(2);

So, I would suggest that if a return type has const the auto becomes "const auto" immediately, attempts to change this are easy to spot.

And -Wignored-qualifiers should NOT report a warning on a const qualification of a return, because it is being used in the auto case, and then if it were being assigned to a mutable type:

bool test = OverTen(2);

Then you should truly get an ignored-qualifiers warning, because the const on the function result is being ignored.

Friday, 24 May 2019

Development Job: My Interview Log

Where have you been, and what have you been doing?... Well, in the short I've been very busy with the new job, which brings me to post, as there was a little confusion raised about my post the other night.... That post, like many of them here, was set up to go out months ago (in 2018 to be honest) I'd actually forgot it was in rotation, it wasn't for a recent job interview.

But it's about interviews I want to talk, so in my job search last year I had five interviews, count them... FIVE.... I'm not sure where on the scale of interviews that stands, to me it was a lot, to others it maybe very few, for you see the last time I was seeking a new role (in 2003 so a LONG time ago) five interviews was a lot, I had new roles very quickly for a time and interviewed for them once.

This time however I interviewed them as much as they interviewed me, indeed my current boss can vouch for the fact that after they'd made an offer I actually asked to go back and meet them some more, I wanted the right fit.  Being honest, I think I have it, it's interesting work and in a new field and includes international travel (as much as that can be a drag).

However, I wanted to talk today about the other four interviews, all of them started as phone interviews, two of them didn't go further than that, two did... One did and lead to an offer I kindly declined, lets just dissect what I can from them.

The first phone interview was for a company literally around the corner from my old house, I only decided to interview because of the proximity, a literal 10 minute commute really appealed after the 1 hour + drive I'd endured so long.  The interview was about server control, fiber channel, fat pipes, bits and bobs, but nothing development, I was after a hybrid role to allow me to stretch more with my server work but keep the development side ticking over... Simply the role didn't seem a fit so I left it there.

The second was also a phone interview and Brexit got mightily in the way here, it was for a company based in France, who wanted to move a certain subset of their products to the UK before Brexit, so they could possibly avoid import/export problems if the UK drops out of the customs union, it was all very very dodgy sounding and seemed they were willing to pay, and pay well, but you were taking all the risk.  Three times they repeated that "you will only receive one months severance pay in the first five years", very odd to say in an interview.  Then the kicker was that my boss would be in France, I would have to pay (myself) to travel back and forth, and I thought to myself my schoolboy French (GCSE grade E no less) would not suffice.  Plus it was in a very boring industry.

The next interview was a phone call, that progressed to my being invited for a face to face, and is perhaps the worst interview I've ever been in.  It began with them handing a laptop to me and asking me to write code... Except, they didn't want me to write code... They wanted me to write the Unit tests (google or NUnit - your choice)... BEFORE the code existed.  Now, this is a little alien to me, Test Driven Development (TDD) has always been a bit of a dark art, to write a test of code which doesn't exist yet seemed even more strange.

I get the principle, you write tests then write the code to conform to those tests, but this smacks of doing the work twice to me, I'm much more at home writing the code then testing it, or littering it with asserts, than TDD.  And I personally always favour a positive forward branch approach to code, so I make checks to get to the functional guts of a function then handle the error conditions in each "else", not the most popular approach but less off the wall than this chap was asking.

I went along with this test, let him show me what he wanted, then asked "the foo-bar program, it's maybe 9 lines of code, we've written fifty in tests, it's taken forty minutes to catch every case.  I can't but help think this is just to make someone none-tech-savvie happy that their code runs instead of them understanding the code themselves".

There was a distinct gust of cold air in the room at this point, and the technical interviewer left, handing me over to the WORST three hours of interview, YES, three hours.  They loved me, they talked about me, my life, told me their situations, about the company, about plans and products, stuff they really shouldn't have unless they were hiring me.... They were so happy they were promising me a job offer by the end of the week, even the end of the day. But on my mind was that test, it made me utterly not interested, that TDD session had me stone cold on the idea of not working there*.

At the end of the interview, I said this, that the technical test was a major off put, I said that I felt it smacked of their being a manager stood before a board berating everyone that their test was orange or god forbid red, rather than the code be succinct or of quality.  And that I would withdraw from the application.  They looked surprised and asked me why I didn't like the TDD approach, but I didn't want to elaborate.

As I went into the car-park, where I had parked, the sun had come around in the hours I'd been in there, so what was an opaque window I could now see into... there was a large man, with a bluetooth headset on, stood in front of a large wall mounted display, with the tests showing green or orange or red, and he would theatrically put his hand to his ear and make a person in the room look up as he spoke to them through this headset... I could not help but chuckle.

The final interview was from a friend, whom hearing I was on the job market instantly wanted to work with me again, he set up an interview with their C# web crew and told me to get my bum in their seat.  But this role was a long way away and even with the M1 it was an hour still... But on the days I went down there, massive traffic jams and I spent 3 hours in the car both ways, so it was already not going to be on the cards.  What was interesting though was this progressed to two interviews, two face-to-faces.  Because, the first two guys who interviewed me were leaving, they were hiring me as their own replacement.

My friend kept me interested and the pay was excellent, even if it was C# rather than C++ and they did their own NOC work and even though it wasn't a 100% fit it felt okay and the industry was familiar, as I'd worked within it before.  But on the second interview I was asked the BEST technical question... "if you have millions of strings, how would you optimised concatenating them together"... I asked if they were sorted, they were, so I said "from a single thread, optimise by threading the operation, concatenate the first half to the second or however many cores you have".

The guy just looked at me... "What about StringBuilder"... That was his whole reply, string builder, which is allocating it's memory half over each time and appending my memcpy under the hood was the solution he wanted, not threading, not pointer amalgamation, not memory defragmentation "StringBuilder".  This continued, rather than their thinking about solutions in code in terms of the problem, they thought of them purely in terms of C# classes, C# C# C#.  It was a little woeful.

I then asked about the roll out of the product, asked how they were working on it, remember I'm interviewing to be their boss... "because there's a bug in there"... I had done my homework, I'd spent a bit of time on their site, and found a definite bug, you do a search term and you get informed there's maybe 40 results or 200 results.  How many of these results can you see?... Just one.  The resulting search list was only showing the first result, none of the others.  If you changed the sorting order (to say by price) and did the same search, a different single result was shown, but still it said there were X others.... I pointed this out.

I literally sat there and showed them the bug.  And the chap looked at me, blinked and said (in front of his own departing managers) "There are no bugs".

I literally laughed, I thought it was a joke.  The managers just looked at me almost cringing, looked at him and we left it there, walking out to my car I asked the manager, "Is that why you're leaving?  You can't control or tell that technical bod when there's a problem?".... His answer was "Yes".

The last interview was were I've come to, about which I will say no more, but I hope you've enjoyed my little journey through strange, interesting and sometimes scary interviews in 2018.

* Interestingly a chap on the team I'm now on had worked at that company, he'd left them when the TDD mania began, funny that.

Sunday, 12 May 2019

Development Job : Interview Questions?

I was asked a question a few hours ago, "how would you kill a named process"... This annoyed me on two levels, firstly, as I was put on the spot, but secondly I had already blogged about this exact problem just a few weeks ago...

The quiz master knew this, or rather they should have, given all the information they had about me, including this blog... So to ask tells me more about them, than my answering would tell them about me.

It tells me that they're working to a bare minimum investigative level, they're looking perhaps too much to their goal (which it to get answers they like) rather than checking anything produced before.

This would be a little like asking Sir John Geilgud, whilst interviewing for a country play.... "Have you done any acting?"

It frustrates me.

Sunday, 21 April 2019

C++: When to Cast Away Const

There's a rule, a very good rule, a brilliant rule, almost a law to not cast away const in C++.  There are legitimate reasons for this, and greater minds than myself have invented and enforced said coding standard.

Unfortunately, this doesn't mean there are not cases where you can use this technique, lets take a look.

So, modern C++ casts should always be used.  These are static_cast, reinterpret_cast, the dreaded dynamic_cast and as we're going to look at const_cast.  Where would I use this?  Well, in concert with good parameter conventions, we always want to communicate to the outside world what we'll use a parameter for...

class Foo
    int* memory;

    Foo(int* ourMemory)


We're assigning our memory to the class, but this constructor is communicating something back to the caller, it intimates that the pointer could perhaps, maybe, be changed as we pass it without the constant prefix.  A caller could then assume they must check whether the pointer has changed, become nullptr or whatever else.  That's assuming our API users are good people, which we all knows they are!

But, we don't change the pointer, we just take it into our member variable pointer.

We therefore have a dichotomy, the class may change the pointer along the way, but the actual constructor does not, this is a design decision, so assuming we communicate this back, I just want to make it clear the constructor does not change the pointer.

class Foo
    int* memory;

    Foo(const int* ourMemory)


Unfortunately you now get a compile error that "int*" can't be cast to "const int*".  So we need to cast-away the const in our constructor, like this:

class Foo
    int* memory;

    Foo(const int* ourMemory)


This is, pretty much, the only use case I can find in my own coding standards for casting away const.

Monday, 25 March 2019

C++ Variadic Template Compiler Optimizations

In my prior post we briefly talked about how the compiler unrolls a variadic template and we needed to provide the end-point function to stop that iteration, lets take a closer look at how the compiler does this unrolling.

The impact this has on your debug build is critical, and I demonstrate that you can see the unrolling of numeric functions (such as summation) but then in release the compiler is smart enough to optimize that all away and use a constant.  Understanding when this is happening is a crucial lesson, as we then see the action of a repetitive string output.

If you found these two little videos of any use, please life & subscribe on YouTube to let me know!

And as always the comments below are available.

Sunday, 24 March 2019

C++ Variadic Template Parameter Packing Example

Today in the brief few mintues I hate, I wanted to welcome all the new readers the blog is getting, there are nearly 5000 of you folks passing through these pages each month!

And now the code video....

Today we go over a usage example for variadic templates, demonstrating the new C++17 parameter packing, how to call functions with the parameter pack, how to mix parameter types with the template and control the compilers iterative unrolling of your code.

Find the source code here:

Find Fedor Pikus's new book here:

Please Note: Filmed in one take, during the single half-hour I have spare, so don't complain about the low production values, cus the code does at least work!

Friday, 22 March 2019


I don't like P4

Its not the best blog post after a fortnights silence, but it's all I have to say really.

Thursday, 7 March 2019

Mistakes Were Made

I had a lovely post for this evening, until a coworker pointed out it was utterly wrong... DOH.

Tuesday, 5 March 2019

C++ Factory Create Shared Pointer - Private Constructors

Back in 2016, I posted this little ditty about hiding the constructors but still enabling the use of "make_shared", this worked through a friendship between your class and the ref counter, but was sadly windows only.

At the time I promised the follow up for the same code for GNU, well I forgot, so here's the secret sauce, make your class as per that post, but friend it thus:

friend class __gnu_cxx::new_allocator<Foo>;

This only came up as I showed a colleague today and realized, I never got around to posting the other item!

Sunday, 3 March 2019

Home Network Upgrade - Part 1

This is going to have to be a multi-part series, firstly as it's a complex task we've got on, but also time constraints from both my side and also from suppliers delivering me kit means it's already spread itself over three weeks... and I can only imagine it's going to take a lot longer yet.

What am I up to?  Well, we're all settled in the new house and it's time to sort out the networking... Now I only have wireless at the moment, you may have seen my prior posts about the lost router?  Well, I found it... And I was wrong, it wasn't lost at the in-laws, it was lost here.... After searching the garage again, with the wife for that fourth time she finally believed me that it was lost (not just that I was being a stupid man) and she helped look elsewhere... We still didn't find it, however the next day at work my phone rang and on the other end was a joyous voice "I found it, the router, I found it"...

Yes, it was in a box in the garden!

Not open to the elements, but not fabulous either, anyway, router found I stuck it in place.  The problem now, I had two wireless networks the router provided one and the BT Homehub one... Easy, turn the BT Wifi off.... Which I did.

Except, that doesn't turn off the BT Wifi with Fon thing, the free access point for any BT customer to use.  And, I saw folks using my Wifi*

So, I hit the old interwebs and looked up a decent ADSL/VDSL modem replacement, the one which came up, from a video by Cameron Grey actually.  I ordered a Netgear DM200.

It looks quite nice, this is just an ADSL jack in and RJ45 jack out, it is NOT a wifi router.  But, this is an utter and total pig to set up folks, really a total and utter pain in the bum.... I tried three weekends in a row in six different sessions each of over an hour before it finally sorted itself out.

For those interested, flash the firmware to v1.61.  Give it power but no network connections plugged in and hold the factory reset button on the back for 30 seconds, then kill the power to it... Plug in the ADSL feed and connect it with a single ethernet cable directly to your laptop or PC.... Give it power and wait... and wait... and wait... until all three lights go green... If they don't after like fifteen minutes (seriously wait that long), only then remove the connections, but leave the power on factory reset again and power off, connect and power on etc until you get three green lights.

Then on your PC browser open to "" and get in there, and just run the Genie wizard, if ANY thing else comes up, factory reset!  Let it detect BT, enter the username as no password, nothing else and wait literally tens of minutes, it will get somewhere.  And when it's asking you to register on the netgear site pacify it with the "next" button until it is totally and utterly and completely done.  Only then open another tab and try a website.

When I finally got a website I then removed this hunk of trash.

Finally, no BT Wifi with FON sucking on my juices.  I set the DM200 into modem only mode, wired it to my Router and set up PPPoE with the username and password for BT again... Anyone wondering and BT, with VLAN set to 101.

And voila, I was back to where I was with my virgin router at the old address, I now have my nice router working nicely with a nice modem on this BT line... And it's about 5mbps quicker on my speed tests, the DNS resolutions (set to Google and CloudFire are around 30ms quicker too).  And I have more control over everything, I am so much happier.

But I'm not altogether happy, because the next phase of my work has been massively massively delayed, by like a year... Like this was planned for the old house... Fiber Optic.

Yeah, remember this box?

Hang on, lets be clear... THIS BOX...

Yes, they are fiber optic network cards... You might ask "Xel why have you so many?"... And I would have to blush and admit, I thought I was buying two as a test, instead I bought TWO JOB LOTS OF 10 CARDS!  So  have this huge box full of 20 fiber optic network cards.

The plan therefore is to put together a small form factor PC by the router and fit a fiber connection to it.   Carry that fiber line up into the loft and up there have a fiber optic router.  That's the ultimate aim.  But I want to do that test first, machine to machine... So, I fitted a card to my workstation and another to my my Xeon home server... All fine, drivers and everything fine, and I set about ordering a pair of short 2 meter cables...

And I wait...

And wait....

And a month later finally....

Oh yeah baby... Except, hang on...

I ordered a pair of cables didn't I... Didn't I... Yes, yes I did... How many are in that baggy?... Just one... OH NO JUST ONE!!!?!?!??!?!!  So, this is where I leave this project for now, it's been a long time coming, but I hope to get the optics test done, then we've got two runs of ether cat 5 or fiber to run from the router feed in down stairs to the loft and then to my office and to the garage.

As owning a garage, this is where I now plan to have the server rack, and running fiber to it may be my optimal solution, it may even be possible to get cat 5 into the garage easier than to the loft, so all the fiber might go in the garage, this is literally a plan in the process of being figured out as I find out the structure and layout of the house.

Stick around for more.

* I actually spoke to a neighbour about this, he said "Oh that'll be my lad, he connects to the as many BT Wifi connections for free, we don't pay for the internet that way".... Nice, thanks... 

Saturday, 23 February 2019

Its all a question of metier

I've had one of those moments, taking the wife to a new hair dressers, I had to sit and after giving up the pile of decidedly feminine magazines as a bad job I used my phone to crib up on a problem I'm having setting Code Collaborator up properly.

The problem aside, it's just one of those things, I needed to read the info.

About fifteen minutes into my reading and with many female voices cackling merrily away their 11 o'clock comes in with her husband in tow.  He takes the seat with me and we do the usual nod of the head and tut at the flapping the girls are all doing cooing and fawning over one another.  It really is all a bit beyond me, some form of communication is taking place, but I'm not certain what kind.

Alas, five minutes after our perfunctory nod and his going through the self same magazines he strikes up a conversation "you reading something good?"

I reply, good naturedly and we're washed over with a wave of cackling.

"Computers eh?" he says it like it's some mystery force in the universe, "our lads into them, doing his A-Levels".

I listen again, "Yeah he wants to go into using them, looking at his degree options and he got into Nottingham".

So, I do the dutiful thing, I ask what degree... I'm expecting computing, programming, systems or something...mathematical maybe physics at an outside edge.

"He's going to do English Literature"

I don't really think about it, I just ask what's the link to computers then?

"Wants to work with them".

And I can't help it, but we're in this rabbit hole and I ask "How does he jump from English Literature to working with computers?"

The guy fumbles a little here, I think this maybe the first moment he's thought about the tenuousness of the connection from A-Levels in Sociology, English Lit and Physical Education, a degree in English Literature and the wish to work in Computers.  But he gathers himself in a flash.

"He uses a right good laptop for his home work".

Game over, good night vienna, sensible has left the building.

Our conversation peters out some at this moment and I just leave him to this thoughts as my wife's done, but I can't help think about the metier here.  Computing is a goal, or the lad enjoys playing games, but he's studying completely unrelated topics, with no seeming extra curricular things, and he'll no doubt be out trying to get any computer related job, I don't know what, maybe sweeping out server rooms.  But he'll be cheaper than a qualified person in a computer academic bent.

Thursday, 21 February 2019

RAF Tornado Retires

I'm quite sad to see the retirement of an icon of my age, born in 1978 I saw the Tornado come into service and has a lad had a cool postcard poster of one coming into land, it was such a modern thing and to my eyes still is, the forward angle on the air intakes, the vaunted carrying capacity and the potential for this pan European jet to enter service and serve us well.

Which she has, the Tornado has been a mainstay for the RAF, its replacement isn't even clear cut, as the aircraft was so versatile, we see the Eurofighter Typhoon taking on the air-superiority and potentially some of the light strike capabilities, we see the F35 coming over from the US to augment the fighter force, but they're machines at the moment, they're things.  The Tornado for me, she has a certain personality.

Friday, 15 February 2019

Coding Standards - About Scopes (again)

Consistency is good, consistency is light, consistency is really what you need think about when creating code, no matter what format, language, platform or project you're on do things the same way, and even on your first pass do them your way consistently before you apply any locally demanded view of the code....

What do I mean by view?  Well, I'm talking about coding standards, but the non-functional side of things, hence the view.  You can look at code from any angle you choose, indeed there are multiple ways to achieve the same solution within code, the difficulty is to get things out there, put them down, then sort the wheat from the chaff.

I've done this in a couple of videos, where I move pieces of code from their own coding layout to my own, I have labelled these "coding standards", but in retrospect they've just the coding view.

One of my big points is the notation for the scope of variables, I love to use scoped notation.  Having been brought into programming when Hungarian notation was not only taught to you academically as required, but demanded by all projects you worked on (basically as you had no code completion tools, so knowing the type of a named variable whenever you utilised it was really very useful) but that was twenty plus years ago, now we have code completion I strongly feel your tools should be made to work for you.

Therefore, when I complete a call or variable name, I want that to communicate something to me, and the most useful is to check the scope, the code completion tells me the type and the name, but scoping isn't really fully covered in the tooling (please post below any suggestions for Visual Studio, Atom, CodeBlocks or Visual Studio Code which perform scope notation or checking on the fly).

When I complete my typing and pause I want to see all the m_ members together, all the c_ constants all the s_ statics and so many coding standards documents define these three.  However, it's just not far enough, what happens when you have locals named 'angle', 'view' and 'Gregorian'?  They're at very different points within the code completion window which pops up, you have to remove your hands from the keyboard to begin scrolling through them; or worse still start typing letters in order to guess the name (for instance we may start to type a c to see if 'Gregorian' comes up actually as 'calendar').

My solution?  The solution I've been pushing time after time, post after post, video after video?  Scope more things.

We can add "local" as "l_", parameters as "p_", we can compound them, so a static constant maybe "sc_" and we can tailor this in whichever manner we feel fits best, but be consistent.

Let me be utterly clear, this is not Hungarian notation of old, we are not adding "i" to integers or "l" to longs, we are not defining the type within the name, we are simply defining the scope and helping the tools to help us by grouping the various scopes of variables together.

I find it incredibly hard to read documents which go half way, defining members as "m_" (or just a leading m) is extremely common, ditto for constants and even statics, it's only with parameters people get a little squeamish.  "p_" is sometimes reserved for pointer, but that's a style edging back to Hungarian you're notifying the reader of the type and use rather than the scope, therefore I push "p_" as a parameter.  But I can also see arguments for "i_" and "o_" for parameters, which tell you it's an input or output to the function.  If one wanted to be a pedant you could go so far as to stress this with "pi_" and "pi_".

This isn't to say I'm for everything, for example in returning from a function:

int foo();

I will not define an "r_" as the return scope, I'm not interested in the semantics to that extent, and I don't feel code like this:

int foo()
int r_result(0);

... Some code to set r_result

return r_result;

Is communicating anything useful, so often in my code you will find:

int foo()
int l_result(0);

... Some code to set l_result

return l_result;

As the result remains a local until returned.

Which brings me back to my second bug bear of the month, one which I've already blogged about returning early.  I'll let you remind yourselves of my opinions.

And just a note to the world at large, if you're coding "m_" for members, but ALSO add Hungarian notations "m_iInteger" stop, stop it now... and yes that includes when you're doing pointers "int* m_pIntegerList"... argh, I want to pull my own arm off just to have something to throw at the screen when I see this one, it's a hybrid as annoying as the Alien in Alien Resurrection.

What's my solution?... Well the completely sane idea I use is "m_IntegerListPtr"... Yes, it's a pointer... I tell myself it's one, I'm not strange at all... Alright, maybe a little.