Category Archives: DLed

DLed’s works

yet quicker start for a c++ project

The simplest way to try out some c++ concepts on your machine is the built-in build support of some ‘smart’ text editors, such as Sublime Text or SciTE. However, if you want to start quickly, but be able to grow the project from that one small seed, you’d probably want to have SCM set up.

To start cross-platform c++ projects I usually use git and premake. For premake I’ve set up a couple of quickstart scripts that implement some code organization conventions I usually follow. That project still requires one to set up a git directory, add a submodule, edit a premake4.lua file, write the first code file. How about automating these tasks as well. Every developer writes own support shell scripts, here’s one: new_cpp.sh that doesn’t do much – just what is described above. Considering, you have copied it somewhere where it’s executable globally, here are the steps:

  1. new_cpp.sh project_name → make the directory, init a git repo, add the premake submodule, the first source file and the premake4 build meta-configuration.
  2. cd project_name
  3. premake4 gmake → generate, makefiles, could be vs*, xcode*, too.
  4. make -C Build → build to see if everything is set up.

You can now start growing your code from project_name.cpp.

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.