but they don't do much to prevent the quality problems we're experiencing. In the hour before I wrote this slide, we had 1329 AttributeErrors in production. This is fixable in Python, but we should be free to choose other tools if they're more appropriate - especially for loosely-coupled services.
a free lunch. Python & Django are great at some things, but they're not perfect. Good Bad expressive slow ὐ included clumsy concurrency & parallelism duck-typing runtime errors minimal ceremony poor encapsulation exceptions exceptions In general, we work around Python's weak points with conventions and tests.
this week: As code quantity, code complexity, and number of developers increase, conventions scale poorly. There's too much tribal knowledge. Said differently, Murphy's Law always wins.
application. That said, writing tests is work. We need lots of tests to be safe (for the class of errors we're talking about) If we write tests like that, what's the net gain in development velocity? When Python & Django are doing a lot of heavy lifting for us, it's worth writing enough tests to be confident in our code. For tasks that don't leverage much of Django, we should use tools that do more to support us.
Statically typed and compiled to machine code Designed for writing clean server code at scale Feature-wise, it has Great concurrency primitives An unusual take on object orientation ὐ included (but different) It's a language for working programmers, not researchers or academics.
a i n i m p o r t ( " f m t " " n e t / h t t p " ) f u n c m a i n ( ) { h t t p . H a n d l e F u n c ( " / " , f u n c ( w h t t p . R e s p o n s e W r i t e r , r * h t t p . R e q u e s t ) { f m t . F p r i n t f ( w , " H e l l o , 世界" ) } ) h t t p . L i s t e n A n d S e r v e ( " : 1 3 3 7 " , n i l ) } Run
easier. f u n c m a i n ( ) { g r e e t i n g : = " H e l l o , 世界" f m t . P r i n t l n ( g r e e t i n g ) u n i c o d e : = [ ] r u n e ( g r e e t i n g ) f o r p o s , p o i n t : = r a n g e u n i c o d e { f m t . P r i n t f ( " R u n e % d i s a t p o s i t i o n % d . \ n " , p o i n t , p o s ) } } Run
d a b l e i n t e r f a c e { R e a d ( p [ ] b y t e ) ( n i n t , e r r e r r o r ) } f u n c h e a d ( r R e a d a b l e ) s t r i n g { b u f : = m a k e ( [ ] b y t e , 5 0 ) n , _ : = r . R e a d ( b u f ) r e t u r n s t r i n g ( b u f [ : n ] ) } f u n c m a i n ( ) { f i l e , _ : = o s . O p e n ( " c o d e / z e n . t x t " ) f m t . P r i n t l n ( h e a d ( f i l e ) ) r e s p o n s e , _ : = h t t p . G e t ( " h t t p : / / h e a r s a y s o c i a l . c o m " ) f m t . P r i n t l n ( h e a d ( r e s p o n s e . B o d y ) ) } Run
) { e n g : = g o c h a t . N e w L i s t e n e r ( " E n g i n e e r i n g " ) g o e n g . L i s t e n ( ) i n f r a : = g o c h a t . N e w L i s t e n e r ( " I n f r a s t r u c t u r e " ) g o i n f r a . L i s t e n ( ) f o r { s e l e c t { c a s e m s g : = < - e n g . M e s s a g e s : f m t . P r i n t l n ( " E n g i n e e r i n g : " , m s g . M e s s a g e ) c a s e m s g : = < - i n f r a . M e s s a g e s : f m t . P r i n t l n ( " I n f r a s t r u c t u r e : " , m s g . M e s s a g e ) } } } Run
) ( t e x t s t r i n g , e r r e r r o r ) { f i l e , e r r : = o s . O p e n ( " c o d e / z e n . t x t " ) i f e r r ! = n i l { r e t u r n } b u f : = m a k e ( [ ] b y t e , 1 0 0 0 ) n , e r r : = f i l e . R e a d ( b u f ) i f e r r ! = n i l { r e t u r n } r e t u r n s t r i n g ( b u f [ : n ] ) , e r r } f u n c m a i n ( ) { z e n , e r r : = z e n ( ) i f e r r ! = n i l { f m t . P r i n t l n ( e r r ) r e t u r n } f m t . P r i n t l n ( z e n ) } Run
in the standard distribution: Cross-compiling, runtime race detection: go build Source-driven dependency management: go get Unambiguous, tooling-enforced formatting: go fmt Linting: go vet Source-driven documentation: go doc Integrated testing framework: go test Production-ready webserver, routing, and templating. Go takes tooling seriously.
golang repo (https://github.com/hearsaycorp/golang) with githooks. Chef recipe (already installed on dev machines) Jenkins job to build, lint, test, and archive packages Deployment from S3
Write Go Code (http://golang.org/doc/code.html) The interactive tour (http://tour.golang.org/#1) Effective Go (http://golang.org/doc/effective_go.html) Concurrency Is Not Parallelism (http://www.youtube.com/watch?v=cN_DpYBzKso) There are Django-style mega-frameworks, Flask-style micro-toolkits, BDD and xUnit- style testing, and database-agnostic ORMs available Plugins for emacs, vim, Sublime Text, JetBrains, and Eclipse available