🖥️
Intro to Computer Science (ICS3U/C)
  • An Introduction to Computer Science
  • Videos & Slides
  • Unit 1: In the Beginning
    • The History of Computers
    • Binary & Logic
      • Bits and Bytes (Binary)
      • Transistors (Changing Bits)
      • Logic Gates
        • Poster
        • Logic.ly
    • The Parts of a Computer
  • Unit 2: Intro to Code
    • How Do We Code?
      • Coding Conventions (Rules)
      • Commenting Code
    • What is HTML?
      • Hello World! (in HTML)
      • HTML Slideshow
    • Hello World!
    • Input / Output
      • The Console
      • Prompt, Alert, Confirm
    • Variables & Data
      • Strings (Text)
      • Numbers (Values)
        • Converting & Rounding
        • The Math Object
          • Random Numbers
      • Booleans
        • Truthiness
      • Arrays
  • Unit 3: Control Flow
    • Conditionals (if this, do that)
      • If...Else
        • Logical Operators
      • Switch / Case
      • Ternary Operators
    • Loops (Repeating Code)
      • For...Loop
      • While & Do/While Loops
    • Debugging
  • Unit 4: Functions
    • Functional Programming
    • User Defined Functions
      • Hoisting and Scope
    • Calling a JS Function
  • TL;DR
    • Programming Basics
    • Slideshows & Demos
    • Javascript Syntax Poster
  • Advanced Topics
    • Recursion
    • Structures & Algorithms
    • Mmm... Pi
  • External Links
    • Typing Club!
    • repl.it
    • Khan Academy
    • Geek Reading
    • ECOO CS Contest
Powered by GitBook
On this page
  1. Unit 2: Intro to Code
  2. How Do We Code?

Coding Conventions (Rules)

PreviousHow Do We Code?NextCommenting Code

Last updated 6 years ago

Every programming language, development environment, business, and person has their own opinion of how to write readable code. Without a set of rules, reading your colleague's code would be difficult. It is important to make code easy to read because someone else might need to use or improve it - and that's ok!

Most programmers have very specific rules for code style. Ours are simple:

  • Variable and Function names will be meaningful and complete.

  • Variable and Function names will only start with lowercase letters.

  • Variables and Functions will be named using .

  • Constants are written in all UPPERCASE letters.

  • You will put spaces after commas, and around operators ( + - * / ).

  • Always use 2 or 4 spaces to indent code blocks (our default is 2) (tabs are interpreted differently, depending on the text editor). Example: function toCelsius(fahrenheit) { return (5 / 9) * (fahrenheit - 32); }

  • Always end single lines of code with a semicolon;

  • Place opening brackets at the end of the current line, preceded by a single space.

    • Closing brackets are placed on their own line without leading spaces. for (i = 0; i < 5; i++) { // Opening bracket x += i; } // Closing bracket

  • Hyphens are not permitted in names, use underscore instead.

For more on this topic:

camelCase
LogoJavaScript Style Guide
LogoProgramming styleWikipedia