Skip to content
Daniel Hasegan edited this page Aug 5, 2014 · 5 revisions

Usually follow the code surrounding where you want to add code. Usually it should be good, but you can never be sure if you don't know the coding styles. Read them below for each language:

!!! INDENT WITH SPACES NOT TABS (everywhere) !!!

Python

Python coding style and conventions are best described by:

Use this to construct a basis for coding in python, but this may be overwritten by the Django coding style

Autoindent (optional)

You can install "Python PEP8 Autoformat" for automatic indentation and formatting. I use it sometimes but never for "urls.py" !! You can install the package for sublime-text from the package manager and then use CTRL+SHIFT+R to auto-format. Make sure that you configure sublime so that it ignores breaking the lines that are too long.

Here are my settings for the autoformatter:

{
// autoformat code on save ?
"autoformat_on_save": false,

// enable possibly unsafe changes (E226, E24, W6)
// aggressive level, 0 to disable:
"aggressive": 0,

// list codes for fixes; used by --ignore and --select
"list-fixes": false,

// do not fix these errors / warnings (e.g. [ "E501" , "E4" , "W"])
"ignore": ["E501"],

// select errors / warnings (e.g. ["E4", "W"])
"select": [],

// Maximum line length
"max-line-length": 79
}

Flake8 (optional)

flake8

Django

For django there is no standard but there are a few suggestions like:

Javascript

Rule 1: Follow the file structure of the current js files in

connect.academy/academy/static/local/js/*

Rule 2: Any function that is larger than 50 lines should be breaken down into smaller parts

Rule 3: Any file that is larger than 300 lines should be breaken down into smaller files

Rule 4: Cache unchanging items in me.settings

Rule 5: Use me.init to make the initial declarations on your page

Rule 6: Use me.bindUIActions to do exactly that

Rule 7: Use the utils function for ajax: Utils.SubmitFormAjax

Sassy CSS (sass or scss)

Rule 1: don't write CSS, write SCSS.

Rule 2: if its a color, make it a variable

$course-rating-badge-color:         #33424D;

Rule 3: If its something from bootstrap, modify it there:

connect.academy/academy/static/bootstrap/stylesheets/bootstrap/_variables.scss

Rule 4: Follow the nested structure type of the current code connect.scss

Clone this wiki locally