Git Product home page Git Product logo

code-styleguide's People

Contributors

anandkumarpatel avatar bkendall avatar thejsj avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

code-styleguide's Issues

Promise patterns

Let us discuss our new coding patterns now that we moved everything to promises:

Method 1 Linear program w/ comments

Promise.try(() {
  // JSDoc
  ... code ...
})
.then(doSomething1 () {
  // JSDoc
  ... code ...
})
.then(doSomething2 () {
  // JSDoc
  ... code ...
})
.then(doSomething3 () {
  // JSDoc
  ... code ...
})

Pro: looks linear
Cons: unit testing is harder, requires more setup

Method 2 Functional

Promise.try(() {
 return fn1()
})
.then(() {
  return fn2()
})
.then(() {
 return fn3()
})
.then(() {
 return fn4()
})
// JSDoc
fn1 = {
  ... code ...
}
// JSDoc
fn2 = {
  ... code ...
}
// JSDoc
fn3 = {
  ... code ...
}
// JSDoc
fn4 = {
  ... code ...
}

Pro: functions are broken up into smaller components. Each function can have proper unit tests and docs
Con: have to look at different areas on the page to understand full function.

Any other methods people prefer & which do you like the most?

testing guidlines

Writing some notes down before committing so everyone can agree and provide input

stub and restores

Some discussion arised regarding testing patterns
https://github.com/CodeNow/api/pull/1208/files#r46918040
This is related to #1 but with more narrow focus.

The questions is when do we stub function:

  1. @anandkumarpatel prefers to stubbing and restoring once but specifying particular function behavior inside the test https://github.com/CodeNow/sauron/blob/master/test/unit/workers/container-life-cycle-died.js#L47
  2. @cflynn07 prefers to use beforeEach/afterEach for stubbing/restoring. Not using parent beforeEach/afterEach and being explicit. Also it's ok to create describe with single it in order to stub everything specific for a test inside beforeEach
  3. @Myztiq uses both parents and children beforeEach/afterEach

Please correct options I provided and please express your opinion with more details.

Let's settle one some convention and use it across all the codebase.

@anandkumarpatel, @bkendall, @cflynn07, @Myztiq, @thejsj, @rsandor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.