2020年/02月/26日
Golang之禅
文中引用很多经典的言论以及和python之禅的对比
“Design is the art of arranging code to work today, and be changeable forever.”
Sandi Metz
Most programming languages start out aiming to be simple, but end up just settling for being powerful.
— Dave Cheney (@davecheney) December 2, 2014
“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”
C. A. R. Hoare, The Emperor’s Old Clothes, 1980 Turing Award Lecture
“Simplicity is prerequisite for reliability.”
Edsger W Dijkstra, EWD498, 18 June 1975
“Controlling complexity is the essence of computer programming.”
Brian W. Kernighan, Software Tools (1976)
“I think that error handling should be explicit, this should be a core value of the language.”
Peter Bourgon, GoTime #91
“Line of sight is a straight line along which an observer has unobstructed vision.”
May Ryer, Code: Align the happy path to the left edge
“APIs should be easy to use and hard to misuse.”
Josh Bloch
“You type g o, a space, and then a function call. Three keystrokes, you can’t make it much shorter than that. Three keystrokes and you’ve just started a sub process.”
Rob Pike, Simplicity is Complicated, dotGo 2015
glang之禅
Each package fulfils a single purpose
Handle errors explicitly
Return early rather than nesting deeply
Leave concurrency to the caller
Before you launch a goroutine, know when it will stop
Avoid package level state
Simplicity matters
Write tests to lock in the behaviour of your package’s API
If you think it’s slow, first prove it with a benchmark
Moderation is a virtue
Maintainability counts