Jason's Development Blog

Life

Unit Testing and C++11

by on Jan.16, 2013, under C++, Code, Life, Programming, Technology

TDD - All Code Is Guilty Until Proven Innocent Merry Christmas and Happy New Year to all! Hope you’ve had a blast over the holidays. I know I have. I went to my first Company Christmas Shindig. It was great, I got to wear a dinner suit and drink from an open bar. What more could I want?

Now, on to the coding! Lately I’ve been using a lot of C#. It’s what we predominately use at work, which explains that one. Naturally, we try to deliver the best quality product possible, and one of the techniques we employ to do so is test driven development. To accomplish this we largely use NUnit as our testing framework and Moq for mocking out implementations of interfaces. And on average this works very well.

Now in my spare time I like to occasionally code. I am not willing to give up a hobby just because it’s also a career. Now, C# is great and all but I like to spread my wings, stretch my legs and explore other languages. And most modern languages have pretty good support for TDD. C++ isn’t a modern language. In programming terms it’s steampunk, Victorian fashions realised with modern designs. It’s unit testing and mocking libraries are not quite so easy to use in a TDD context.

I tried with quite a few, and had some reasonable success with UnitTest++ combined with Google Mock. But they never quite matched my needs or expectations, unfortunately. And as the old saying goes, if your wheel is difficult to attach to your car, build a new wheel. Then burn the car down with it. It’s an interesting saying. And it led to the creation of my latest little project, UnitTest11.

UnitTest11 is a testing and mocking framework written in C++11 to take advantage of the latest features provided by the language. It aims to involve less Macros than previous testing frameworks, and allow for code to be written in a more modern style. It’s based inherently around the concepts of “Given, When and Then” (Arrange, Act and Assert), and allows for tests to be expressed in this BDD-like fashion without always requiring you to be encumbered by the strictness of Behaviour-Driven Development.

The actual assertions are written to mimic the “natural language” constraint model of NUnit, namely they adopt an “AssertThat(Value, Predicate)” format, to allow for greater readability and flexibility.

The mocking framework is designed to allow for verifications to be made after the act, as assertions. This is something many other C++ mocking libraries, such as Google Mock, do not (to the best of my knowledge) provide good or even any support for. And since both are built into one library, they integrate with less discrepancies compared to when the Testing and Mocking libraries are unrelated.

At present if you wish to look at the library, feel free to do so (For the curious, the code is under the MIT licence). I’ve not completely finished development of it, the tests driving the library are still a mixture of the new UnitTest11 style and older UnitTest++ tests used to bootstrap the development. Also not every feature is fully implemented. For example, whilst the actual Mocking classes are present support for quickly and easily creating Mock Classes is still not fully implemented. I’m looking into the best way to accomplish this, but fear the Google Mock way of having a series of Macros for varying numbers of parameters may be the only viable option. That makes me a little sad.

Still, it works and I would hope it effectively proves the concept. And if Unit Testing and TDD in C++ interest you, feel free to check it out and let me know what you think. I’ll most likely post again about it, with actual code examples, sometime in the near future.

Quote of the Day
“Cease dependence on mass inspection to achieve quality. Improve the process and build quality into the product in the first place.”
William Edwards Deming

1 Comment :, , , , , , , , , , , more...

Ludum Dare 24 – Defeated, and all the more knowledgeable for it.

by on Aug.26, 2012, under C++, Code, Games, Life, Programming, Technology, Video Games

Well, that’s it. My fears confirmed, time management has killed me. There is no way I’m getting this done in time. I spent too long on the background under-the-hood code, which maybe related to how that’s the part of coding I find the most fun. Which could also explain why I’m on the Platform Team at work. We make the API and let the Application Team worry about the best shade of Cornflower Blue to show the customers. And that’s what I ended with, the start of what could be a solid API but something only tangentially related to a working game.

On the brightside my code is very modular, and I am definitely going to create something properly using a more refined variation on this design at a later date (and the lack of time limit will let me use proper TDD and the like).

If I take part in the next LD, I’ve learnt a lot here and had fun, even if I have nothing to demo by the end of it but a sprite moving around the screen. I learnt from my mistakes and will hopefully have more to show in the future.

Major respect for the other LDers who actually get something done without getting lost in background implementation details, as I did.

If I could do it again, I’d pick a pre-existing “engine” (hate that term) instead of writing my own. I just can’t write fast and hackish code without feeling unclean, but for rolling things yourself I’m not experienced enough to do anything but in the timeframe. I fought against that, and it took me too long.

Also I’d impose a much stricter “sprint” system, planning out from the start goals on an hour-by-hour basis (using hourly iterations) with a set of things that needed doing I could pull from. I tried this by the end, where I started to pick up the pace, but it was too little too late.

Code by the end is on github for the curious.https://github.com/MorleyDev/ld24Evolution

tl;dr – I failed hard, but had a blast doing so.

Leave a Comment :, , more...

Documentation.

by on Jul.09, 2012, under Life, Programming, Technology

Piles of Documentation Universities love documentation in their Computer Science courses. I once got 100% on a piece of coursework in no short part because I provided 60 pages of documentation. (autogenerated from comments).

Here’s a little tid-bit: Documentation is a dying art. Universities are way behind. Using TDD, with massive function names and tests to document your code and how it should be used, is the way the industry is going, has been going for the last 10 years and continues to be going. Even large parts of game development, often dismissed as “not possible to test drive”, are being test driven (because the dismissers are wrong, and large parts of game programming can be test driven).

But most universities pay a small lip-service to tests and unit testing, it gets mentioned, you write one for your coursework, it vanishes into the great nether. This is wrong.

Computer Science Students are completely unprepared for industry, and the lack of current practices such as Agile Development and Test Driven Design being taught in Universities is definitely one of the reasons for this.

The option placement year is not optional for anyone at University who wants to work as a Software Developer. It’s the only exposure to modern Software Development they’ll get during their time at University. Because the University sure as heck isn’t going to teach them.

Quote of the Day
“By education most have been misled.”
John Dryden, The Hind and Panther, Part III, line 389.

Leave a Comment :, , , , , , more...

Hello in here!

by on Jul.05, 2012, under .NET, C#, Life, Programming, Technology

Photograph So….Hello! Yeeeah, been awhile huh? Well what’s changed? Well, I have a job for one. A Paid Internship to be exact. I’m almost like a real software developer. Also I’m being introduced to a world of professional techniques like Test Driven Development, which is pretty darn neat and why have I never used it before? Why do universities not try and teach this? You’re hardly prepared for the industry if you do nothing in common with the industry. And that’s a good summary of university education.

On the plus side, I shall has much monies soon. And the work there is definitely interesting, with many Agile Software Development techniques to develop the cutting edge software so I’m learning a lot of practical, real world tricks of the trade.

On the down side, I don’t have much time for other things like personal projects or sleeping until noon. I do so miss sleeping until noon.

Quote of the Day
“When the last days were upon me, and the ugly trifles of existence began to drive me to madness like the small drops of water torturers let fall ceaselessly upon one spot of their victim’s body, I loved the irradiate refuge of sleep. In my dreams I found a little of the beauty I had vainly sought in life, and wandered through old gardens and enchanted woods.”
Ex Oblivione – H.P. Lovecraft

Leave a Comment :, , , , , , , , , more...

Linux? Steam? Take all my downloads!

by on Apr.25, 2012, under Life, Technology, Video Games

This could be amazing. That article there. Know what it talks about?

Linux on Steam!….wait, I think I got that wrong.

Steam on Linux!

So why is this something which could be amazing? Well, I don’t know about you but for me at least I don’t use any software on Windows that doesn’t have a Linux version, and even switch across to Linux for some programs! Except, of course, Video Games.

Oh I do love me some video games. For a long time, only Windows was a viable choice for gaming. Wine and alternatives for Linux weren’t, and still aren’t, capable enough to play the majority of games available. Not even OSX was a valid option.

Then Steam released their OSX version. For you dirty dirty mac users (shame on you!) this brought a renaissance of sorts. Ports for Mac games…appeared! Became easily and readily available. And for those vile mac users, it was good. Still not all games are available for OSX, but more incentives and reasons exist to port and ports have and are happening.

But then people like me were left stuck dual booting Linux and Windows, just so we could enjoy us some video games. Here’s hoping this horrible era is drawing to a close!

Especially since Windows 8 is…Windows 8 and that isn’t a good thing. It is painfully apparent in how Desktop PCs and Gaming are getting shafted here. Shafted I say! I don’t get tablets or their use case or what purpose they serve at all, I have to do a ramble on this at some point.

Okay I don’t mind it so much (the era, Windows 8 and Tablets…I do mind), but having to switch over to Linux and not being able to do squat fun but browse the interwebs and wet ones whistle whilst waiting for a video to render sucks monkeys.

However, a wonderful little truth we all have to keep in our tiny mammalian brains here is that technically that entire article is hearsay, information being repeated. It could all be a lie, and wouldn’t pass in court. Except in the courts of my dreams…

Leave a Comment :, , , , , , more...

Adverts