godot_openxr icon indicating copy to clipboard operation
godot_openxr copied to clipboard

Rename methods and variables to consistant naming conventions

Open BastiaanOlij opened this issue 4 years ago • 5 comments

Naming of variables and methods are all over the place, time to clean this up. I'm planning to start on this after the android-dev branch is merged into master, this gives us time to make some decisions on this.

The current conventions within Godot that I think we should keep following are:

  • classnames in camel case including capitalising the first letter. i.e. MyClassName
  • same for structure names and the collection name for enums
  • enum members in upper case. i.e. MY_ENUM_MEMBER
  • member variables in snake case. i.e. my_member_variable
  • member methods in snake case. i.e. my_member_method()

Note that it is common in Godot to prefix internal methods with an underscore to denote they are considered private even though they need to be public to make them callable from GDScript. We'll follow suit if we're in the same situation, so internal functions like '_readyor_init` or functions called by signals.

Note that layout is mostly enforced through clang-format with tabs used as indent but just for reference.

Class definition:

class MyClassName {
private:
	int a_private_variable;

protected:
	int a_protected_variable;

public:
	void a_public_method(const int p_parameter);
};

Function definition:

void MyClassName::a_public_method(const int p_parameter) {
	// code goes here
}

note we do not include ; after } if not needed.

If statements should always have code blocks (defensive programming) so:

if (expression) {
	// code goes here
}

Not if (expression) // code goes here

Same for switch:

switch (value) {
	case 1: {
		// code goes here
	}; break;
	case 2: {
		// code goes here
	}; break;
	default: {
		// code goes here
	}; break;
}

Switch should always contain a default clause.

BastiaanOlij avatar Aug 19 '21 10:08 BastiaanOlij

@ChristophHaag just so we don't loose sight of this as you correctly raised this issue the other day. Feel free to comment on what other conventions we should add here.

@m4gr3d would welcome your feedback here too.

BastiaanOlij avatar Aug 19 '21 10:08 BastiaanOlij

Sounds good to me

note we do not include ; after } if not needed.

wouldn't that give an undesired compiler warning anyway?

ChristophHaag avatar Aug 19 '21 11:08 ChristophHaag

Looks good to me!

m4gr3d avatar Aug 20 '21 07:08 m4gr3d

wouldn't that give an undesired compiler warning anyway?

Maybe with those fancy compilers you guys use on Linux, MSVC seems to be happy with em... it's a pain in the but because before I contributed to Godot I was used to always have the ; there :)

BastiaanOlij avatar Aug 20 '21 09:08 BastiaanOlij

all jokes aside, if there is a compiler switch that turns this into a warning on MSVC I'm all for adding it

BastiaanOlij avatar Aug 20 '21 09:08 BastiaanOlij