How do you define a "good code"? How to write high-quality software with assistance of linters and static analysis.
Using golint, govet and gofmt can improve our code.
19. is a tool that analyzes source code to flag
programming errors, bugs, stylistic errors,
and suspicious constructs
- Wikipedia
What is a linter?
“
20. Lexer and Parser
● Lexer: converts the statements in code into various
categories of like keywords, constants, variable in a
sentence and produce token
● Parser: takes the tokens produced by the lexer and tries
to determine whether these statements are semantically
correct
27. Homoiconicity
● The code used to express a program is
written using the data structures of
that language
● The Lisp family languages (Common
Lisp, Scheme, Clojure, etc)
● Code is Data, Data is Code
29. ● gofmt - Must have for every project
● goimports - Additionally to gofmt, checks unused imports
● unindent - Report code that is unnecessarily indented
Code Formatting
32. ● abcgo - ABC metrics for Go source code.
● gocyclo - Computes and checks the cyclomatic
complexity of functions.
● splint - It finds any functions that are too long or have too
many parameters or results.
Code Complexity
35. ● GoLint - Golint is a linter for Go source code
● revive - Drop-in replacement of golint
● go-namecheck - helps you to maintain variable/field
naming conventions inside your project
● lll - Line length linter, used to enforce line length in files
Style and Patterns Checking
37. Revive
● Allows to enable, disable, configure
rules using a TOML file
● Allows disabling a specific rule or
the entire linter for a file or a range
of lines
● Provides multiple formatters which
let us customize the output
43. ● govet - checks correctness: a vet check identifies real or
potential bugs that could cause incorrect compilation or
execution
● badtime - Badtime is a Golang linter that detects
inappropriate usage of the time.Time struct.
● safesql - Static analysis tool for Golang that protects
against SQL injections.
Bugs
48. References
● Code Complete: A Practical Handbook of Software Construction
● Effective Go
● golang/lint Repository
● SourceLevel: Team Metrics and Automated Code Review
● How do you define “Good Code”?
● Awesome Go Linters
● scanner Package
● Basic AST Manipulation in Go
● Internal vs External Software Quality
49. References
● Code Complete: A Practical Handbook of Software Construction
● Lexical Scanning in Go - Rob Pike