Software developer blog

IDE vs. VIM

Have you ever seen people engaging in endless debates about what editor do real developers use? Sure you have. You might have even read the xkcd classic on the topic:

I'm sure you've been part of this discussion too.

I'm sure it's not much of a breaking news for you, that this is mostly a religious debate. Talking about it is just as pointless as trying to convince atheists about the existence of God, or vice versa.

That being said, I'd like to go further. Lately I've been hearing people debating about how much of an idiots are those who use vim instead of using an IDE and vice versa. You can go on and on about the wonderful features of Eclipse or InteliJ but you might easily get laughed at in certain circles for not knowing that modern vim versions support most of those things too. You might argue, that IDEs are slow, and can not be effectively used through an SSH link, and be called an idiot for that. You may even start a debate about how mode less mouse based software are for non technical people who can't keep in mind which key does what in which mode, and if they are in the right mode. Eventually someone will tell you that real programmers like modes, because they are effective, and he would be just as wrong as right.

@ //

I talked about "The Clean Coder" by Uncle Bob Martin (HUN)

On Thursday I was talking about Uncle Bob Martins book, "The Clean Coder" on a meetup organized by Agile Hungary. The talk was in Hungarian, but it's already available on YouTube (not embeddable, so please follow the link), along with the slides on SlideShare:

@ //

Unit test framework for C++ in about a 100 lines

Those who know me well are also aware of the fact, that I'm a very strong proponent of test automation and test driven development. Unfortunately there are times in our lives when installing an existing framework is not an option. So when I've been challenged to write a test framework that is so simple one can memorize it, and flush it out of their brain anytime needed, I was up to the task. The entire framework is 113 lines of C++ code, and using it is just as simple as using google test. Of course it doesn't come with all the features, it's fragile and has a good number of limitations, but it's good enough if you have absolutely no other option.

Here is how to use it, along with a sample output:

#include "TestBase.hpp"
 
class TestGroup : public TestBase {
};
 
TEST_F(TestGroup,PassingTest)
{
	EXPECT_TRUE(true);
	EXPECT_TRUE(true);
}
 
TEST_F(TestGroup,FailingTest)
{
	EXPECT_TRUE(true);
	EXPECT_TRUE(false);
	EXPECT_TRUE(true);
}
 
TEST_F(TestGroup,SecondPassingTest)
{
	EXPECT_TRUE(true);
	EXPECT_TRUE(true);
}
Sample output

Sample output of a simple unit test framework

Game of Life on the GPU

Conway's Game of Life is one of the most popular code katas, and the one we will exercise on our next code retreat this Saturday. I have done this kata, quite a number of times, but this time there was a twist: I used the GPU on my Nvidia GTX 560 to calculate the steps of evolution, and to draw them as well. Here is how the result looks like:

Puffer train in Game of Life

Puffer train in Game of Life. Living cells are green, they increase the blue chanel by 1 in each generation, and leave a faiding red trail after they die.

The igniter of this exercise was that I read a book on CUDA programing, and it was quite a disappointment. The examples were really far from anything I would call clean code, or at least easy to understand: it was spaghetti with huge meatballs in it. That kind of examples require a lot of explanation, which basically took up most of the books volume, and there was little left for the useful stuff. So I got curious: is it CUDA that promotes bad code, or the writers of the book didn't care enough? I had a preconception that there was nothing wrong with CUDA  - and actually it's a pretty neat language - so I set out on a quest to code Game of Life in CUDA, and try to make it as clean as possible.  I don't claim, that my code is perfect, but I hope it's going to be an easy read for anyone who tries.

You can download the result of my quest by clicking here, or just browse it as HTML by clicking here. The rest of the blog entry - basically a retrospective of the project, and a few remarks on CUDA features - might not make much sense without looking at parts of the code. If you'd like to compile, than you will need the nvcc compiler for CUDA, the CUDA Toolkit, GLUT and GoogleTest to run my unit tests. Please note, that the code is not production quality: it may well throw exceptions at you, it's only tested on Ubuntu, and it is not performance optimized in any way. (Even the algorithm is the most naive one.)

@ //

How to generate a random binary tree and visualize it with Graphviz

Yesterday I was testing a small piece of code, that was capable of finding the nth item in the in-order traversal of a binary tree. It was a template function with the root node and n as arguments, and only required that the children nodes should be pointed by public members "left" and "right", while unused children pointers are NULL. (Pretty much the old school way of doing it.)

Of course I didn't want to manually generate test cases. Instead I wrote a little function that can generate a large tree on demand, and used that. Since the boost random library uses a constant seed by default I can rely on the tree to be the same each time the test is ran.

@ //

Code for fun

Yesterday I was participating in the Budapest event of Global Day of Coderetreat. It was a very intensive day of coding in pairs. The basic idea is that the same programming task - specifically the implementation of Conway's Game of Life - is repeated in six 45 minute sessions. Since the pairs were switched after every other session, and people came from different backgrounds, this was a great opportunity to learn from each other. Also one could try different design decisions, and see what are the benefits and liabilities of each.

Pair coding on the Global Day of Codetreat, Budapest

For me this was the first time I did real pair coding, and the most important experience of the day for me was that pair coding is good, good, GOOD. 🙂 Even better for me was when we were doing TDD ping-pong with Athos.

@ //

Test driven development and unit testing frameworks

In the last few years I've been using test driven development, and grew really accustomed to it. TDD not only helps in avoiding strange errors, it also helps in software design, implementation and enforces a pro-active approach towards debugging. At first it may seem that writing tests for each and every small part of the code is time well wasted, but in fact it is definitely worth the effort, especially if an automated unit test framework is used. As not everyone may be convinced at first, here is a quick summary about how TDD works, how it improves productivity, and what are it's pros and cons.

The work-flow starts by writing the test using an automated unit test framework, and see it fail. There are several reasons for first writing the test, and implementing the feature afterwards, but I'll get to that later. After the test fails as it should, implement the new feature, and test again. If the test still fails, fix the code, and test again. If your new feature works, but tests of earlier features fail, than see how the broken code relies on the functionality you have changed, and make sure that you fix all bugs. Once all test pass, commit your code to the version control system, and continue by writing the next test, for your next feature. It is important, that you always write only as much code, as necessary to pass the test.

@ //
« Previous Page