Why pascal case for variable names?

Hi, I was just looking over the Unreal Engine coding standards and was wondering what the rationale was for using pascal case for variable naming?

The ‘traditional’ style I’ve seen with other projects I’ve worked on would use c style or camel case for a clear visual distinction between class type and variables. I understand there is no ‘correct’ style guide so Its up to every project to do what they want, but I frequently find when looking at engine source I will come across a name in the middle of a function and I cannot immediately tell from the convention if this is a class type, a local or a member variable without using ide functionality.

(so i guess the question could be extended to why there is no local/member distinction in naming as well, ie mMyFoo)

thanks!

this_is_no_easy_to_read_or_write.

That’s one reason.

Second. what exactly m in mMyFoo mean ?
Member ? Matrix ? Mooo ?

Last, IDEs do pretty good job at coloring syntax, and we don’t really need prefixes, postfixes etc.

This kinda made me cringe as well in the beginning. I’ve been used to naming variables in camelCase, ie. myLocalVariable, mMyMemberVariable and/or m_myMemberVariable but it seems UE4 practise is to name everything starting with a capital and making no distinction between member variables and local variables. It feels weird but I guess you get used to it. I still wonder the reasoning of the UE4 coding conventions but in the end you just have to accept the style.

Seriously though, why all functions and variables start with a capital letter? I understand the functions but why the variables? Perhaps some old timer engine developer could shed some light on this? :slight_smile:

1 Like

This isn’t old school style. If this was, everything would be all decorated up with some sweet old hungarian notation.

void* pPointerTo;
float fSome;
Object mStruct;
static const int kMaximumSomething;.

Ditching all the prefix characters and underscores is more or less in line with the modern C# coding standard.

You’re opening a pandora’s box here. Code formatting, especially in C-syntax languages, can be a really contentious issue among programmers.

Fact is, we can come up for all sorts of justifications for preferring one format over another (oh, and we do, don’t we?), but a lot of it really does just boil down to what we’re used to. At the end of the day, a certain amount of consistency is important in a large code base like Unreal Engine, and somebody has to make a decision about what that consistent format will be.

Prior to coming to UE4, I’d been using lower-case camel case for local and member variables for… yikes… uh thirty years. It’s been one of the few constants in my programming over the years, so it’s been a tough habit to break for me in UE4. Prepending a ‘b’ to boolean names has also been hard for me, and feels a little throwback. There may be a good compelling reason for these decisions, or it may just have been a personal preference of whoever got to write the style guide. In the end, it really doesn’t matter because there are hundreds of thousands of lines of code formatted using these rules already, so an argument for a change would have to be super amazingly compelling. It’s best to just be a little zen about it and accept it for what it is.

UE4’s style is growing on me, though, and I really, really appreciate the consistency when I’m poking around the engine code, reading the wiki, or looking at sample projects. At the end of the day, that consistency is what’s really important.

With a little time, you can adjust to any syntax or formatting rule. It doesn’t take long before it becomes natural (and other formats start looking ‘wrong’). :slight_smile:

1 Like

Absolutely, another code formatting debate is not needed here. Unreal has a clear coding standards, and that is not in question. But I can honestly say from working with a range of c++ projects both in and out of the games industry for many years that I’ve never come across this particular convention for variable naming. I’m interested to know the origin, as I personally find it a little unusual :slight_smile:

Okay, I’ll admit some curiosity about that myself. :slight_smile: Unfortunately, I haven’t got a clue which one (or more than one) of the fine people at Epic made the formatting decisions.

It is a matter of preference… as long as it is uniform ie all source files are using Pascal convention, it should be okay.

I prefer camelCase but PascalCase looks better in editor when using UPROPERTY, it’s more uniform with the rest of the editor