{"action":"created","issue":{"url":"https://api.github.com/repos/deric92/WebSocketApp/issues/1","repository_url":"https://api.github.com/repos/deric92/WebSocketApp","labels_url":"https://api.github.com/repos/deric92/WebSocketApp/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/deric92/WebSocketApp/issues/1/comments","events_url":"https://api.github.com/repos/deric92/WebSocketApp/issues/1/events","html_url":"https://github.com/deric92/WebSocketApp/issues/1","id":154395924,"number":1,"title":"Suggestions","user":{"login":"thehydroimpulse","id":565790,"avatar_url":"https://avatars.githubusercontent.com/u/565790?v=3","gravatar_id":"","url":"https://api.github.com/users/thehydroimpulse","html_url":"https://github.com/thehydroimpulse","followers_url":"https://api.github.com/users/thehydroimpulse/followers","following_url":"https://api.github.com/users/thehydroimpulse/following{/other_user}","gists_url":"https://api.github.com/users/thehydroimpulse/gists{/gist_id}","starred_url":"https://api.github.com/users/thehydroimpulse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thehydroimpulse/subscriptions","organizations_url":"https://api.github.com/users/thehydroimpulse/orgs","repos_url":"https://api.github.com/users/thehydroimpulse/repos","events_url":"https://api.github.com/users/thehydroimpulse/events{/privacy}","received_events_url":"https://api.github.com/users/thehydroimpulse/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-05-12T04:43:48Z","updated_at":"2016-05-14T14:52:16Z","closed_at":null,"body":"/cc @deric92 \r\n\r\n1. Use environment variables instead of hard coding them into your code.\r\n\r\n```bash\r\n# ~/.bash_profile (or ~/.bashrc or ~/.zshrc)\r\nexport DB_HOST=\"...\"\r\nexport DB_USER=\"...\"\r\nexport DB_PASS=\"...\"\r\nexport DB=\"...\"\r\n```\r\n\r\nThen use it in your code:\r\n\r\n```js\r\nconst dbConfig = {\r\n  host: process.env.DB_HOST,\r\n  user: process.env.DB_USER,\r\n  pass: process.env.DB_PASS,\r\n  db: process.env.DB\r\n};\r\n```\r\n\r\nNow that your credentials have been leaked publicly, you'll want to change the username and password in AWS asap. Assume that someone has gotten their hands on those credentials (lots of bots scan github for this kind of stuff).\r\n\r\n2. Indent, indent, indent.\r\n\r\nThis will probably improve the readability of your code by 100x. Indent by 2 spaces and keep the nesting consistent. Use auto indent tools to help you.\r\n\r\n3. Never have more than one empty line sequentially.\r\n\r\ne.g.,\r\n\r\nBad:\r\n\r\n```js\r\n\r\nvar foobar = 123;\r\n\r\n\r\nfunction done() {}\r\n```\r\n\r\nGood:\r\n\r\n```js\r\nvar foobar = 123;\r\n\r\nfunction done() {}\r\n```\r\n\r\n\r\n3. Remove useless comments.\r\n\r\nComments like `// START HERE` or `// CONFIG` are bad and don't do anything to improve readability. Never comment about the *what*, comment about the *why*.\r\n\r\n4. Don't use `var` anymore. It's going to cause you a lot of pain because it's not lexically scoped.\r\n\r\nIf the variable doesn't change, use `const`.\r\n\r\n```js\r\n// bad\r\nvar fs = require('fs');\r\n// good\r\nconst fs = require('fs');\r\n```\r\n\r\nIf the variable needs to change, use `let`.\r\n\r\n```js\r\n// bad\r\nvar a = 2;\r\na = 3;\r\n// good\r\nlet a = 2;\r\na = 3;\r\n```\r\n\r\nLet has lexical scoping.\r\n\r\n```js\r\n// wrong\r\nfor (var i = 0; i < 5; i++) {\r\n   // ...\r\n}\r\n\r\nconsole.log(i);\r\n\r\n// good\r\nfor (let i = 0; i < 5; i++) {\r\n\r\n}\r\n\r\nconsole.log(i);\r\n```\r\n\r\nTry this out and you'll see they don't do the same thing. `let` semantics is what you want.\r\n\r\n5. Use strict mode\r\n\r\nTo use `let`, you'll need to enable strict mode, which is recommended anyways.\r\n\r\n```js\r\n'use strict';\r\n\r\nlet a = 2;\r\na = 3;\r\n```\r\n\r\nAt the top of every file, put `'use strict';`\r\n\r\nMost of this is about learning on the way. Javascript has a lot of bad parts to it, so it's hard to only learn the good ones."},"comment":{"url":"https://api.github.com/repos/deric92/WebSocketApp/issues/comments/219224444","html_url":"https://github.com/deric92/WebSocketApp/issues/1#issuecomment-219224444","issue_url":"https://api.github.com/repos/deric92/WebSocketApp/issues/1","id":219224444,"user":{"login":"deric92","id":14207512,"avatar_url":"https://avatars.githubusercontent.com/u/14207512?v=3","gravatar_id":"","url":"https://api.github.com/users/deric92","html_url":"https://github.com/deric92","followers_url":"https://api.github.com/users/deric92/followers","following_url":"https://api.github.com/users/deric92/following{/other_user}","gists_url":"https://api.github.com/users/deric92/gists{/gist_id}","starred_url":"https://api.github.com/users/deric92/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deric92/subscriptions","organizations_url":"https://api.github.com/users/deric92/orgs","repos_url":"https://api.github.com/users/deric92/repos","events_url":"https://api.github.com/users/deric92/events{/privacy}","received_events_url":"https://api.github.com/users/deric92/received_events","type":"User","site_admin":false},"created_at":"2016-05-14T14:52:16Z","updated_at":"2016-05-14T14:52:16Z","body":"> Here's a codified style guide you should follow: https://github.com/airbnb/javascript\r\n\r\nI'll definitely slowly introduce those habits into my code over time.  Going to be a challenge but so worth it over time."}}