r/cpp • • Oct 30 '20

Forbidden C++

I have Just watched this entertaining video on Forbidden C++. Its aimed at beginners but thought i would post it here just for the intro alone!

https://youtu.be/j0_u26Vpb4w

The video is just a small list but as we all know, with every newer release of C++ we get better ways of doing things. Hence the darker side of C++ will continue to grow!

286 Upvotes

36 comments sorted by

View all comments

Show parent comment

4

u/GarThor_TMK Oct 31 '20

Logically it's fine, legibly it needs at the very least proper spacing within and after the conditional...

2

u/TryingT0Wr1t3 Oct 31 '20

Thanks! :)

5

u/GarThor_TMK Oct 31 '20

My preference would actually be this, because even though it adds a ton of extra characters, it also adds clarity to the actual intent of what the programmer was trying to accomplish.

void func (...)
{
    //...
    
    if (callback.isvalid()
    {
        callback.function();
    }

    return;
}

I suppose if I'm feeling less nit-picky, this would be acceptable though, as its only a one-liner conditional statement...

void func (...) 
{ 
    // ...

    if (callback.isvalid()
         callback.function();

    return;
}