Personally, I prefer thisStyle
to ThisStyle
for functions. This is really for personal taste, probably Java-influenced, but I quite like functions and classes to look different.
If I had to argue for it, though, I'd say that the distinction is slightly more than just aesthetic. It saves a tiny bit of thought when you come across function-style construction of a temporary. Against that, you can argue that it doesn't actually matter whether Foo(1,2,3)
is a function call or not - if it is a constructor, then it acts exactly like a function returning a Foo by value anyway.
The convention also avoids the function-with-same-name-as-a-class-is-not-an-error fiasco that C++ inherits because C has a separate tag namespace:
#include <iostream>
struct Bar {
int a;
Bar() : a(0) {}
Bar(int a) : a(a) {}
};
struct Foo {
Bar b;
};
int Bar() {
return 23;
}
int main() {
Foo f;
f.b = Bar();
// outputs 23
std::cout << f.b.a << "\n";
// This line doesn't compile. The function has hidden the class.
// Bar b;
}
Bar is, after all, both a noun and a verb, so could reasonably be defined as a class in one place and a function in another. Obviously there are better ways to avoid the clash, such as proper use of namespaces. So as I say, really it's just because I prefer the look of functions with lower-case initials rather than because it's actually necessary to distinguish them from from classes.