dotGo 2014 - Andrew Gerrand - 5 things I love (or why you should learn Go)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

Anyone have the links to the talks about concurrency that Andrew mentioned?

👍︎︎ 1 👤︎︎ u/the_BuddhaHimself 📅︎︎ Nov 06 2014 🗫︎ replies
Captions
so you probably all know go go is a programming language and it was created in 2008 at Google and it was created to solve problems at Google's kind of scale and what do I mean by sket Google scale I mean scale in terms of running on clusters of thousands of machines in dozens of data centers around the world but I also mean this kind of scale this is from the 2008 annual report of Google and we had more than 7,000 people in research and development that's engineering and today we have almost twice that number so that's huge teams of programmers working on massive code bases of you know millions of lines of code so what are the important factors at scale well first of all we need speed both in terms of development speed and also in terms of execution speed efficiency second is reliability you need code that does what you expect it does and the third is simplicity at scale you really need to fight this kind of systemic complexity that can really weigh you down in the long term so in 2008 we were kind of locked in this deadly embrace at Google anyway with C++ and Java and Python and on the C++ side we had a lot of speed but to write C++ code reliable reliably is very difficult and obviously it's not simple it's actually an incredibly complex language on the with Java we had a language that was still quite efficient and easier to write correctly and quite reliable but it suffers from this massive systemic over complexity and with Python we had a language that developers loved using it's a highly productive language but it's quite inefficient at runtime and also its kind of absence of a type system or rather an invisible type system can lead to some sort of problems so when go was created we just tried to address the gap between these kind of three technologies that we were so accustomed to at the time but it turns out that what works at scale also helps in the small in teams of smaller people and also just individuals like myself so what I want to talk about today the five things that i love about go me personally and you know i understand probably most of you here i've already written some go codes some of some of you professionally and so you can just kind of cheer along if if you agree so the first thing that I love interfaces go into phases are small so this is a you know be canonical going to face the stringer interface they usually have one of few methods and this kind of smallness is great for flexibility and they're easy to understand and the easy to implement an interfaces are satisfied implicitly this point type is a stringer simply cuz it implements the string method and importantly interfaces are composable they encourage composability so what do I mean by that well if you take like the reader and writer interfaces their streams of binary data and go we have all these different implementations but you know network connections files compresses the oppressors and so on and so in this program here i have a geez if reader that reads from standard input and then i copy the unzipped standard input just added output so it's just an implementation of Gion zip but what we're seeing here is the composition of these three different interfaces and the connection with these connector functions like IO copy another example of some code I wrote earlier today I needed to enclose an XML with a element top element before I could decode it and I was able to use multi reader to compose to string readers and avid reader together to form just one stream of XML data and it's interesting to note that for all of the utility in those i/o packages they actually weren't designed from day one the the OS package already existed before the i/o package came along and the i/o package only sort of came into existence after we implemented the by its package with its buffer time and we saw this at a commonality between the two implementations and so what that means is that interfaces kind of capture behavior that emerges in your programs and oftener declared after the fact and finally interface is a key they're the tool for abstracting functionality and go you know there's no generics no classes no inheritance and so once you understand how interfaces work you understand how to do is type system works and that's tremendous benefit for readability and simplicity but why do I love interfaces basically interfaces just help me write good code quickly I can just write the code that's in my head to solve the problem that I have and then after the fact I can see the patterns that emerge in my code and use interfaces to abstract and generalize my code and the really nice thing about is the whole time my slave type safety so I'm I came from a dynamic language kind of background and I used to do this you know in Python or Java Script and but without the type safety I never felt like I I could safely refactor things I never felt like I could really dive in there and make changes and so with ghost type safety interfaces I'm able to do that without fear and get a lot more work done so the second thing that I love probably predictably is concurrency gos concurrency model to be exact so everyone knows go routines of the basis of concurrent execution and go you put a go static keyword in front of a function call that function call runs in a new girl routine channels at the second piece of gos concurrency puzzle and they express importantly communication and synchronization and so you know in this example we have a go routine that's generating number from the Fibonacci sequence and the main girl routine is consuming those but they're kept in lockstep by the synchronous nature of channels the send only proceeds when the receiving side is ready this is a really powerful construct for expressing something that's difficult to achieve in other environments and finally the third piece is a select statement which enables you to compute on channel operations so you know if I wanted to add the ability to shut down that Fibonacci loop I can just add a quit channel and send a quick message and then in the main loop of energy we have this select statement which which muxes on those channel operations and the really nice thing about this is most concurrent go programs have some select statement like this at their heart and so it's a really nice and natural way of expressing what's actually kind of difficult concept I'd love to talk more about concurrency at length but if you're more interested you should definitely check out one of these are both of these two talks but why do I love goes concurrency model basically it just feels natural to me to to use gos concurrency features you know if I have some code that's that's like this it does something something else and so on and I realized that the second and third things can be done concurrently I can just add some channels and some goroutines and suddenly I have concurrency and it just works and the reason this works is that the concurrency model is by is always there in the background and so it's there when you need it but it doesn't force you to write code in a particular style you don't need to break your code up into these sets of callbacks you don't need to manage thread pools and so on you don't need to keep all this stuff in the back of your mind if you're not thinking about concurrency but when you do decide to think about concurrency the tools are all there and you can use them straight away the third thing that I love about workspaces event about go is work spaces so a workspace is where you keep your go code it's also where you keep everyone else's go code and so you nominate the location of your workspace with the go path environment variable in that directory you have a source been packaged directories that contain source code binary executables and intermediate library build artifacts respectively and here's a really small go path that contains just a single repository from the go examples repository on github and it contains two packages the hello package which is a executable and the string util package which is a library and if we take a look at the hell 000 file we can see that it imports the string use your package by its full path and it uses that the reverse function from the string you your package to reverse a string and it's interesting to note that the import path is actually the full qualified name of that of that package inside the workspace and so if I go into the hello directory and run go install it builds and links both the string util package and the hello binary and installs it to the workspaces bin directory so I can execute it and so now the workspace looks something like this and that string util dot a file can be used you know as a if incremental builds and so on the go tools also responsible for doing things like running tests and also fetching remote dependencies and because we use the full repository address for the base of the input path the goat or can just resolve dependencies across the internet from anywhere which is a really convenient thing this is a audio synthesizer that I wrote that uses a few external packages and that's what gets pulled in when you run good luck yet um there's a lot more to be said about workspaces particularly surrounding dependency management and reproducible builds and I encourage you to check out either of these pieces from conferences this year also I believe Keith Eric pretty shortly is going to give a talk on a similar topic but if I have one thing to say about workspaces a piece of advice go path should be set to your home directory and you don't have to obviously but that's that's that's what I do and having a bin directory and your home directory where all your go executables are is is really convenient but why do I love workspaces first of all not having any make files or build XML files or any of these kind of like build manifests to keep in sync with my code is huge productivity I don't have to remember the syntax of make files which I even I two decades of using mac files I still can't remember exactly how they work because I would change them so sell them every time I need to do something complex so i have to refresh my memory about how it works and and so i know that if i just write my go code and the go code is correct then the build system knows how to build my go code and that's that's huge for productivity secondly everyone already knows how to use workspaces like we all know how file system works I hope and we all know how our VCS is work I guess but the thing is the go the goat fall and workspaces it just takes those two things and lets them do their job well the goat will just handles building 3rd I love workspaces because they enable great tools so you've probably all seen go dr. dog a site that will fetch documentation from arbitrary repositories on the internet so if you looked at the docs for the string you two'll package at go dr. dog that's what you would see and this has just been I think vital to the NGO community and the go ecosystem in terms of visibility of go packages and also encouraging people to write documentation and I think anything that encourages people to document their code it's got to be a huge benefit and that's really just the tip of the iceberg in terms of the kind of tooling the workspace is enable and i'll talk about something more later the fourth thing I love is go font go fund is the the pretty printer for go source code so it takes code that looks like this and turns it into that and you know why do I live grow from termine it's kind of obvious right but first of all it ends formatting wars so raise your hand if you've ever had an argument with a colleague about the position of a brace or a semicolon for the video every single person the audience is resume and right now was it worth it though no yes get out so simply ending the formatting Wars is huge for productivity you should never be having an argument with someone about white space it's insane secondly most code is is in go front form I a couple of years ago I downloaded all of the go source code the open source go source code on the internet and analyzed it and I found that at least eighty percent of it was in the go from standard form I think that number that proportion is probably higher today and interestingly the weather it was go from did or not was a signal about the quality of the code as well like I would look at the code that wasn't go from to intended to be kind of bad so for all intents and purposes you can just assume that all go crowd that you want to use is in go font style and this enables mechanical source manipulation so the type of the the packages that go from tis built with are these go parser go printer go AST packages in the standard library and those packages can be used not just for reforming and go source code but also for manipulating go source code mechanically and so those of you who use go around the time of go one you might remember go fix when we release go one in 2012 we made changes to the the language in the standard libraries i'm quite wide sweeping changes but we knew that you know we had this huge community switch to support both in the open source world and also inside google and so when we migrated to go one we provided this tool go fix it was backed by the same technology of go font and on the day the go one was released you could just run go fix on your code and it would automatically update like ninety-nine percent of the things you needed to do to update to go one and this was huge because it just obviated the entire need for dealing with versioning it was like if you're not using go one you should just run go fix and then you're using go on and also because the code was in go font style already any of the go fixes changes in the diffs were purely semantics there were no whitespace changes so that's that's a critical importance since then a lot more static analysis tools have been developed for growth analyzing go source code and how it executes sand what its types are and so on and so now we have this package this command rather called go rename which is a type of we're renaming tool for go sauce and so these two lines would rename the Jason Marshall and unmarked shins to encode and decode but because its type aware and because its workspace aware it will actually rename those those types across not just in the JSON package but also in all of your packages that use those packages in your workspace and so this you should check it out it's available in the go tools repository and there's a lot more tooling besides that all this stuff enables for instance my fifth and final love which is going ports who here uses going ports actually awesome so about half so go going ports is basically go from that is aware of workspaces and so it'll take code like this this is just a simple program that return that prints the char three hash of the standard input and so if I had this in my editor and I have go imports on my unsafe hook when I hit save it goes from this to that right and so it's written basically half the program for me all of those import statements and then and so what do I love about going ports what isn't it obvious i just showed you it will bat and turn it into that but it's not just the first time you hit save it's also as you keep working it's constantly adding and removing dependencies depending on what your code is actually doing and so this really increases the velocity with which i can get things done and go also go is fastidious about enforcing the usage of packages that you import if you import a package log and then you don't use it you get a compile error like this but thanks to going ports I haven't seen that error message in a really long time and I'm you know I don't regret it or I don't miss it rather so um I just thought I'm sort of trying to finish with a story like a few months ago I was working at work it's a good place to do it and I was sending Gophers which I guess all of you have one off right now yay and I was sending them to each of the people at Google who have committed go code inside Google and to do that I needed to make a query against our code search engine to find all the authors of go code and then I needed to query our organization store to find the employee records and the desk locations all of the Google is around the world who'd commit a guy code and so you know I Romo will go program I was you know using the the various protocol buffers to access services making some requests in parallel using some girl routines channels and you know I wrote this kind of 20 lines of code to access these services and print out the sort of list of death numbers and then when I hit save going for its word into action we have a version of go imports internal to google that uses that can access our entire corpus of go occurred inside google and it populated like this 15 lines of import statements and because this is google everything is bigger and more complicated than it needs to be and so the the import statements were sometimes like 60 characters plus you know and this was all stuff that i didn't need to write and in fact I didn't even need to think about and like when I hit save and I saw that up here I just kind of like it it crystallized you know something that I felt about go for a long time which is that you know go is much more than just a language like the language is just a nice solid basis for for constructing this ecosystem that we've built on top of it you know if there's great standard libraries and like those I our packages and so on and then all of a third party packages built top of that and now we have all these tooling and you know as we write more tools we're just building all this software to help us write software and the computers are doing all the hard stuff and like all that's left for us to do is focus on the problem you know the language doesn't even let me kind of over abstract things it just encourages me to just get the work done and so you know when I hit save I just thought you know I love this world that we've created and I never want to leave so I hope you join me thank you you
Info
Channel: dotconferences
Views: 9,436
Rating: 5 out of 5
Keywords: golang
Id: fsTOOPB1TBY
Channel Id: undefined
Length: 20min 41sec (1241 seconds)
Published: Tue Nov 04 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.