Skip to content

Programming Guidelines

JMcKiern edited this page Nov 11, 2018 · 4 revisions

Width limit of 80 characters.

Tabs are used for indentation. Spaces are used for alignment:

	void KeyCB(GLFWwindow* _window, int key, int scancode, int action,
	           int mods);

As a guideline, break at most shallow nesting

	// Good
	static_cast<Console*>(glfwGetWindowUserPointer(w))->
		ResizeWinCB(w, a, b); // Tab used here since it's just another indent not alignment
	
	for (std::vector<PeripheralConnection*>::iterator it = connections.begin();
	     it != connections.end();
	     ++it) { // Here a tab is used to get to start of "for" then spaces used to aligning with std::vector...
	}
	
	ReallyLongFunctionName(reallyLongParameter1,
	                       reallyLongParameter2); // Again, one tab to match indentation level and then spaces for alignment

	// Below uses one tab up to "auto", spaces up to start of ReallyL... then 4 more spaces to indent AnotherL...
	auto x = ReallyLongFunctionThatReturnsValue(
	             AnotherLongFunction(parameter1, parameter2))
	
	// Also could use a variable to shorten the line
	auto usrPtr = glfwGetWindowUserPointer(w);
	static_cast<Console*>(usrPtr)->ResizeWinCB(w, a, b);

	// Bad
	static_cast<Console*>(glfwGetWindowUserPointer(w))->ResizeWinCB(w, a,
	                                                                b);

Width comes before height

Naming convention:

  • functions: fooBar();
  • variables: fooBar;
  • Members: fooBar;
  • Methods: FooBar();
  • Class: FooBar;

in *.cpp gaps after bottom of function only when moving to different category of functions/methods

ptr * are on the side of the type (eg int* x; not int *x;)

Methods definitions should be in the same order as their declarations

All default constructors are the ones that would be used in the NES. Any others may require additional setup before use.

Clone this wiki locally