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.

Tuesday, 3 March 2015

Elite Dangerous - Trade Tool Sneak Peak - Update - Progress Pt12

I have been starting to set up to record my programming and testing... Here is a test stream - I didn't have my joystick plugged in, hence the erratic flight, but you can see me pop up the trade data and it quickly find me a worth while trade in system.


Update: You can now support this project at Patreon!

Monday, 2 March 2015

USB 3.0 Storage Project

This weekend has seen the final parts of the server infrastructure I had powered down, and this leaves me with a gap in my storage needs.

I carry two mechanical harddrives, old laptop 2.5" drives, power by 5v with me most of the time, but these are getting old (and they were already old before I pulled them out of the retiring laptops they served) they're also quite slow and I have no back-up for them.

This is a situation which can not continue on my conscience.  Therefore, I've just bought a pair of 32GB USB 3.0 flashdrives, a cheap USB 3.0 hub and a hot glue gun.

The project is going to be to strip an old 3.5" hard drive, even dremel the middle out of it iff needs be, and after stripping the hub and sticks of their plastic shells, mounting them inside the old hard drive shell.  Screw the shell back up and hopefully I have a 64GB storage space, which is none-mechanical, and which I can just plug-in and go.

Initially this is going to be for moving some recorded files around and perhaps holding a git repository, or even my old SVN respoitories for checking or supporting projects.

If it's a successhowever, I maybe looking at a nicer strip USB hub, and slowly building 64GB sticks at a time (£10 a pop) to build up a big drive, with a full back up script etc.

I may also be getting together a USB 2.0 hub and a couple of 8GB flash drives to act as a storage backup on the web-server, this will be for the Elite Trade data to be dropped off on.


Or this lad has the idea...

Saturday, 28 February 2015

Gaming & Films - Blade Runner 2 - Robin Hood X

What has been going down in groove town?... Well, I have to say, Elite wise, not a lot... I've been very busy with the office job, doing 12+ hour days all week.

I've finished the project I was on however, and am happy to sit now puzzled that everything was such a rush, because unlike some other developers around here, when I say something will get done... I do it.


Immediately, I just think.... "NOOOOOOOOO"..... A long strong voice, showing my lineage as a chronic moaner and critic... Just... "Nooooo"....

This then came to my searches and it sums things up....


Or perhaps this.... 


But, I dunno, we're yet to see Ford in the new Star Wars, maybe he can still act and this isn't just like letting Paul McCartney still sing (he can't sing anymore, if you didn't realise and his nurse hasn't told him).

More closer to home, I also spotted this film ditty...


Yes, a "Pirate's of the Caribean" style hood romp... Hmm... I wonder if like "Into the Woods", it'll be a fucking musical?!?!?


So, if I'm not up to Elite Trade Data code, what am I up to?... Well, the office is nearly all sorted, I'm also signed up to Twitch now, OpenBroadcaster and some other options are being tweaked about with, so expect some live streams of gameplay, of development and perhaps even a special once a week segment of the wife hassling me whilst I play (this is particularly funny, as she doesn't know anything, but insists on playing Zombie games, then complains how gorey they are!).

Expect to see more gaming content over the weekend!

Friday, 27 February 2015

The World Reacts to the Mighty Jingles - #10 Germany

We've all wondered, haven't we, what happens when Jingles releases a new Video?... In this new series I aim to help solve that mystery.... This week, we catch the German Chancellor receiving her fix via Mobile


Check back each Friday at 18:30 UK time for the next thrilling instalment, where might we find Jingles being Enjoyed?

Tuesday, 24 February 2015

Working with Taiwan Twinglish Embedded Development Kits

You know sometimes, I wish people would just write a manual.  I've just come across a chap who wants to sell a development kit to the company I work for, he's in Taiwan and very excited, he knows all about his kit, and he's been on the phone bulling it up for the boss.

He has ticked all the boxes with the boss, and they've gone a head and ordered the extortionately priced item, and it's arrived on my desk.

I took one look, and asked "Where's the manual", there isn't one.  Because this is a development kit... Right, what power does it take.. No-one knows, the only way to tell has been to look at the chips and see what the lowest possible power feed should be to the lowest value chip.

Which prong was the negative?... Only could tell that by tracing - by eye - back from an obvious earth plane and a couple of large caps and checking that the line was the negative rail.

This level of just basic documentation, being lacking, immediately makes me worry about the whole bundle.

They're trying to sell this, but I think they're actually trying to get a native English speaker - i.e. me - to write their manual for them.

Next thing, how do I build software to run on this kit?... They don't know... Seriously, this is what the chap has said to me, "It in C, write in C"... okay, what compiler you got?... "We no got compiler"...

So I have to go to the chip vendor and ask for their compiler?... These people throwing this kit together don't have a compiler?  And don't have any recommendation of which compiler to use?....

Luckily I can look at the board and see the processor, so I know what architecture I'm going to target, but I was about to ask "What's the architecture", and I'm pretty sure he'd not know.

How to get the software as built onto the kit, also seems a mystery, there's no obvious portable slot, no ethernet, no USB, no serial... I can't believe I have to burn EEPROM's and plug them in... In this day and age, I've been told "Firmware take your software in, firmware do it"... but not been told how.

I swear, I could pull the last shreds of my hair out with this, not least because I have to appraise this for use by our whole UK arm before this guy jumps on a pre-booked plane ticket from Taiwan over to here.... Gah

Friday, 20 February 2015

The World Reacts to the Mighty Jingles - #9 India

We've all wondered, haven't we, what happens when Jingles releases a new Video?... In this new series I aim to help solve that mystery.... This week, India and this one cool dude is Swapnil Desai.  Some say he's developed a voice command recognition system; I however say he's ready to get his Jingles Fix!


Check back each Friday at 18:30 UK time for the next thrilling instalment, where might we find Jingles being Enjoyed?