I’m looking for code feedback on handling if checks, nullptr, and ensure()
This is how Sam wrote it
bool UMainMenu::Initialize()
{
bool Success = Super::Initialize();
if (!Success) return false;
if (!ensure(Host != nullptr)) return false;
Host->OnClicked.AddDynamic(this, &UMainMenu::HostServer);
return true;
}
this is the code I wrote:
bool UMainMenu::Initialize()
{
if (!Super::Initialize()) return false;
// Host = nullptr;
if (ensure(Host))
{
Host->OnClicked.AddDynamic(this, &UMainMenu::OnHostClicked);
}
return true;
}
I like that when using ensure is logs a call stack of where it happened. I’d never used ensure before. I’m being real nick-picky about some of the checks and how conditions are handled and it probably comes down to personal preference, but I hope to get some feedback. Opinions are welcome as well, doesn’t have to be official standard although that’s preferred.