Skip to content

Instantly share code, notes, and snippets.

@KindDragon
Forked from haacked/csharp-conventions.md
Last active August 29, 2015 13:57
Show Gist options
  • Save KindDragon/9597019 to your computer and use it in GitHub Desktop.
Save KindDragon/9597019 to your computer and use it in GitHub Desktop.

Space vs Tab

Space

std::string GetSomething()
{
    return something;
}

Tab

std::string GetSomething()
{
	return something;
}

Block Statements

Curlybrace with one space

if (height < MinHeight) {
  //...
}

while (isTrue) {
  //...
}

switch (foo) {
  //...
}

Curlybrace withat new line

if (height < MinHeight)
{
  //...
}

while (isTrue)
{
  //...
}

switch (foo)
{
  //...
}

Curlybrace with no space

if (height < MinHeight){
  //...
}

while (isTrue){
  //...
}

switch (foo){
  //...
}

Constant name

Constant is Pascal cased

const std::string FooBar = "baz";

Constant is all caps with underscore

const std::string FOO_BAR = "baz";

Conditionals

Condition with space

if (true) {
  //...
}

while (true) {
  //...
}

switch (v) {
  //...
}

Condition with no space

if(true) {
  //...
}

while(true) {
  //...
}

switch(v) {
  //...
}

Method arguments with one space vs no space

No space

void SetName(std::string name) {
  // ...
}

if(isTrue) {}

while(isTrue) {}

One space

void SetName( std::string name ) {
  // ...
}

if( isTrue ) {}

while( isTrue ) {}

Line Length over 80 characters

Line length is within 80 characters.

/* width is within 80 characters */

Line length is within 120 characters.

/* width is within 120 characters */

Line length is within 150 characters.

/* width is within 150 characters */

Special prefix for static var

No special prefix

static std::string name;

Special prefix

static std::string s_name;

Global prefix

static std::string g_name;

Private member naming

no underscore

public:
    std::string GetProperty { return property; }

private:
    std::string property;

underscore prefix

public:
    std::string GetProperty { return _property; }

private:
    std::string _property;

underscore suffix

public:
    std::string GetProperty { return property_; }

private:
    std::string property_;

m prefix

public:
    std::string GetProperty { return mProperty; }

private:
    std::string mProperty;

m_ prefix

public:
    std::string GetProperty { return m_property; }

private:
    std::string m_property;

Class casing

Pascal casing as God intended

class MyClass
{
}

snake_casing for people who love STL

class my_class
{
}

camel casing for people who hate the world

class myClass
{
}

Public method casing

Pascal casing as God intended

public:
    void DoSomething()
    {}

snake_casing for people who love STL

public:
    void do_something()
    {}

camel casing for people who hate the world

public:
    void doSomething()
    {}

Private method casing

Pascal casing as God intended

private:
    void DoSomething()
    {}

snake_casing for people who love STL

private:
    void do_something()
    {}

camel casing for people who hate the world

private:
    void doSomething()
    {}
@KindDragon
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment