Author Archives: DLed

c++ humor: you don’t know what it does

Remembering some obscure code, even if the code looks clean and short, you still can’t say anything about it without a test. What about that?

#include "my_library.h"

int main() {
    double my_data = 36.7;
    my_library::do_some_useful_work_with( my_data );
}

Say, you trust the person who wrote my_library.h and compile and run. Imagine, my_library is full of complex template-metaprogramming – the person is a genious anyway. And the code is clean, you can clearly understand what my_library::do_some_useful_work does – it clearly states so. But Then, your program somehow fails to works as expected. You look under the hood and see:

open the header
[cpp]struct HideousHack {
HideousHack() {
// Downloading the whole internet
// …
// Allocating a static 120TB buffer
// something else you’re surprised to see
}

// … extras
};

#define double HideousHack
[/cpp]

That’s just when you can still run through this one header. But if you’re including something more elaborate, consisting of recursive includes of obscure or generated library parts?

If you include (import, use, load …) something untested or something you can’t test easily, there’s no point in thinking, you know what’s happening from simply reading the code.

The solution strategy? Don’t trust, test if it’s important.

Quickstart for cross-platform c++ projects

A typical dilemma for a c++ developer is creating the initial build configuration. Out of my affection for Lua, I’ve collected my typical premake4 patterns into a separate project to be able to set up c++ projects on any platform within a minute.

Here’s a sample from selfdestructing:

_G.package.path=_G.package.path..[[;./?.lua;./?/?.lua]]
assert ( require 'premake.quickstart' )

make_solution 'selfdestructing'

includedirs { 
	'./selfdestructing',
	'./Catch/single_include'
}

make_console_app( 'selfdestructing-test', { './test/test.cpp' } )
make_cpp11()
run_target_after_build()

want to try out cucumber with c++? try cucumber-cpp+premake

Feature: Cukes simple build
    As a c++ programmer convinced of specification by example
    In order to be able to write Cucumber tests for my projects
    I want to be able to build cucumber-cpp and its prerequisites easily

Scenario: Checking out cucumber-cpp
    Given a c++ developer environment
    And The Boost library is present
    When I write my cucumber steps
    Then I can easily link them to cucumber-cpp libraries

feedback and contributions are welcome.

Current status: build needs some cleanup, but it works: travis-ci badge

To build, either use the generated makefiles or the Visual Studio 2012 solution in the Build directory, or clone and extend the premake script.