Showing posts with label annoying. Show all posts
Showing posts with label annoying. Show all posts

Monday, 21 November 2022

It's a C++ STL Rant : Constness and Vector Erase

I believe I am right and correct to be seethingly annoyed that this code does not compile...


#include <vector>
#include <iostream>
#include <algorithm>

struct Test
{
    const float value;
    int changable;
};

int main()
{
    std::vector<Test> items;
    items.push_back({42.5f, 0});
    items.push_back({1.23f, 1});
    items.erase(items.begin());
}

It just really annoys me this won't compile, do you know why?  Don't cheat, just have a look why does this PERFECTLY REASONABLE AND ACTUALLY I THINK CORRECT CODE NOT COMPILE?

Yes, because of the ISO Standard, and it's really annoying.

ISO/IEC 14882:2003 23.1 [lib.container.requirements] / 3:

The type of objects stored in these components must meet the requirements of CopyConstructible types (20.1.3), and the additional requirements of Assignable types.

The compiler could have been told this far more simply if the std::vector had an earlier and cleaner static_assert that the type is copy constructible before it got into the weeds of the real message we get.

For can't compile because it seems the standard implementation of erase results in a bunch of move semantics in the vector, which then devolve into copies.  And to my simple monkey brain it's all just babbling horrible template junk that comes out the compiler as well.

You can of course move a struct of type Test perfectly well, or at least mark it for move (cast it thus):

#include <vector>
#include <iostream>
#include <algorithm>

struct Test
{
    const float value;
    int changable;
};

int main()
{
    std::vector<Test> items;
    items.push_back({42.5f, 0});
    items.push_back({1.23f, 1});

    Test bar { 123.456f, 2};
    items.push_back(std::move(bar));    
}

This compiles and runs just fine!

But it's not copy assignable.  Let us take a look at the compiler spew:

In file included from <source>:1:
In file included from /opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/vector:60:
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_algobase.h:427:4: error: static assertion failed due to requirement 'is_move_assignable<Test>::value': type must be assignable
          static_assert( __assignable::value, "type must be assignable" );
          ^              ~~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_algobase.h:495:22: note: in instantiation of function template specialization 'std::__copy_move<true, true, std::random_access_iterator_tag>::__copy_m<Test>' requested here
                              _Category>::__copy_m(__first, __last, __result);
                                          ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_algobase.h:522:19: note: in instantiation of function template specialization 'std::__copy_move_a2<true, Test *, Test *>' requested here
    { return std::__copy_move_a2<_IsMove>(__first, __last, __result); }
                  ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_algobase.h:530:8: note: in instantiation of function template specialization 'std::__copy_move_a1<true, Test *, Test *>' requested here
                std::__copy_move_a1<_IsMove>(std::__niter_base(__first),
                     ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_algobase.h:652:19: note: in instantiation of function template specialization 'std::__copy_move_a<true, __gnu_cxx::__normal_iterator<Test *, std::vector<Test>>, __gnu_cxx::__normal_iterator<Test *, std::vector<Test>>>' requested here
      return std::__copy_move_a<true>(std::__miter_base(__first),
                  ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/vector.tcc:179:2: note: in instantiation of function template specialization 'std::move<__gnu_cxx::__normal_iterator<Test *, std::vector<Test>>, __gnu_cxx::__normal_iterator<Test *, std::vector<Test>>>' requested here
        _GLIBCXX_MOVE3(__position + 1, end(), __position);
        ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_algobase.h:656:44: note: expanded from macro '_GLIBCXX_MOVE3'
#define _GLIBCXX_MOVE3(_Tp, _Up, _Vp) std::move(_Tp, _Up, _Vp)
                                           ^
/opt/compiler-explorer/gcc-12.2.0/lib/gcc/x86_64-linux-gnu/12.2.0/../../../../include/c++/12.2.0/bits/stl_vector.h:1530:16: note: in instantiation of member function 'std::vector<Test>::_M_erase' requested here
      { return _M_erase(begin() + (__position - cbegin())); }
               ^
<source>:20:11: note: in instantiation of member function 'std::vector<Test>::erase' requested here
    items.erase(items.begin());
          ^
1 error generated.
Compiler returned: 1

We read this from the bottom up, first erase needs to call "_M_erase(begin() + (__position - cbegin())) what on earth?  Well it appears this is trying to perform a copy-move of the rest of the vector; the rest of the stack all the way to the top shows us various iterator types to the top two messages where we have __copy_m and then a compile-time static assert that the type must be assignable.

With the intentionally const member we can't compile we therefore have two options, first we make the member non-constant.  This isn't very practical because the type is derived from a bunch of runtime values, they're not known upfront and can be different for each instance of the struct.

The second option therefore is even less appealing and looks like this hideous mess:

#include <vector>
#include <iostream>
#include <algorithm>

struct Test
{
    const float value;
    int changable;

    Test& operator=(Test pOther)
    {
        float& mutableV { const_cast<float&>(this->value) };
        mutableV = pOther.value;
        this->changable = pOther.changable;
        return *this;
    }
};

int main()
{
    std::vector<Test> items;
    items.push_back({42.5f, 0});
    items.push_back({1.23f, 1});

    Test bar { 123.456f, 2};
    items.push_back(std::move(bar));

    items.erase(items.begin());
}

We define this assignment operator performing this const reference magic and just.... ergh, don't do this folks, just don't.  Not only is this an excellent lesson in const member flagging in STL and it's pitfalls.  But then it's also a lesson that const doesn't really mean const.  AND it's a lesson on whether you want to keep a constness or nor given such awful hacks to get around it.

I could even go further than this, the operator= could be made private and the STL type "std::vector<Test>" could be made a friend, or the __copy_m could be made a friend; though in that last case the MSVC implementation of the STL will be different, so we'll have to work around platform differences too.

No, the most annoying thing here is picking open quite why __copy_m wants to end up assigning.  I am still digging into why, but oh boy am I annoyed by this one.  For in a module I unironically had to repeat at University solved this in 1996.... I would use a linked list, and simply pluck out the value... or I would skip to the index of the item to remove and copy those after (if they were host memory contiguous then memcpy speed achieved) and just write over and this erase is achieved.

To just see this wanting to copy assign at the element level is just hideous, and I hate it, and I with the ISO standard would change in this regard,

Thursday, 4 February 2021

The most insidious file on Windows....

The most insidious file on Windows....

Microsoft.DataWarehouse.Interfaces.resources.dll?

This particular file lives in my 

D:\Program Files\WindowsApps\Microsoft.Office.Desktop.Excel_16050.11029.20108.0_x86__8wekyb3d8bbwe\Office16\ADDINS\PowerPivot Excel Add-in\sk

folder.... The key feature of that hideous path is that it's in my D drive... this is my second drive and you'd be right to ask why it has a windows installation on it?


Well, that's the drive that came with my laptop, and so it had the spyware, adware riddled carcas of a windows installation I never used, I just installed my own new NVMe drive and went with that.

This installation of windows has been taking up like 15GB or more of Space for over two years to it was time to nuke it.  The problem?  You can't just remove windows trusted installer files.

My way around this is to go into the properties, into advanced, set the owner user and god for that file to be me and remove the other windows junk user groups and such, and make sure everything is inherited down the line.... 

And I did this, removed windows, program files and windows and program data.... all except for this one file.

Which is totally insidious.

It won't disappear despite my being that very user/owner and even having used "runas" to launch explorer and cmd as myself for 100% certain.

The security settings can't be set....



It is literally moments like this where I hate that I can't fully control my operating system.

Sure, this is an edge case, who would really want to let windows delete something critical, but I've clearly worked around the issue, jumped through enough obscure hoops and set myself in the driving seat that the OS must know I'm up to something I know I'm doing... and I'm doing it with their UI, so not with some obscure script, so I'm clearly NOT a baddie.... sort of.

Yet, I can't delete a file, the file is actually zero length... it's just crud and evil.




Thursday, 23 July 2020

Drop Ships Dilemma

I'd never heard of "drop shipping", to me it conjure soldiers in heavily armed space-shuttles being flung pell-mell at the surface of an enemy planet with the winds of plasma and fire burning all around them.
However, what it actually means; apparently; is that you've bought something - say a chair - off of a reputable site like Amazon, but you did so not from them but seller on their platform.

This seller then doesn't actually sell you anything, what they do is contact their own network of suppliers and they buy the item for you and get it shipped by that third party to you.  The drop ship being that third party, to whom you don't exist, they deliver to your address as though you and your address is the middleman you met on whatever selling platform you chose.

And apparently, this is legit on some selling platforms, Amazon, Ebay etc etc.  The former put some extra steps in there, such as if you have an issue that middleman has to accept the return and handle the shipping, but this is a nightmare, because you use something like Amazon or Ebay for the protection the service affords, the expectation of easy and care free returns.

The trouble being, this middle man is only there to cream a little commission.

So my issue was a chair, is a chair - this is still going on - which I ordered from Amazon on the 13th, I didn't even clock it wasn't via amazon themselves, this chair has a brand and a name and was set to be delivered on the 20th.

Which came and went no sign, also no tracking, when these drop shippers do their thing they can keep their cards close to their chest, Amazon just ask that they've dispatched when they say they have ditto for ebay.

Trouble was this middle-man tried to tell me that they had called and left me a voice mail, and I'd not gotten back to them... .except, I don't have a voice mail, don't like voice mails... so they lied.

During this discussion they then said (bare in mind this is the 21st, a day late and eight days since ordering, which said "dispatched") it'd not even been dispatched, indeed it wasn't expected into stock with them until the 27th.

Silence.... I want my chair, I want to know when it'll arrive.

I still don't actually know whether this is a drop shipper or a scam.

"We have another chair, I assure you it's better, more expensive which we can get to you tomorrow".

Now, just because something is more expensive does not make it better, and I spent time picking this chair out on Amazon, it has all the bells and whistles I want... four major features and a comfy shape.

This middle man is persisting to send me details of another chair, and "if you agree I'll send that next day delivery"... this seems like a scam to me, but I don't even get to choose because the information never arrived.

I never saw the info, so never okay-ed it, I never wanted anything except the item I ordered.

Just now, I'm in the kitchen and I hear the letter box flap, and a van drive away... there's been no knocking, no noise made, just a note through the door "left with neighbour".

Hate my neighbours, but go find out what this delivery was... turns out to be a chair... Not the chair I ordered.

A quite ugly square one... with two features I ordered missing, made of plastic not steel, and a manufacturing fault along the top cushion.

So I call this guy up, tell him "I was expected to wait for the item I ordered, I never got the info, never asked for this item, it's the wrong chair and missing features and made of the wrong material".

"This is a more expensive chair" he says.

It certainly doesn't look it, and even if it arrived with gold bullion stuffing the cushions I'd return it because it's not the chair I ordered.

This guy is getting on my nerves, and that's when I realize I've been drop shipped, this guy is in an office himself, this is "his business", but he's clearly at work doing something else, he's not a chair saleman, he's just acting as a middleman.

So back to the selling platform, Amazon... who... seem to be quite happy to let 48 hours pass until they will even talk to me, to give the guy time to reply to me...

I therefore am out of pocket, still without a chair, and frustrated by this whole mess.

I think Amazon need to make a very much more clear distinction between the items sold and delivered by them and items being drop shipped like this or worse.  "FROM AMAZON" in a big clear type.

There's even issues there, for instance I've seen resellers listing parts like say "Intel CPU's" and it'll be listed as "by Intel"... but it's not being sold by Intel at all, sure it's made by intel, but "John Doe Computer Tech in Driotwich" are the seller on Amazon, and really we need to be told that more clearly to avoid the kind of situation I'm now in.

Wednesday, 8 July 2020

Waste Management or Disposal

This is fine, the BBC have released this film to highlight to us mere tax paying mortals the problem affecting the environment... Personally, I loath when I see any waste discarded, fly tipping being my personal bug bear in Nottinghamshire (a land-locked county).


Good, great we all know...

But realistically what can we do about this?.... Well, we, or at least I certainly, pay my council for refuse collection services, they come each fortnight and take my waste away.  Any excess I store, compact and take to the local household waste site run by Biffa.

These are council services, they are firms whom have tended to the council to responsibly collect, manage and dispose of my waste on their behalf, and I as a customer of the council expect it to have been done responsibly.

Maybe, I should contact the council for an audit trail of where my waste goes, but I'm pretty sure the council would say "they collect it, and they dispose of it".. and way back when in the mists of the negotiations for that lowest rate possible waste collection service there was a plan probably waved about in front of a Councillor or clerk and it was accepted as the planned disposal method.

And across the whole country there will be similar, if not identical, sets ups with each and every council, from London to Llandudno, from Nottingham to Norfolk, everywhere in the UK the waste is collected and managed by councils.

So this piece of journalism by the BBC, though informative and ghastly, is really pointing the stick at the wrong folks, we can't opt out of council waste collection, one can't selectively only pay for part of the services afforded by our council tax.  If we could then one would be able to opt in and out of anything, chaos would reign.

The responsibility to dispose of this waste therefore, rather than it end up in the ecosystems of our planet, is that of the collecting agent, they took our money for it, we put our trust that its being fulfilled, and if not perhaps those councils need to be brought to account, rather than this kind of video make me feel guilt.


For I do feel guilt.


But there's very little practical steps I can take to dispose of my waste through any other channels, or companies.  I can't incinerate it myself, I can't bury it anywhere myself, I can't recycle things myself, they are large industrial tasks which is why I pay my fee and clearly hope for the best.

But the best isn't good enough.  Councils of the United Kingdom, sort this one out.

Saturday, 20 June 2020

CubeWorld - Where's my key?

I bought CubeWorld back in the day, and I just heard it was actually released, this really annoys me that I've heard it's been out ages... and apparently wasn't as good as the demo even in the end.

But the really annoying thing is that apparently early buyers like me were meant to get a code to play the game?!?!

Where's my game key?.... What a total cock up he made of that game.

Thursday, 18 June 2020

Brain Dead Boring Boomber Bastards Next Door

Its been over a month, so I've come to terms with something... Some people are just horrid.

We'll just dial back the clock, 1945.... VE Day... All four of my grandparents were serving in the war effort, Solider, Sailor, Nurse & Land Army Girl respectively.  It was their war, their life, and I respect that immensely.

I made a video to that effect a head of VE Day.


However, with the lockdown, my wife and I, being in at risk groups didn't plan on anything for a street party out front, not least as our neighbours, as already mentioned in these pages, are quite abhorrent people breaking the rules and putting themselves and others at risk, but we also had no idea there were any such plans a foot... After all, why risk it when we and all of them are in at risk categories?!?!....

So, we sat it out, rightfully and with respect, I do spend a lot of time with my mind cast back to the world wars and I don't think any of my neighbours, unless there's some secret military historian in their ranks, can touch my knowledge of the struggle and suffering inflicted.

It was therefore with some surprise that I've heard on the grape vine how "disgusted" our direct neighbours were of our "ignoring VE Day" and "disrespecting the spirit of the day".

These fools haven't dared say this to our face, these brain dead boring boomer bastards won't face me and say a word, and you know what... that makes them pretty horrid in my book.

Friday, 15 May 2020

Goodbye Childhood Confidence

My best game of charades got crapped on... This is a grudge, a very old grudge, for this happened when I was 8... Yeah, I don't let go easily.

It was a life lesson, which put the nail on my opinion from experience that as a child adults can be dumb and remain so outside of their own specific fields of interests, and will miss no opportunity to knock a child's confidence.

What was this about?  Well, it came after a string of little things where adults put me down, my mother would not accept that "ambulate" is a word... And before you start to say "why didn't you just google it and show her?... well, there was no google, this was the 1980's.  There wasn't even a dictionary in the house!

She'd also in correctly corrected my mental arithmetic on numerous occasions, which set me on the path of a life not trusting my own number skills for life.

TL;DR; I'd had a load of adults putting me down...

Anyway, the story.... I go to school this day, you know school; where all the teaching staff encourage learning and being clever like.... Well... No.

On this day, we were all given over to full charge of the schools one teaching assistant, because the teacher herself felt very ill, the teaching assistant, who I will call Mrs C, had no idea what to do with us so we played charades.

Each child was asked to think of a TV show they had watched the night before and to come up with a sign or gesture for it without speaking and we each had to guess the show.  Recall there were only 4 TV Channels at this time, and most of us played out right after school or our tea, so pickings were slim.

Eastenders was signed by one girl pointing east and clapping the drum motif.

Coronation Street was signed by a boy making out a crown on his head and walking about a bit.


Things dried up a bit, "The Bill" was two lads walking around slowly flicking their heels a bit, we all thought they meant a dance show.

Then after a lot of silence, and I was a shy child, I decided to give it a go with the last show I was allowed to watch.

I stood and I performed a wave to everyone, waving and blowing a kiss across the room, then bent down and stroked an imaginary dog at my heels... A pet dog.... A wave goodbye and a pet dog.... A goodbye and a pet... 



I thought this quite clever, I remember watching the men in the show in their bunk room, never really paid any mention to the plot nor story, it was something on the TV and I knew that the words were "goodbye" in German and "pet" was added to affect a geordie accent.

And the teaching assistant, clearly knew what I meant and rather than be encouraging, as she had been to the other kids, who worked in pairs or made only strange motions to intimate their thoughts she shat all over mine.

Like proper shat on me from a great height.  "Don't be ridiculous, how was anyone going to get that?"

Was it my fault you lot can't speak English, or work backwards from "petting something" to "pet" to.. Oh the only show on one of the 4 measly channels last night has the word Pet in it, even if you don't know the funny foreign words because you're 8 English and this is the era before the Berlin wall came down and Germany was a distant ignored memory from old war films and Grandad's recollections of their not liking it up them.

I've never let this go... Not even now.

Saturday, 21 September 2019

Annoying Neighbours Update - The Solicitor Speaks

How have things gone with the annoying neighbours?.... Well, from bad to worse, though they'd argue otherwise.

A turn up for events, which gave us hope they'd seen things with a modicum of empathy they started to park one of their cars in front of their house, not in front of ours.  The other one remained where it was, but remember we'd been told they planned to clear the garage out and move one car into their.... So we were under graces that there'd now be one car out of sight and the other in their own double garage.... NO MORE CARS ON MY LAND....

Except, immediately, this meant they had one car parked and a space.... or what everyone coming to their house took to be a space... and they had a slew of visitors, ranging from a few hours to overnight stays, all coming and going too-ing and fro-ing using the right hand end of my drive as their parking spaces.

It struck us immediately that they've only moved the car to free up a space and please themselves, it was NOTHING to do with empathy for us.

We've tried to speak to them, we've sent them a nice letter setting out a few rules and granting basic permission so long as they tow the very thin rules, but to no avail, we've tried to mediate and let them but giving and inch simply seemed to see a mile taken.

It was solicitor time.

We actually spoke to our solicitor in July, he's asked us to just sit on the topic, see if it was a one off and to be stern with ourselves to ask "are you being unreasonable", but then these visitors started and then th eguy began using the area as a place to drill out and nail length of wood - nails or gawd knows what potentially going down the hill onto my drive - and then with the doors open on thei double garage all summer as he's been "working" in their... it became apparent it was a joke, they'd unilaterally decided to convert part of their buildings for another use and their solution to parking was to just park on my land.

So, our solicitor did his thing, and he turned up an interesting covenant from the original construction of the houses..... That the occupants of that house can not do anything which disturbs or which causes a loss of environment for occupiers of my house.... This was set out in 2002 when they were built.  There is apparently an auxiliary list of things, like not parking a vehicle in front of the garages, no vehicles, caravans, storage units or other unsightly items to be stored unless explicitly agreed and not for more than reasonable for the purpose of access... So, lets say they were moving house and they hired a huge van, they could ask and I would reasonably say it could be parked there maybe over night, or for a few days whilst they moved... see... but not for ever, not the norm.

Our solicitors letter was quite to the point and polite.  We know it was sent yesterday.... it clearly just arrived.

The woman from next door is literally out stalking the street telling anyone and everyone who'll listen of her plight.  I'm sure she's making something up about her being old and their having been reasonable, and it being us whom are unreasonable.

What she doesn't quite get is, I'll hear all this, I'll hear what she's been saying, I'll extend my solicitors instructions on any defamation occurring.  And that we're in the right, we have all the photographic proof of cars routinely being there and coming and going, visitors, family and their own... Which are not just for access, but are to park literally occupy that end of my drive way, in full or part the cars are parked on my drive that's the point.

And you may recall my attempts to speak to them:
* Moving in day - totally overwhelmed me, gave them verbal permission to carry on as we saw no harm.

* Easter 2019 - verbally he approached me to check whether being "so far your land" was acceptable - for you and your wife yes - and he immediately had visitors, a camper van thing and then his daughters parking all the time, they'd even go so far to move their own car down onto the road to make space for the vistors to park (and these aren't infirm visitors, these are fully able bodied people - before that comes up).

* Camels back - The incident of my asking them not to park cars there and the guy went crying at me, then crying at the other neighbour, and then later his wife came over and when I asked about the cars not parking there, especially the large camper van thing she said "Camper van, do you not know how much that cost?" - I don't really care love, move it.

* The massive blow out - their visitor had completely blocked the drive the day my Rabbit needed vetinary care, utter nightmare... But they didn't even have the decency to talk to me about it.  This was when the next day, I stopped to just heads up about it, I was even going to say "That's not your fault he'd parked there, just ask them to move, no biggy" - and the guy just literally moaned at me and waved his hands as he could not be bothered with me...

Solicitor time, done, lets see what the idiots say, we've been basically advised if they've got a large double garage and have found a space besides their property for a car anyway, they shouldn't be parking at all in front of mine ever and a judge would essentially conclude they have adequate parking and their repurposing the building shouldn't impact on the use, enjoyment of environment of our property.

This whole thing is long since due, as we understand it, the vendors who sold to us; very sneakily not mentioning these issues; moved partly because of this issue, except they themselves had enflamed the problem by blocking the right of way... Instead of talking and checking their rights, the old fella who lived at mine before me just pulled his cars forward to completely block the road... which put him himself at a loss.

So, here we are just shy of a year of moving in, finally getting it down official, don't park on my land kids, go park on your own or the road, enjoy!

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.

Tuesday, 18 July 2017

Speak More Slowly Please

I'm English, this means I speak English, or at least a dialect of it... This mere fact has furnished me with the ability to communicate to a myriad of other people, of different nationalities and inclinations.

However, it completely alienates me from the French.

Well, a certain sub-set of French speakers, whom simply are rude... Now, I'm sorry, but these people exist, and good on them, they want to protect their beloved French language from the likes of me, coming along speaking it with a terrible rich British Midlands accent.

I accept that.

I'm not trying to compose poetry in French, I'm just trying to communicate with someone, so when I say:

"parlez plus lentement sil vous plais, je ne pas parlez Francais bon"

I think I'm asking them to speak more slowly please, as I don't speak French very well.  I don't expect them to stop the conversation completely, roll their eyes and then turn their back on me.  That's rude.

And this wasn't an isolated case, since the mid-90's it's happened a few times.  And every single time it annoys me more.

When a French person speaks to me with strongly accented and semantically incorrect English, I of course listen to them, I'll even take a stab at working out what they were intimating, I'll smile and maintain eye contact, reassure them they are okay to just try... Very much a "we'll get there together" feel to the conversation.

Some French speakers however... Just Rude.

There, I've said it, I'll leave this here....

This post also may give away why there's been a small break in posts for the last half month... No I've not been anywhere, but I have been extremely busy.

Wednesday, 4 March 2015

C++ Cock Ups - Tips on Programming C++

Spot the problem in this code... I've just summarily rejected a piece of code from a developer, and they're being really really pissy about it, they're in fact being so pissy they've been moaning about me in the kitchenette at the side of the office, and the people they've been pissing and moaning at about me have been coming to me laughing that the guy can't work out that he's in the wrong and his code is shite.

Now, I'm not able to post the full code, it's a commercial product, however, I will give you a quick over view... Here's a sort of example:

#include <iostream>
#include <sstream>
#include "CString.h"

char* IntToString (int value)
{
std::ostringstream s;
s << value;
return s.str().c_str();
}

int main (int c, char** v)
{
CString str (IntToString(c));
std::cout << "There are: " << str << " parameters" << std::endl;
}

Now, this is pretty much how part of his program looks, that "IntToString" function is taken straight from his code, and it's horrible, but he really can't see why...

So, can you see why folks?...

Right, well, first things first, and this is the elephant in the room... Why the fuck has he reimplemented String?... He's written his own "CString" function to wrap character pointers as strings of characters, and he's done a bad job of that because he's done this:

char* buffer = new char[256];
delete buffer;

Yeah, see the mistake?... He doesn't, I've pointed out "delete[]" to him several times elsewhere.

But, yes, despite using the standard library for "string stream", he's not used "std::string"...

So, changing the code above:

#include <iostream>
#include <sstream>
#include <string>

const std::string IntToString (const int& value)
{
std::ostringstream s;
s << value;
return s.str();
}

int main (int c, char** v)
{
std::string str = IntToString(c);
std::cout << "There are: " << str << " parameters" << std::endl;
}

So, we've used "std::string", we've fixed the return type to be a constant, and also made the value input to the function a constant reference, so we don't copy the value into a new integer before passing to the function - I know a 4 byte integer is trivial - bit imagine copying a 2MB class, or a 35mb image before passing it!

However, I'm still not happy with this code... In this project, in all my C++ projects the boost libraries are always made available, they're built ont he platform for the project, and go along with it as a "contributing" library of helpers, to stop people reinventing the wheel.  On the office wall, printed on the notice board in the very kitchenette the moron has been moping around in there is a print out of several template functions we lilke to use.

These template functions are also included in a "Framework.hpp" file, which I tell all contributors to use, inside there is a function:

#include <string>
#include <boost/lexical_cast.hpp>

namespace Framework
{
class Helpers
{
private:
Helpers() {}
public:

template <typename T>
static const std::string ToString<T>(const T& p_Value)
{
std::string l_result("");
try
{
l_result = boost::lexical_cast<std::string>(p_Value);
}
catch(const boost::bad_lexical_cast&)
{
// Report
}
return l_result;
}

template <typename T>
static const T FromString<T>(const std::string& p_Text)
{
T l_temp;
try
{
l_temp = boost::lexical_cast<T>(p_Text);
}
catch (const boost::bad_lexical_cast&)
{
// Report
}
return l_temp;
}
};
}

These functions let you convert any type to and from text easily, and you don't reinvent the wheel...

Someone did point these out, "Why not just use helpers in the framework?"...

Which would tell me to do "Framework::Helpers::" and see what the code completion came up with, at the very least, or just to go look at the Framework.hpp file, this guys response was apparently:

"I can't, the constructor is private, and when I make it public I can't see the to and from string functions in the instance of the class I create"

Just, the... ah... This is a "graduate" programmer, who considers (at least according to his CV) himself an expert user of C++ for over 4 years, expert in C++11.

I swear to god, the guy is testing my patience to the max, not least because he just moans all the time, and most of the time, it's just his being shite.

I mean, I've moaned before, moaned whilst coding systems, whilst coding parts of things, sometimes warranted, sometimes not, but I don't think I've ever put my foot as far in my mouth as this guy has ever, ever!  And I once accidentally text'd a manager pondering why said manager was such a wanker!

Hey ho, I wish the office was not open plan, I'd like to take the guy aside and explain to him these problems, thede deficiencies in his knowledge, but there's no private space, I may send him a mail asking him to hang back to talk when others have floated out, most of the other developers disappear after 4, and all are usually gone by 6; it's only myself doing the later hours in general.

Wednesday, 4 February 2015

I broke Amazon

I broke Amazon... I've had an item on order since Monday, and at the time of ordering it was listed as in stock and I even paid for expedited delivery...

When on Tuesday it'd not been dispatched I really wondered why, so asked, but had no immediate reply, four hours later I started to chat with them and not only did I get my expedited payment refunded, but they insisted the item would be sent for delivery 1st class.

Unfortunately, since then I've seen the item appear as "Out of Stock", as "12 items in stock", as "Back in stock Friday", and as "In Stock"... So I've not been confident it'll be delivered.

Today, it's still not listed as dispatched, but it is still listed as "In Stock", however the price has risen £20... From Monday to Wednesday, £20...?

This is sold and dispatched by Amazon... I dunno, maybe my query cost them to answer, so they upped the price.

Either way now, if I get it before the weekend I'll be ecstatic, but just to get it for the original price I'll be happy...