ptg16105617
THE GO PROJECTxv
Or ganization ofthe Book
We assume thatyou haveprogrammed inone ormoreother langu ages, whether comp ile d li ke
C, C++, andJava, orint erprete d li kePyt hon,Ruby, and JavaS crip t,sowewon’tspell out every-
thing as if for a tot albeg inner.Sur face sy ntaxwill befami liar, as will var iables andcon stants,
expressions,control flow,and functions.
Chapter1 isatut orialonthe basic cons tructsofGo, int roduce d thro ugh a dozen programsfor
ever ydaytasks like readingand writing files, for matting text, creating images, andcommuni-
cating wit h Internet clients andser vers.
Chapter2 des crib esthe str uctural elements ofaGoprogram—de clarat ions,var iables, new
types, packages and files, andscope.Chapt er3 dis cussesnumbers,boole ans, str ings, andcon-
st ants, andexplainshow topro cessUnico de.Chapt er4 des crib escomposite typ es, that is,
typesbui ltupfro m simpler onesusingarrays, maps, str ucts, and sli ces,Go’sappro ach to
dy namic lists. Chapt er5 cov ers functions and dis cusseserror handling, panic and recover,
andthe defer st atement.
Chapters 1 through 5 are thu s thebasics, things thatare par t of any mainst reamimp erat ive
language . Go’ssyntaxand sty lesom etimesdif fer fro m ot her langu ages, but mostprogram-
mers will pickthemupquickly. The remainingchapt ers focus ontopics where Go’sappro ach
is lessconvent ion al: met hods, interfaces, conc urrency,packages, testing , andreflec tion.
Go has an unusualappro ach to obj e ct-oriente d prog ramming. There are noclass hierarchies,
or indeed any class es; comp lex obj e ctbeh avior s arecre ate d from simpler onesbycomposition,
notinher itance. Met hodsmay beass oci ated wit h anyuser-define d type,not juststr uctures,
andthe rel ation shipbet weencon crete typ es andabstrac t types(interfaces)isimp licit, soa
concrete typ e maysat isf y an interface thatthe typ e’sdesig ner was unawareof. Met hodsare
covere d in Chapt er6and int erfaces in Chapt er7.
Chapter8 presentsGo’sappro ach to con cur rency,whichisbas edonthe ide a of communic at-
ingsequential pro cesses(CSP), embodie d by goroutinesand channel s.Chapt er9 explainsthe
more tradition alasp ectsofcon cur rency bas edonshare d var iables.
Chapter10des crib espackages, the mech anism for organizinglibrar ies. Thischapt erals o
shows how tomakeeffec tive use ofthe go to ol, whichprovides for compi lat ion, testing ,
benchmarking , prog ram formatting , do cumentation,and manyother tasks, allwit hin a single
command.
Chapter11deals wit h test ing , whereGotakes a not ably lig htweig htappro ach,avoiding
abstrac tion-l aden framewor ksinfavor of simplelibrar ies andtools.The testing librar ies
prov ide a found ation atopwhichmorecomplex abstrac tions can bebui lt if necessary.
Chapter12dis cussesreflec tion,the abi lit y of a prog ram to examineits own represent ation
during exe cut ion.Reflec tion isapow erfultool, thoug h on e to beusedcaref ully; thischapt er
explains findingthe rig htbal ance byshowing how itisusedtoimp lementsom e importantGo
librar ies. Chapter13explainsthe gor y det ails oflow-le vel programmingthatusesthe unsafe
packagetosteparo und Go’styp e system, andwhenthatisappro priate.
The Go Programming Language
© 2016 Alan A. A. Donovan & Brian W. Kernighan
revision 3b600c, date 29 Sep 2015
From the Library of YIGUANG HU