TYPING NO COMPILE TIME BUT THEY ALSO HAVE THE "BAD": Slow Not type-safe (static errors occur at runtime) Doesn't scale well They're also not very modern (+10 years)
TYPED FAST EXECUTION, FAST COMPILERS LIGHT AND EASY TO WRITE FAST TO WORK IN SCALES WELL DOESN'T REQUIRE TOOLS, BUT SUPPORTS THEM WELL GOOD AT NETWORKING AND MULTIPROCESSING
compiled, but it feels lightweight and dynamic Designed for modern computing (multicore) Aimed at software such as webservers, but turned out to be a great general-purpose language
n g h t t p : / / l o c a l h o s t : 8 0 8 0 / w o r l d : p a c k a g e m a i n i m p o r t ( " f m t " " n e t / h t t p " " l o g " ) 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 , % q " , r . U R L . P a t h [ 1 : ] ) } ) l o g . F a t a l ( h t t p . L i s t e n A n d S e r v e ( " : 8 0 8 0 " , n i l ) ) }
n c G r e e t i n g ( p r e f i x s t r i n g , w h o . . . s t r i n g ) G r e e t i n g ( " h e l l o : " , " J o e " , " A n n a " , " E i l e e n " ) [ ] s t r i n g { " J o e " , " A n n a " , " E i l e e n " }
Channel sends c h < - v a l u e Channel receive v a l u e = < - c h Starting a goroutine f u n c ( s * S e r v i c e ) S t a r t ( ) c h a n r e q u e s t { c h : = m a k e ( c h a n r e q u e s t ) g o s . s e r v e ( c h ) / / s . s e r v e r u n s c o n c u r r e n t l y r e t u r n c h / / r e t u r n s i m m e d i a t e l y }
p o r t " g i t h u b . c o m / b m i z e r a n y / p a t " Two purposes, import path and library repository Just push your code to a public repository The "go get" command download and install all rependencies Easy to define, easy to use
(pointers but no pointer arithmetic) Consistent standard library Integrated testing Ultra fast compiler (can be used as scripting language) Target i386, amd64, arm (Mobile development) BUT.. AS ANY RESPECTED LANGUAGE ALSO HAS DRAMAS!
Actor model, Go implements goroutines Scala has thread based Actors that are heavyweight goroutines are lightweight, threads are heavy All three models uses channels for messages In Scala passing around primitive data like integers is expensive because of the JVM legacy
for server programming Awesome standard lib but not enought Go stdlib, http, templates, websockets, tar/zip, json, xml, sql, smtp, etc... node code is by definition non-blocking and asynchronous Go let's you write synchronous looking code which behaves like if it were asynchronous, without requiring you to handle the callback spaghetti Many libs in Go stdlib are non-blocking
http://teddziuba.com/2011/10/node-js-is-cancer.html node.js v a r h t t p = r e q u i r e ( ' h t t p ' ) ; f u n c t i o n f i b o n a c c i ( n ) { i f ( n < 2 ) r e t u r n 1 ; e l s e r e t u r n f i b o n a c c i ( n - 2 ) + f i b o n a c c i ( n - 1 ) ; } h t t p . c r e a t e S e r v e r ( f u n c t i o n ( r e q , r e s ) { r e s . w r i t e H e a d ( 2 0 0 , { ' C o n t e n t - T y p e ' : ' t e x t / p l a i n ' } ) ; r e s . e n d ( f i b o n a c c i ( 4 0 ) + ' ' ) ; } ) . l i s t e n ( 1 3 3 7 ) ;
e m a i n i m p o r t ( " f m t " " n e t / h t t p " " l o g " ) f u n c f i b o n a c c i ( n i n t ) ( r e s u l t i n t ) { i f n < 2 { r e s u l t = 1 } e l s e { r e s u l t = f i b o n a c c i ( n - 2 ) + f i b o n a c c i ( n - 1 ) } r e t u r n } 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 e q * h t t p . R e q u e s t ) { w . W r i t e ( [ ] b y t e ( f m t . S p r i n t f ( " % d " , f i b o n a c c i ( 4 0 ) ) ) ) } ) l o g . F a t a l ( h t t p . L i s t e n A n d S e r v e ( " : 8 0 8 0 " , n i l ) ) }
c u r l h t t p : / / l o c a l h o s t : 1 3 3 7 1 6 5 5 8 0 1 4 1 r e a l 0 m 2 . 0 9 7 s u s e r 0 m 0 . 0 0 7 s s y s 0 m 0 . 0 0 5 s Go 1.2 t i m e c u r l h t t p : / / l o c a l h o s t : 8 0 8 0 1 6 5 5 8 0 1 4 1 r e a l 0 m 1 . 3 2 3 s u s e r 0 m 0 . 0 0 7 s s y s 0 m 0 . 0 0 5 s