Do I need to prefix function names that return a boolean with b?

I know that you need to name a boolean variable like bVariableName, do you need to do this for functions too?

Thanks in advance

That only says boolean variables. So I don’t need to prefix boolean functions?

Does this help? Coding Standard | Unreal Engine Documentation

Functions that return a value should describe the return value. The name should make clear what value the function will return. This is particularly important for boolean functions. Consider the following two example methods:

// what does true mean?
bool CheckTea(FTea Tea);

// name makes it clear true means tea is fresh
bool IsTeaFresh(FTea Tea);

I’m assuming you could use b as a way to describe your functions, although it might confuse you or anyone reading your code at some point.

I got it from here, just above the example section:

But I was told that in Unreal, boolean variables had to be prefixed with b e.g. bQuestCompleted or else it wouldn’t properly compile.

For functions that return booleans, when I did my course on Udemy for coding C++ in ue4 I was never taught this.

I went back to my course and looked for a function that returned a boolean. This is an image of the teachers code.

301118-rhtbrv.png

As for boolean variables, yes I was taught that the variables should have a b at the beginning of the name. As it was the coding standard.

Hello internet friends! I hope this answer is helpful.

Do you need to prefix a boolean with a b? No. However, it does seem to be a best practice for Unreal Engine.

What we’re talking about here is called Hungarian Notation. Generally, I would frown on using Hungarian notation. Refactoring your program latter can be challenging. What if you don’t want it to be a bool anymore? But that might be the precise reason it is a best practice for Unreal.

Unlike systems programming or other flavors, we create an API between the Editor and the compiled C++. It is very important for people to know that something is a bool in the editor. In fact, just like the Editor transforms CamelCase into Camel Case it also transforms bIsRunning into Is Running in the label presented to the Editor.

You don’t need to use b prefix. Unreal will work just fine. But, I encourage you to use Hungarian Notation and prefix those variables because that’s the convention of Unreal and you should adopt and follow the established conventions. If you don’t, people will be more confused when working with your great works because you do things unlike everyone else.

Respectfully,

Aaron Greenlee

1 Like

Idk man this just seems like circular logic.

How do we know it’s a bool? It should be well named, ie, “isFinished, hasCompleted” and syntax highlighting plus mouse hover to see the type, I just don’t see the point of this, especially only for booleans? Why? What makes bools so special that they are the only type that needs this.

Besides, if you have a type bCar, sure I know its a bool (my IDE also helps me realize this) but I don’t know what it means. So it should be renamed to bHasCar, now I know what it actually means in context of the program, but now the b is redundant. its not giving anyone anymore information that hasCar already gives.

The only reason is that its convention, but its a silly convention. And if people get confused and don’t know what variable type hasCar is and don’t know how to use their IDE to figure it out, that’s their problem. It’s also not my problem if they choose to not use an IDE like some programmers do.