Day 5/100 100 days of Code

Chris DourisChris Douris
2 min read

Today I watched a fascinating talk about safe C++ where the creator of the language Bjarne Stroustrup talks about delivering a safe C++ application.

He suggests some best practices on safety and talks about the concept of profiles which can be used to set If there is a need for safety checks in the code that is typed or not. It would also be possible to mix them and remove safety checks if performance is needed in some other part of the code base.

Watch the talk here:

I also made some changes in the game I made in Global Game Jam. I removed some unneeded code and replaced the C-style for loops with range-based wherever it was possible. I did this in a destructor as the loops are used to free up memory that is being held by vectors.

emplate<>
Player<SDL_Surface, SDL_Texture, SDL_Renderer >::~Player()
{
    for (auto &i : frontAnimIdleFrameSurface)
    {
        if (i == nullptr)
        {
            break;
        }

        SDL_FreeSurface(i);
    }

    for (auto &j : frontAnimWalkFrameSurface)
    {
        if (j == nullptr)
        {
            break;
        }

        SDL_FreeSurface(j);
    }

    for (auto &k : backAnimWalkFrameSurface)
    {
        if (k == nullptr)
        {
            break;
        }

        SDL_FreeSurface(k);
    }

    for (auto &l : sideAnimIdleFrameSurface)
    {
        if (l == nullptr)
        {
            break;
        }

        SDL_FreeSurface(l);
    }

    for (auto &m : sideAnimWalkFrameSurface)
    {
        if (m == nullptr)
        {
            break;
        }

        SDL_FreeSurface(m);
    }

    if (frameTexture != nullptr)
    {
        SDL_DestroyTexture(frameTexture);
    }

    if (backAnimIdleFrameSurface != nullptr)
    {
        SDL_FreeSurface(backAnimIdleFrameSurface);
    }
}
0
Subscribe to my newsletter

Read articles from Chris Douris directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chris Douris
Chris Douris

AKA Chris, is a software developer from Athens, Greece. He started programming with basic when he was very young. He lost interest in programming during school years but after an unsuccessful career in audio, he decided focus on what he really loves which is technology. He loves working with older languages like C and wants to start programming electronics and microcontrollers because he wants to get into embedded systems programming.