Friday, 3 August 2018

Junk Hunt - Strange Typewriter Thing

I'm on the hunt for information, or even the actual thing... What thing?... Well, in the early 1990's my parents took me into a stationary store in Nottingham, I think it was Staples or Office World near the Post Office main buildings, so we're talking St Anns or City Centre ish, certainly behind the Victoria Centre.

Anyway, in there I saw a machine I was sorely tempted to get, it was a semi-electronic typewriter, so it had a form factor about 11" a typewriter keyboard with an LCD screen across the center, you typed could see the text then when you hit enter it write it to the typewriter as a nearly silent printed line...

It also simultaneously write this as an ASCII text file onto a 3.5" floppy which was inserted into the right hand side.

The one I saw was red, cherry red.

The print was a very strong, black, the ribbon was a one use thing once it had put a letter down if you came over the same piece of ribbon (by winding it back) and put another character it'd be missing the bits from the mask cut by writing the prior letter.

And... I loved it.....

I went to see this thing about six times.  I really wanted it to augment my then A-Level studies.  because it was silent, the keyboard had a tactile feel, but no click, the printing was this nearly silent swish and you got the text file from it... or you could put a text file into the disk, load it and it'd print the whole thing out in this lovely type.

Remember, at home I was toting a 9 pin Citizen 120D+ printer, so this really vibrant printing really appealed to me to present things.

If you have any idea what device I'm talking about, comment below!

Monday, 23 July 2018

Microsoft's Noexcept Code Throws Exceptions

I've not dug into this one fully yet, I'm mid-stride on what's going on, however the stack has unspooled me to this location having thrown a read access violation...


But can you see the problem here?  I'm in Microsoft's xstring, as far as I'm concerned this is from my using std::string or std::ostringstream, the function is decorated "noexcept" yet its throwing an exception!


I find this mind bendingly annoying, not least as under GCC & clan on Linux it runs perfectly fine!

So, this is "Unhandled exception thrown: read access violation" in xstring _Equal which is decorated noexcept... Time to format c: and never use Windows I think.

Saturday, 21 July 2018

C++ : Coding Standards by Example #1 (with Boost Beast)

Today I've spent sometime doing a little different video, rather than just play about in code, whilst I played about I made a video of the time I had... Here is it...


We cover:


  • C++
  • Coding Standards
  • Structured Programming
  • Functional Programming
  • Encapsulation
  • Object Orientated Programming
  • Building the Boost Libraries (1.67.0)
  • Visual Studio 2017
  • Static Linking

And generally spend time seeing how I turn gobble-de-gook code into something usable and maintainable against my own Coding Standards.

Get the code yourself here: https://github.com/Xelous/boostBeast

Friday, 20 July 2018

That Moment...

That moment you get half an hour into watching Brad Pitt in War Machine and the wife suddenly asks....

"Do you know him?"

"Who?"

"The actor!"

"Which actor?"

"Him with the grey hair?"

"The General?"

"Yes"

"Brad Pitt"

"Fuck off, that's not Brad Pitt"

I gave up.

Thursday, 19 July 2018

C++ : Copy Constructor versus Ignorance

I've spent a bit of time reviewing someone else's code recently and I've come to an impasse with them, so they have a lot of code which will take some standard container, and the code doesn't just initialise the local copy from the passed in reference... No it'll iterate over the list of elements adding them to the class version.

I have picked fault with this, it's not RAII, it looks ugly and if you're threading you can create your class instance and the member is empty or in a partially filled state before the loop within the constructor is finished... I highlight this in red below...

My solution?  Just initialise the member from the reference - see the green highlight in the code below.

My results from the timing below?



These times are "microseconds" so tiny... But with just constructing from the existing reference we always get a lower time, quicker code...


Running this test 30,000 times, trying it in different orders and with maps of upto 1000 elements I had a rough average increase of 60% speed by using the copy constructor of std::map rather than reallocating new memory for each pre-existing element.

I wanted therefore to understand the reasoning behind the original code, was there some reason to perform a clone (alloc and assign new instance) operation for each pair in the map being passed in?  Looking at the code there was no apparent reason, so I spoke to the developer, asking why they had performed the construction in this manner... Their reply...

"That's how you initialise a container"

You can load up a container in this manner, but you already have the contents of the map, you're just copying it... "Why don't you use the copy constructor?"... I asked...

"I didn't write one"

Hmm, "You don't, the compiler generates it for you, std::map has its own copy constructor".  Use the copy constructor folks, trust me.


#include <map>
#include <chrono>
#include <string>
#include <iostream>


using Mapping = std::map<int, int>;

class A
{
private:
Mapping m_TheMapping;

public:

A() = delete;
A(const A&) = delete;
void operator=(const A&) = delete;

A(const Mapping& p_Mapping)
:
m_TheMapping(p_Mapping)
{
}

A(const Mapping& p_Mapping, const bool& p_Other)
:
m_TheMapping()
{
for (auto i : p_Mapping)
{
m_TheMapping.emplace(i);
}
}

inline Mapping& Mapping()
{
return m_TheMapping;
}
};


int main()
{
Mapping l_m
{
{ 0, 0 },
{ 1, 1 },
{ 2, 2 },
{ 3, 3 }
};

auto l_time(std::chrono::high_resolution_clock::now());
// Copy Construction
A l_map(l_m);
auto l_timeB(std::chrono::high_resolution_clock::now());

auto l_Dur(l_timeB - l_time);
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(l_Dur).count() << std::endl;


auto l_time2(std::chrono::high_resolution_clock::now());
// Clone Construction
A l_map2(l_m, true);
auto l_time2B(std::chrono::high_resolution_clock::now());

auto l_DurB(l_time2B - l_time2);
std::cout << std::chrono::duration_cast<std::chrono::microseconds>(l_DurB).count() << std::endl;
}

Tuesday, 17 July 2018

Preach at the Bar?

Oh its been a long hard fortnight, delivery of project at work and the World Cup took up most of the last week, my cars (yes both of them) have cost me a total of £1,100 so far and one of them is still broke... Hence I'm broke.

However, I've been working on a project this very evening and whilst doing so I spotted something rather odd.

You might have thought the Preacher was busy sorting out the festivities at PreachCon, however, I think he's been moonlighting on us... No he's not been playing a game other than Warcraft... Oh no... He's literally IN another game... Take a look...


From NeebsGaming's video of Drunken Bar Fight... Uncanny Valley or what mate!

That's the Preach!  No-one knows where Ghosty is though...

Sunday, 8 July 2018