text
stringlengths
0
2.35k
**Mat Ryer:** Well, I mean like sometimes in a project you have multiple packages. Sometimes people will -- each one of those will be a module, instead of just a package inside this bigger module. Things like that.
**Michael Matloob:** Yeah, I feel like one thing that we learned after some experimentation with modules, after some time using vgo and then modules in the Go command, we learned that multi-module repositories should be rare. They have a lot of surprises when you're working with them. So now our general recommendation ...
**Mat Ryer:** Yeah. I think for packages and things if you're releasing a library that people are gonna use, I think that's kind of great advice. Definitely a time I've seen where multiple modules exist is if you have a monorepo... The way that you would do it at the moment - I use Visual Studio code - you basically op...
**Michael Matloob:** \[40:18\] Yeah. I mean, one of the driving forces behind us starting to work on modules was the user experience in not just Visual Studio Code, but any editors that user Gopls, which kind of powers the Visual Studio Code Go experience. The team was thinking of different ways of representing multipl...
So we decided the best thing to do is to make this a first-class feature of the Go command, so not only could Gopls use it, but users who introduce modules can then open up command line and the Go command understands that they're working in the same workspace, in the same set of modules.
**Mat Ryer:** So how does it actually work in practice then? Do you have to set up a workspace? Is this a new concept of a thing you create?
**Michael Matloob:** Yes, so we have go.mod files, and now we have go.work files. So you create a go.work file, the syntax is very similar to go.mod; we wanted it to be easy for people to pick up... And the go.work has one new directive as the use directive. So you tell it which directories you want it to use, and all ...
**Mat Ryer:** And it's gonna be aware of those other modules, and you're not gonna be fighting the tools anymore.
**Michael Matloob:** Yup.
**Mat Ryer:** And can you do replaces as well in there?
**Michael Matloob:** You can... We don't think people should need to add replaces, except in very specific circumstances. We actually added replace because if you have multiple modules in your workspaces, they might have conflicting replaces... So replacing the go.work file can override the replaces that are fighting. ...
**Mat Ryer:** Yeah. So I feel like lots of tools probably got touched by adding this kind of support. Was it a difficult one to get in?
**Michael Matloob:** Most of the work was in the Go command itself. There's definitely an amount of complexity in the Go command, because their module-loading code - it does more than you'd think. But once we got it to work in the Go command, one of the nice things -- most of our tools call into the Go command. So as l...
We've had to make on the VS Code Go and Gopls teams -- they've made changes to understand go.work files and pass them into the Go command, but... You know, once you pass that in, all the hard work is done by the Go command itself.
**Mat Ryer:** This is a really nice thing to have. In the way that I work, this is gonna change a lot. There was an experiment for a while where you could try this out with an environment variable, wasn't there?
**Michael Matloob:** Yeah. I filed a proposal for this, and I made it available, and we had a link for people to easily download a development version that included these changes using the gotip command, and so people could try it in and give feedback. We got some feedback on it, which was super-helpful. And we got a l...
**Mat Ryer:** \[44:27\] Absolutely. Well, honestly, I think these kinds of things make such a difference, so we're so pleased. And honestly, I feel like there's a lot more to talk about with workspaces and modules. Maybe, Michael, you could come back one day and we'll do like a modules and workspaces special.
**Michael Matloob:** Oh, sure. I'd love to.
**Mat Ryer:** Okay, cool. Well, we will hold you to that. I do consider this to be legally binding.
**Michael Matloob:** Like the pinky promises?
**Mat Ryer:** Pinky promises are, of all the types of promise, I think, they're up there with the most important. You've got local laws, you've got national laws, and then all the way at the top, after the Supreme Court, you've got the little pinky promise there.
**Michael Matloob:** Pinky promise at the top. Got it.
**Mat Ryer:** Yeah, I think that's the legal structure of the pinky promise. Well, here's another pinky promise - I promise you're about to hear some unpopular opinions.
**Jingle:** \[45:25\] to \[45:42\]
**Mat Ryer:** Okay, who's gonna go first with -- I don't know why I'm speaking in this spooky voice. Who wants to say the first unpopular opinion?
**Daniel Martí:** Maybe I can start with mine... Mine is that I think code generation should be avoided whenever possible.
**Mat Ryer:** \[laughs\]
**Daniel Martí:** I think the main reason for that is because it adds developer friction, it often increases build size and build time, and oftentimes people overestimate how slow reflection is. If you use reflection well, the cost is actually very reasonable. And it's not like you're building your whole program around...
**Mat Ryer:** What do you think of that, Michael?
**Michael Matloob:** I guess I don't have a very strong opinion about this either way...
**Mat Ryer:** I do.
**Michael Matloob:** Yes? Let's hear your opinion. Is it the popular or unpopular variety?
**Mat Ryer:** The thing is, I love code gen, because it's like you're doing loads and loads of typing. You just do a bit of typing, and you run a command, and it's just like you've done loads of typing. So that's the thing... Reflection is hard, so it's quite satisfying when you get it right, but editing a template and...
**Michael Matloob:** I will say this - I find that working with code generation when using the Go command is not very fun. I don't like using go generate, I don't think it has a good user experience... It happens separate from the build, so it's really easy to have stale files.
You know, I feel like this ship has sailed, but if you're gonna do a lot of code generation, Basil is very nice for that, but it's not very heavily used in the Go community. Inside of Google we use mostly generated prodos... And it's seamless, because the build just generates some automatically and you don't need to th...
**Mat Ryer:** \[48:13\] I think generics -- ugh, I've said it. Yeah, I'll get booted out of here... But I think this rule obviously is very weakly enforced. So much for pinky promises, right? After I was bigging them up and giving them all that legal weight, look at it now. It's been reduced to a silly, childish thing....
Well, what I was saying is, I think generics are gonna get rid of a lot of cases for code generation... But reflection is pretty difficult to write, because there's no kind of feedback -- like, you need unit tests really for your feedback to... I mean, you don't really need that; let me rephrase that. I think reflectio...
I'd be interested to test this one on Twitter @GoTimeFM. We will tweet out a poll and find out if this really is unpopular. It's a candidate for one though, it's a good one. Can you beat him, Michael, is the question?
**Michael Matloob:** My unpopular opinion is we should bring back the try proposal.
**Mat Ryer:** Oh, really?
**Michael Matloob:** And this is where I'm going to not mention other features by name, but I'll say - of all the features that people have proposed as language changes to the Go language, I feel like none have been as potentially impactful as the try proposal was... And I was sad to see it pulled back. Because I think...
Certainly, the proposal as it was needed more work before it should go in, but I really do think we should bring back the try proposal, and keep working on it and make it better. I don't know when we'll have the bandwidth for another big language change like that, but...
**Daniel Martí:** I have to agree with Michael. I think the reason the try proposal got so much bad feedback is because Go is so opinionated, a lot of its users have gone into this mentality of Go doesn't need features, so sometimes the users can have this knee-jerk reaction of somebody proposes a change to the languag...
**Mat Ryer:** So just refresh our memories. What did try do?
**Michael Matloob:** Yeah, so basically it gave you a mechanism to try with a function that returned an error as its final argument. And then it would allow you to handle that error elsewhere. So you could add -- I think in one of the variations of the proposal there was like a handle for handling a number of tries in ...
\[52:10\] So addressing that awkwardness and nudging people towards doing the right thing, especially if try and handle came with helpers... And now we do have functions like `ers`, `is`, and `as` that help people with wrapping errors. Those together would provide a better model for handling errors and for people to th...
**Mat Ryer:** Well, fascinating stuff there... Yeah, I'll tell you what - it's interesting, because I think... See, when I handle errors - and I don't know if I do this different to other people. I may be unusual in this... But when I return the error, I add quite a bit of context there. So each one is different; I'll ...
But yeah, the other thing is -- I mean, this doesn't hurt that, but I do like that error handling is at least explicit. The try proposal didn't really interfere with that, but I like the fact that in Go we are kind of handling errors, even if you are just returning it. It's like, as long as you're not forgetting about ...
I literally was writing something today, and I literally had to write if err!= nil, and then I had to stop and think "Oh, what do I do if this errors like that?" That actually is not a trivial problem in this particular case. I wasn't able to just return an error. I had to handle that... So I quite like that it's in th...
**Michael Matloob:** Yeah. I'm interested in seeing how unpopular that is. Do you think that could go for the most unpopular opinion expressed in one of these segments?