Monday, 25 April 2016

Embrace C++14 Please Mr Developer

Today I've had to spend sometime setting up a Xenserver, to host some virtual machines, the moment I was done, of course the first request I had was for a developer to have a Linux machine running a compiler.

I was quite excited, in a C# & embedded C strong company to hear "C++" as the reply to my query "what language are you going to use?"... However, my excitement quickly evaporated when I asked, "What version of C++ do you need?"... And he replied "There are different versions?"

After I had explained, yes, yes indeed there are... I took a look at his code for him, and pointed out naked pointers:

char *something = new char[28];
memset (something, 0, 28);
delete something;

I quickly explained, as kindly as I could, that this code is not only wrong, but very very old hat, and I introduced him to the standard library:

#include <string>

std::string something;
memset(&something[0], 0, something.size());

And his eyes opened a little... He asked what version of C++ is this in???... C++98... and his crest fell again, realising it was very old tech, which he had no idea about.

So I pointed him to C++14 and explained smart pointers as something for him to try out:

#include <memory>
#include <iostream>

namespace Xelous
class Test;
using TestPtr = std::shared_ptr<Test>;
class Test
void Hello()
std::cout << "Hello";

int main (int p_argv, char** p_argc)
Xelous::TestPtr instance = std::make_shared<Test>();
std::cout << " World";

So, once this was done, I left him reading a copy a Tour of C++ by Bjarne, and told him to read all of Scott Meyers books.

This is a sad state of affairs for a programming & technology environment, especially when I know the chap earns more money than me, and as polite as I was I did want to just ask him to get his coat, and I'd slip into his salary grade & comfy company car (a perk I don't get).

Not least because I think the chap whom sent me off to speak to this fellow treats me a little more like a trained monkey, and they've themselves no idea about virtualisation, servers or development, beyond say using Turbo C++ from the command line in DOS 6.22... And unfortunately, things have moved on a lot since them...

Anyway, this leads me to tomorrows post, which I'm drafting, I set this C++ developer on the path to C++14, and installed him a Ubuntu 14.04 virtual machine on my little server... He was amazed, until he wondered over to me and pointed out that he had to manually add -std=c_++14 to the build options, and that sometimes the code-completion crapped out on him... Seems older Codeblocks instances fall on their face, and the default version of gcc/g++ on Ubuntu is 4.8.x and we need 5.x for C++14.  The next post will cover going through setting this up from the command-line.

No comments:

Post a Comment