Tag: c++

Working with mruby

August 17, 2019 22:55

Having worked with Lua before and made a LuaCppInterface, I decided about a year ago to start working on a C++ interface for mounting mruby as a scripting language.

To start, I have been developing in Ruby for several years now and I found it to be q...

Read post

Exceptionless Programming

November 28, 2012 00:00

I am a big fan of writing code that generates no runtime errors. This is an implementation of a function that takes the first element of an array.

template<typename T>
T first(std::vector<T> array)
{
    if (array.size() == 0) { throw EmptyArrayException(); }
    return array[0];
}

This is ...

Read post

Why I Prefer Initialization Through Constructors

September 18, 2011 00:00

I always prefer initializing my class through the use of a constructor like this:

class Apple
{
    Color color;
    Taste taste;
    List<string> countries;
    public Apple(Color color, Taste taste, List<string> countries)
    {
        this.color = color;
        this.taste = taste;
        this.countries = countries...
Read post

Will the destructor be called?

August 10, 2010 00:00

Here's a C++ quiz for all of you: somefunc() will be called from a thread. Do you think this destructor will be called?

class A {
public:
    A () {
        printf("Constructor\t");
    }

    ~A() {
        printf("Destructor\n");
    }
};

int somefunc () {
    A inst;
    int* a = 0
    *a = 1;
    return 0;
}

...

Read post

Idioms

June 21, 2010 00:00

What if

for (int i=0; i<100; i++) 
{
    doSomething();
}

// and

for (int i=0; i<100; i+=2)
{
    doSomethingElse();
}

Was

doSomething() for 1..99;
while (i=1,2..99) { doSomethingElse(); };

Would the world be a better place? ...

Read post