├── language ├── csharp.md ├── elm.md ├── ruby.md ├── haskell.md ├── python.md └── javascript.md ├── README.md ├── platforms └── nodejs │ └── bestPracticesNodeJS.md └── frontend └── react └── bestPracticeReact.md /language/csharp.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /language/elm.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /language/ruby.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /language/haskell.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /language/python.md: -------------------------------------------------------------------------------- 1 | # Python Best Practices 2 | 3 | ### Variable 4 | - Naming use PEP 8 (for example: lower_case) 5 | - Naming constant using CAPS_LOCK 6 | - Avoid global namespace. 7 | *** 8 | ### Method 9 | - Use simple method 10 | - Keep all operation the same level of abstraction 11 | *** 12 | ### Structure 13 | - Use Explicit structure 14 | - Use default dictionary structure 15 | *** 16 | ### Common 17 | - Document your code 18 | - Follow common style-guide in all application. For example use 19 | [PEPs](https://www.python.org/dev/peps/) 20 | - Use if not x instead of if x == 0 21 | -------------------------------------------------------------------------------- /language/javascript.md: -------------------------------------------------------------------------------- 1 | # JavaScript Best Practices 2 | 3 | ### Variable 4 | - Avoid global scope. 5 | - Choose easy to understand and short names for variables and functions. 6 | - Declare and initialize variable on top. 7 | - Use shortcut notation for declare variable. 8 | *** 9 | ### Function 10 | - Use descriptive names. Name should be a verb or a verb phrase. 11 | - Avoid long argument list. 12 | - Avoid default param. 13 | - Reduce side effect. 14 | - Single responsibility. Function either modifies or handle smth, but not both. 15 | *** 16 | ### Async code 17 | - Use Promises where you need async code 18 | *** 19 | ### Common 20 | - Use strict equal (===) 21 | - Good code explains itself. Comment to code only if it needed. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Awesome Best Practices 2 | This repository is a collection of AWESOME Best Practices for all dev situation with language\framework\lib and tools. Feel free to star and fork. Any comments, suggestions? Let me know. I like PRs :bowtie:, please follow the awesome format. 3 | 4 | ## Programming language 5 | 6 | - [JavaScript](https://github.com/ximet/awesome-best-practices/blob/master/language/javascript.md) 7 | - [Python](https://github.com/ximet/awesome-best-practices/blob/master/language/python.md) 8 | - [Haskell](https://github.com/ximet/awesome-best-practices/blob/master/language/haskell.md) - Coming soon 9 | - [Elm](https://github.com/ximet/awesome-best-practices/blob/master/language/elm.md) - Coming soon 10 | - [Ruby](https://github.com/ximet/awesome-best-practices/blob/master/language/ruby.md) - Coming soon 11 | - [C#](https://github.com/ximet/awesome-best-practices/blob/master/language/csharp.md) - Coming soon 12 | 13 | ## Platworms 14 | 15 | - [NodeJS](https://github.com/ximet/awesome-best-practices/blob/master/platforms/nodejs/bestPracticesNodeJS.md) - Event-driven I/O server-side JavaScript environment based on V8 16 | 17 | ## Front-End Development 18 | 19 | - [React](https://github.com/ximet/awesome-best-practices/blob/master/frontend/react/bestPracticeReact.md) - A JavaScript library for building user interface 20 | -------------------------------------------------------------------------------- /platforms/nodejs/bestPracticesNodeJS.md: -------------------------------------------------------------------------------- 1 | # NodeJS Best Practices 2 | 3 | - #### Understand the Event Loop 4 | It is necessary to understand how it works and how it interacts with it. See picture: 5 |  6 | 7 | *** 8 | 9 | - #### Use try-catch 10 | 11 | Try-catch is a JavaScript language construct that you can use to catch exceptions in synchronous code. Use try-catch, for example, to handle file(JSON, org and other) parsing errors as shown below. 12 | 13 | *** 14 | 15 | - #### Don’t use synchronous functions 16 | 17 | Synchronous functions and methods tie up the executing process until they return. 18 | 19 | *** 20 | 21 | - #### Use ES2015 22 | 23 | A year passed and ES2015 support grew to 99% with Node v6. 24 | 25 | *** 26 | 27 | - #### Use Promises 28 | 29 | Promises will handle any exceptions (both explicit and implicit) in asynchronous code blocks that use then() 30 | 31 | *** 32 | 33 | - #### Use JS CodeStyle 34 | 35 | For the help this point use: 36 | - ESLint 37 | - JSHint 38 | 39 | *** 40 | 41 | 42 | - #### Use JWT for your REST API 43 | 44 | JWT consist: 45 | 1. Header 46 | 2. Payload 47 | 3. Signature for your payload 48 | 49 | *** 50 | 51 | - #### Use HTTP Methods for your RESTful API 52 | 53 | *** 54 | 55 | - #### Use a small subset HTTP status codes 56 | 57 | For example only main status code: 58 | 200. OK status 59 | 201. Created 60 | 304. Not Modified 61 | 400. Bad Request 62 | 401. Unauthorized 63 | 403. Forbidden 64 | 404. Not Found 65 | 500. Internal Server Error 66 | 67 | *** 68 | 69 | - #### Pick good framework for your NODE.js REST API 70 | 71 | Frameworks: 72 | 1. Express 73 | 2. Koa 74 | 3. Restify - for build strict API services 75 | 4. Hapi 76 | 77 | *** 78 | 79 | - #### Test your NODE.js REST APIs 80 | 81 | *** 82 | 83 | - #### Create documentation for your NODE.js REST APIs 84 | 85 | *** 86 | ___ 87 | ## Video link with best practices: 88 | 89 | 1. [JavaScript best practices, Node.js, and how to end poverty with Eric Elliott](https://www.youtube.com/watch?v=pVNagJzzaFg) - 17 Jun. 2015 90 | 2. [Panel: Best Practices for Contributing to Node.js Core - James Snell, IBM](https://www.youtube.com/watch?v=sZdPHi5EMKI) - 24 Sep. 2016 91 | 3. [Best Practices using TypeScript with Node.js by Bryan Hughes, Microsoft](https://www.youtube.com/watch?v=ATUvAQZaTbM) - 15 Dec. 2016 92 | 93 | 3. [Performance and Highly Scalable Micro-Services](https://www.youtube.com/watch?v=Fbhhc4jtGW4) - 31 Oct. 2017 -------------------------------------------------------------------------------- /frontend/react/bestPracticeReact.md: -------------------------------------------------------------------------------- 1 | # React Best Practices 2 | - #### Create reusable component 3 | (better without mutation) 4 | It should encapsulate the smallest element possible that can potentially be reused. 5 | 6 | *** 7 | 8 | - #### Create composable component 9 | Not need create the same component with small changes or component with hard structure. Better think about how create composable component. 10 | *** 11 | 12 | - #### Importing components without relative paths 13 | If you use webpack, use setting resolve.alias 14 | 15 | ```javascript 16 | //for example 17 | resolve: { 18 | modules: [path.resolve('./node_modules')], 19 | alias: { 20 | Components: path.resolve(__dirname, '../../../../ui-component/component') 21 | }, 22 | extensions: ['.js', '.jsx', '.json', '.scss'] 23 | } 24 | ``` 25 | Now we have problem with alias in webpack 2 see [issue](https://github.com/webpack/webpack/issues/4160#issuecomment-281236136) 26 | *** 27 | - #### Create functional component 28 | ```javascript 29 | //for example 30 | const MyComponent = props => ( 31 |