Last active
December 17, 2015 15:09
-
-
Save sent-hil/8d09ebaa3a9f1b8cf525 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Comments prefixed with // & space. | |
// right | |
//wrong | |
2. No blank lines between for & next line. | |
for _, name := range notAllowedSuffixes { | |
if strings.HasSuffix(sourceName, name) || strings.HasSuffix(targetName, name) { | |
} | |
} | |
3. If last line is return, add blank line above. | |
do_something() | |
result := do_something_else() | |
return result | |
} | |
4. Declare `var` right above they're used, not at top of function, | |
unless in global scope. | |
5. No blank lines between }}. | |
} | |
} | |
6. Group code together by chunks, if more than 1 line. | |
// hard to read | |
relationshipsURL := nodeURL + "/relationships/all" | |
response := sendRequest("GET", relationshipsURL, "") | |
relations, err := jsonArrayDecode(response) | |
7. Error checking if statements shouldn't have else. | |
// leads to node style callback staircase | |
if err != nil { | |
fmt.Println(err) | |
} else { | |
neo4j.UpdateNode(sourceId, sourceContent) | |
} | |
8. Fail as loudly as possible, log unexcepted data. | |
if sourceName == "" { | |
// log here | |
} | |
9. Wrap at 80, no less than 60; second & more lines should have more | |
indentation. | |
return fmt.Sprintf( | |
`{"key":"id","value":"%s","properties":{"id":"%s","name":"%s"}}`, | |
id, id, name) | |
10. Avoid creating strings with +, use fmt.Sprintf() | |
url := "amqp://" + user + ":" + password + "@" + host + ":" + port | |
11. Anonymous return values. | |
// right | |
func say(word string) string {} | |
// wrong | |
func say(word string) (greeting string) {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment