text
stringlengths
0
2.35k
**Jaana Dogan:** Yeah, the tooling is also part of the standard tooling. It's not just a test, but it's a really good edition \[unintelligible 00:27:00.05\] is also a part of the tests, because we all have this workflow of not merging things if the tests are not passing... So you would ideally wanna enable the race det...
And it's amazing, but there's one thing I think we should mention - your tests should cover concrete cases, so that the detector can detect them. If you don't represent those by concrete situations, the detector won't be able to detect them... But it's amazing, because it's just so on point, and it's easy, and it's a p...
**Mat Ryer:** Yeah. Now, it's worth saying that the race detector - if it reports that there's a violation, then that is a violation, but it doesn't necessarily catch everything... Isn't that true?
**Jaana Dogan:** \[28:01\] Yeah.
**Mat Ryer:** Okay. But it's still -- to be honest, I've never seen a race condition get through after testing it with...
**Jaana Dogan:** Because you are actually good, in terms of like you care about your tests, so you represent all the cases, probably... I've seen a lot of times people are just not creating those situations where concurrency is a problem. They have all these super micro-tests, so they don't really capture it. And I thi...
**Mat Ryer:** Yeah, that's a really good point. Well, with TDD you tend to get good coverage. Code coverage, by the way, is also another part of the tooling that we just get for free, which is awesome. But yeah, I never try and shoot for 100% code coverage or anything, but naturally, it's quite high with TDD, and I sup...
I like go run, as well. You don't tend to have much magic in Go, but go run is probably the magic tool, because it actually secretly does a build, and then executes... It does a few steps behind the scenes. But it's great if you're just learning to code, or you just wanna write a little script quickly and just execute ...
**Jaana Dogan:** Yeah. I think people use go run for their first Hello, world program. It sometimes becomes complicated... They have this habit of using go run -- I think before GOPATH was a little bit more difficult to rely on; go run was able to work outside of GOPATH, so the behavior of go build and go run was not q...
**Johnny Boursiquot:** You were right, Mat, when you were saying -- from my understanding, it does the same thing as go build, the difference being that once the programs run, it just discards that temporary artifact. At least that's the high-level of what I think it does.
One thing that's worth mentioning also is you can run it with -race as well. That way, if there's any sort of race conditions in the code, when the program fails, if it panics, then you'd actually get some information around where that race condition occurred, as well.
**Mat Ryer:** I didn't know that. That's brilliant.
**Jaana Dogan:** Yeah, I think race is supported in test, build, run... Generally, all across the tools.
**Mat Ryer:** Hm. But it adds overhead, doesn't it? And it slows down your program, and things. It's not something you would just always switch on.
**Jaana Dogan:** Yeah, that's why I think it's useful to make it an optional thing for tests. But apart from that, you don't wanna have the race detector always on.
**Mat Ryer:** Yeah.
**Johnny Boursiquot:** I've had mixed results, depending on the size of the codebase, obviously... But these days I'm working on small codebases. I've been working a lot with microservices, that kind of thing, so these codebases tend to be somewhat small, relatively speaking... So by default, I use the make command. \[...
\[32:18\] I haven't noticed significant slowdown in that, but again, obviously, it might vary, depending on the size of your project and how many things you've got going on.
**Jaana Dogan:** There was a benchmark about this... I think it was kind of like memory usage is like five times larger if you have the race detector on. And I think execution time-wise - again, there were some reports, but it's really depending on the use case, let's just say... It's kind of like adding some overhead,...
**Mat Ryer:** Yeah, cool. Okay. I was thinking as well about go get. Go get is another one of the tools which I think -- obviously, things have changed a lot, especially in the module space... But I've gotta say, when I was first using Go, to just be able to install packages by saying "go get" and then the package name...
**Johnny Boursiquot:** I'll punt the modules to JBD and let her tackle that, but I can tell you when using go get, especially when I'm teaching, being able to say "Look, we're gonna import this package. Before we can actually import this package and use it in our code, we need to go get it." So I'd literally say "Okay,...
Then it dawned on me that if I literally copy that path, go into the browser and paste it in the URL bar and navigate to that repository, immediately they were like "Oh, okay. I see what this is. You are literally pulling this code, that lives at this very path; you're putting it on the command line. You are pulling it...
**Mat Ryer:** Funny, because it's no magic, and the fact that it's so obvious, i.e. "That's the URL. Go look at it. You know what a URL is." I think that's great, and the little story you've just told makes total sense. If I use some npm stuff for a project, I install a few things and I look in that Node modules folder...
**Jaana Dogan:** \[36:35\] I think we need to make an episode on Go mods, but I agree that go get is a really good initial experience. One thing I like about it - if you're go getting a main package, it installs it, it puts it in your GOPATH /bin directory... So it's just a good way to distribute tools, as well. Before...
**Mat Ryer:** Yeah. What I'm gonna do is just keep moving on to different Go tools, because I'm already learning things about these as well... The other one with go build which I love is the fact that we can do cross-compilation. Now, this has been around from (I think) the beginning.
**Jaana Dogan:** Yeah.
**Mat Ryer:** Essentially, for those that don't know, you can choose the target architecture, the target machine to build your Go code for. That's very useful if you're using Docker, because on a Mac you can do the build for Docker, and then you've got the Linux binary that you can then put into the Docker image. Or yo...
**Jaana Dogan:** I think it was magic. When I first saw -- they were typing GOOS (it's pronounced goose) and Windows and go build, and you'd get a Windows binary... It was like "Whoa!" It was fascinating. I usually generate binaries for Linux, so I kept working on my Mac without any worry, or anything. It was so awesom...
**Mat Ryer:** Yeah. Have you used it, Johnny?
**Johnny Boursiquot:** Absolutely. One of my first jobs using Go full-time, my first responsibility was to have a multi-platform build process. I relied on GOOS and GOARCH quite a bit. And for those of you who don't know what GOARCH is - that's the companion to GOOS, for Go architecture. Using GOOS and GOARCH were sort...
There are a ton of them that Go supports out of the box. For ARM processors... The sheer combinations you can have - I've lost track of all the different variations you can push out. It really was a godsend. There's no way I would have been able to get that job done without these things being in there.
**Jaana Dogan:** I think it's also awesome that -- I was doing a lot of development for ARM, for Raspberry Pi, for example... The processor on a typical Raspberry Pi is going to be not comparable to my laptop, so I would just build things on my laptop because it's going to be faster, and then I'd push it to the Raspber...
**Mat Ryer:** \[40:04\] Wow. So how does that actually work? Because obviously, the compiler is doing a few steps, and then it ultimately creates a binary that's made up from the machine code. Is it just that the machine code is generated differently, depending on the architecture?
**Jaana Dogan:** Yeah, you know - they know what to generate for each architecture, so they just basically take the input, they know what to map it, and then they generate the output based on the operating system and the architecture.
**Mat Ryer:** That must have been possible because of the way that they built the tool system. Do you think it was deliberate that they wanted to be able to build it to any target architecture, or do you feel like they just realized they could after, because they'd just built it and designed it in a simple way?
**Johnny Boursiquot:** I don't think you stumble on something like this by accident. If I had to guess, I'd say this was by design... Considering that the creators of the language -- basically, they were building for Google, so I imagine that at some point they needed to be able to run binaries on different platforms, ...
**Jaana Dogan:** I think we simplified the process, but there's this intermediate assembly... The compiler first translates everything to that intermediate assembly, and from that point on they are being compiled to the architecture's specific instructions. So the internals of the compiler is this two-step thing... And...
**Mat Ryer:** And of course, you can have build tags, as well. Does anyone wanna describe build tags?
**Jaana Dogan:** Yeah, build tags are providing conditional compilation, and you can create different rules. For example, you can have constraints to say "Only use this file for Linux builds." Or you can say "I just want only ARM builds to have this file included in the build." There are many different rules provided b...
**Mat Ryer:** Yeah, I've used those successfully when it comes to testing. Sometimes if there are long-running tests, or if there are integration tests that require a different dependency to be running or something, I use a build tag in our test files. That's quite an easy way to choose a subset of things to run. And i...
**Jaana Dogan:** Yeah, I think it's on the top of the file, there's a particular place... But that's it. And it's really readable. I think my only complaint about these rules, about the build constraints, is that it's just really hard sometimes to just have multiple rules represented. It becomes really hard to parse. I...
**Break:** \[44:18\]
**Mat Ryer:** Okay, I want to also mention a couple of tools from the community, as well. Because remember, we are using Go tools all the time, but we can write tools as well, and some people have contributed. I think goimports was a Brad Fitzpatrick project; that was his own idea, that he just did on his own... It ess...
Some of the tooling as well doesn't have to be Go tooling running on our machine. Matt Holt has a great JSON-to-GO service. If you google "JSON-to-GO", you basically paste in a JSON blob, and then it generates the Go structures for that JSON blob. Extremely useful, especially if you're gonna consume an API and you need...
Are there any other community tools that we like?
**Johnny Boursiquot:** I personally like the Go Report Card website, which -- well, I guess it's less of a local tool, but something that can basically evaluate how close to the idioms of the Go community your code is being kept at. I think it might even incorporate some of the tools we've mentioned before - the linter...
I find that useful, especially when I'm evaluating a repository, a third-party package, to determine whether I'm gonna use it or not. If it has a score, I will look at that. If it's anything other than A, then I'm gonna take a closer look; I'm gonna be a little bit more hesitant with bringing it in, because I'm like "O...
\[48:03\] Sometimes I may just see what's happening and maybe replicate it locally, without having to bring in the package, if I don't like the score, so to speak. So it's sort of another data point, so to speak, to help you evaluate the quality of the repository. But yeah, it's one of the things I like to see, as well...
**Mat Ryer:** The same for GoDoc. GoDoc is a tool you can run locally, but we have also the godoc.org hosted service, which lets us view documentation for any open source project. I think that's also nice. It's a nice way to provide that capability, because it makes sense; yo want to share just a link.
The nice thing for GoDoc - it's just godoc.org/pkg/importpath. So again, you're still referring to that import path, and we see it.