Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

README.md

Code Convention Philosophy

Our code convention philosophy: Code is far more read than it is written, so we will favor read-time convenience to write-time convenience.

These conventions are based on Simon McConnell’s framework for code conventions from the book Code Complete.

Style

TBD

General Conventions

Human Language

English Language when naming variables, functions, classes and comments

Use descriptive language when naming functions/variables. They should be self-explainatory.

#BAD
mxpl = 7
current = datetime.datetime.now()

def date():
  return current
#GOOD
max_people = 7
current_date = datetime.datetime.now()

def getCurrentDate():
  return current_date

Computer Language

Javascript - camelCase

let camelCaseVariable = "This looks good"

Json - camelCase

{
"camelCaseVariable" : "This looks good"
}

Python - snake_case

snake_case_variable = "This looks good!"

No Magic numbers

This is numbers directly in the functions that serve a specific value.

# BAD
if password_length > 7:
    print("Password has to be shorter")
# GOOD
MAX_PASSWORD_LENGTH = 7
if password_length > MAX_PASSWORD_LENGTH:
    print("Password has to be shorter")

Use Encapsulation

Never access other classes variables directly.

// BAD
class Person {
  constructor(name) {
    this.name = name;
  }
}

kent = new Person('kent')
kentsName = kent.name
kent.name = 'Eline'
//GOOD
class Person {
  constructor(name) {
    this.name = name;
  }

  //This is encapsulation
  getName() {
    return this.name
  }

  setName(name) {
    this.name = name
  }
}

kent = new Person('kent')
kentsName = kent.getName()
kent.setName('Eline')

Naming Specifics

Constants

UPPERCASE_LETTERS with snake_case

MAX_PASSWORD_LENGTH = 99

Boolean

Use positive boolean names

#BAD
notFound = true

#GOOD
found = true

Typical boolean names:

#To indicate whether something is done
done = true
isDone = true

#to indicate whether an error has occured
error = false
hasError = false

#to indicate whether a value has been found
found = true
isFound = true

#To indicate whether an operation has been successful
success = true
ok = false