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.