Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Intro

This document will go over the style guides used for different languages\

Style Guides

For react we have adopted the Airbnb style guide

  • Overview

    • All variables, functions, props, should be lowerCamelCased

    • Components should be CamelCased

    • Use all single quotes instead of double quotes in js files

    • Spread objects and lists instead of mutating them

    • Some general spacing guidelines are listed below

      // bad
      <Foo/>
      // good 
      <Foo />
      
      // bad
      <Foo bar={ baz } />
      // good
      <Foo bar={baz} />
      
      // bad
      <Foo superLongParam="bar"
           anotherSuperLongParam="baz" />
      
      // good
      <Foo
        superLongParam="bar"
        anotherSuperLongParam="baz"
      />
      
      // if props fit in one line then keep it on the same line
      <Foo bar="bar" />
      
      // children get indented normally
      <Foo
        superLongParam="bar"
        anotherSuperLongParam="baz"
      >
        <Quux />
      </Foo>
    • Always self-close tags that have no children

  • https://airbnb.io/javascript/react/

  • https://medium.com/docon/airbnb-javascript-style-guide-key-takeaways-ffd0370c053

For python we have adopted PEP

  • Overview

    • All functions, class methods, and variable names should be snake_cased

    • All class names should be CamelCased

    • Constants and global variables should be UPPER_CASED

    • Long function calls should use vertical alignment

      example2 = function(first_var, second_var,
                          third_Var, fourth_var)
    • Big objects and lists should be spaced on multiple lines

      new_list = [
          'one', 'two', 'three',
          'four', 'five', 'six'
      ]
      
      new_obj = {
          'key_1': 'value_1',
          'key_2': 'value_2',
      }
    • Maximum line length is 79 characters

    • Do not use wildcard imports

      # don't do this
      import * from your_package
      
      # do this instead
      import your_class from your_package
    • Single quotes around your strings or double quotes around your string mean the same thing. You can choose what one you like more, but stick to it so you can use the alternative you didn’t choose instead of backslashes.

    • Some general spacing guidelines are listed below

      # add space on either side of all operators
      x = y + z 
      # not 
      x=y+z
      
      # no whitespace for function calls
      my_funtion()
      # not 
      my_funtion ()
      my_funtion( )
      
      # when indexing or slicing the brackets should be directly next collection
      collection[‘index’]
      # not 
      collection [‘index’]
      collection[ ‘index’ ]
  • https://www.python.org/dev/peps/pep-0008/

 

 

  • No labels