One and two and three and four and proposals!
This show is supported by our beautiful Patreon member. Wanna become beautiful yourself? Nah, you're already beautiful. If you wanna join Patreon, wait around till the ad break to hear more about that. This is a cup of go coming to you from a literal coffee shop for December 6, 2024.
Shay Nehmad:Keep up to date with the important happenings in the Go community in about 15 minutes per week. I'm Shay Nehmad. And I'm Jonathan Hall. Which coffee shop are you hailing from?
Jonathan Hall:Yeah. I'm in, Norm's. I think it's just called Norms. Were they Norms? It's called Norms.
Jonathan Hall:Yeah. Somebody had to confirm with me in, downtown Newton, Kansas.
Shay Nehmad:How's the coffee? You can only say it's really good because they hear you.
Jonathan Hall:It it is good.
Shay Nehmad:John is, like, holding the classic white, stereo foam with, his cardboard thingy, cup. Looks beautiful. So I hope it's full of go. We took the week off last week. A ton of news this week.
Shay Nehmad:So let's get started. Let's start with releases, then we have a ton of proposals to jump through. We'll talk about, like, vetting a little bit and multithreading a little bit. It should be fun. And finally, I wanna mention a a pretty fun blog post I've, we've found because someone sent it to us on the Slack channel.
Shay Nehmad:So let's get started. It's the version I've been waiting for.
Jonathan Hall:Yes. Finally, 1, 2, 3, 4 is here. There are only 40, 41 more minor releases to go until we have 1, 2, 3, 4, 5. So there's no, really interesting things in 1, 2, 3, 4. No security vulnerabilities that are fixed or anything like that.
Jonathan Hall:It's kinda just a run of the mill release, but you should upgrade. I did this morning.
Shay Nehmad:Yeah. If it like, mostly bug fixes. Right? Yep. Run of the mill upgrade, just remember to do that.
Shay Nehmad:That's I have an update on a past news item. It's not very important. Do you know what go test minus minus count does?
Jonathan Hall:Not really. I know that it is useful when you want to disable the test cache.
Shay Nehmad:So what it actually does, it if you add, like, 3, it will run the test 3 times. So if you wanna run the tests Okay. Multiple times because maybe you wanna make sure that they are isolated and you can run them a few times, that's pretty good. Another flag that helps with that is shuffle. Right?
Shay Nehmad:You change the order every time, in that way you can find bugs, yeah, that are caused by tests not being isolated. Just like as a side note, there are things you can do other than running shuffle and count to detect tests that are not isolated. I've been working a lot about it, recently. One thing is before and after each test, take a snapshot of all environment variables. We I've been working on it, with someone from my team.
Shay Nehmad:Look at accesses to databases, blah blah blah. A lot of things you can do to make sure the tests are isolated and not flaky, which we all like. Anyway, what do you think should happen when you run minus, minus count 3 and shuffle?
Jonathan Hall:What I think should happen is I it's a good question. I don't know.
Shay Nehmad:It's a bit tricky. Right? So the way it worked so far, you shuffled it and then you duplicated it, which actually meant you didn't get the effect I think most people wanted, which is to double them first and then shuffle. So the order is quote unquote more random. Right?
Jonathan Hall:Mhmm.
Shay Nehmad:That has been discussed at infinitum in the thread, what do we actually want and whether the current implementation is a bug or a feature. They decided it's a bug, let's improve it. Let's do, like, the duplication first and then just shuffling so it's more shuffled. We updated on it and there's a change list. They implemented it and I did some code review on it, which was really nice because I I think I found some useful things.
Shay Nehmad:That was, like, a few a while ago. And like every good change list, it had some extra things in it. For example, updating the version of math, which is interesting because there's a new there's math v 2. Right?
Jonathan Hall:Math brand v 2?
Shay Nehmad:Specifically. Yeah. So they upgraded the version of that as well, and, yeah. It's it's still being worked on, but looks like all the reviewers gave the thumbs up, and it's gonna get implemented, I hope, really really soon.
Jonathan Hall:Yeah. That's really cool. How often do you actually run with count other than 1?
Shay Nehmad:On every CI, of course. Because I want to catch these cases. Okay. Just not necessarily on every CI run, maybe, like we do it on a nightly basis just because it costs a lot of CI time and it's rather expensive. So we do it on a nightly basis instead.
Shay Nehmad:And, yeah, it detects a lot of flakiness. It's a good method to to do. You don't need a lot of count. You can do count 2 and that probably takes care of all the tests that change something that will make the like, I can't think of a lot of cases where if you run a test twice, it will pass, but thrice it will not. You know what I mean?
Shay Nehmad:Like, the big jump is from 1 to 2. So, yeah, it's, there's a change list and I did some code review. It's really nice. You should try to do that as well sometimes, especially if the change is about something you care about like this one.
Jonathan Hall:Yeah. Cool.
Shay Nehmad:So we can talk about the new proposals or we can talk about 124. We've decided to not talk about 124, the draft that's being drafted right now. Right?
Jonathan Hall:Yeah. We'll have plenty of time to talk about that before February.
Shay Nehmad:It's months out. We think it's not relevant enough yet, So we will talk about it. We know that the draft is out there, but we wanna talk about proposals, first. Alright.
Jonathan Hall:So the first one, I wanna talk about is a new proposal. This has not been accepted. It was just recently added to the minutes. Although, the original proposal dates back to 2016. So it's been around for a while.
Jonathan Hall:The proposal is to add a new vet check to look for abuse of sync wait group. If you're very used to sync wait group, you probably can imagine what we're talking about here. A common pattern you'll see in the wild is to call a goroutine. First thing you do in the goroutine is you call waitgroup.addone. And then you call defer waitgroup.done.
Jonathan Hall:This is wrong. And the reason is because your go routine may be delayed in executing. The wait group may terminate before that wg.add is even called. So you need to call the wait group add before you start the new go routine. The proposal is to add a vet check that will warn if you don't do that.
Jonathan Hall:I think that's a great idea because this is such a simple thing to do. It's a little brain fart issue that can it can bite anybody, and, it's so easy to detect and warn us against it. So I think it's a great proposal.
Shay Nehmad:How, ubiquitous is this, like, quote unquote abuse? Because if it never happens, maybe we shouldn't work on it.
Jonathan Hall:Yeah. I don't know how often it happens. I know I have done it before. I don't think I've done it often, but I've definitely done it before. And Joe Tsai, who brought up the issue, says that he's seen it very commonly.
Jonathan Hall:I don't know what that means. I don't know what kind of research he did to he doesn't provide numbers that I see about how often it's done. Yeah. I don't know I don't know the answer. I know I've done it before and have and caught it because of a bug, not because of a linter.
Jonathan Hall:So I think a linter would be great.
Shay Nehmad:At the topic of, linters, there's another new proposal here. It's been accepted. It's not very new. Like, it's been open since, 2022, but it's been accepted yesterday, and the final comment period went by without a hitch. But it's it's new on my radar just because a few weeks ago it it popped up again.
Shay Nehmad:In Go, we have struct tags. Right? So you can define a struct with fields a, b, c of, like, string, int, int, and then do JSON tags next to them. Write back tick JSON something, that sort of changed the JSON behavior of that struct which is super useful. One of these JSON tags is omit empty.
Shay Nehmad:It's if the value is empty, omit it from the JSON. That's really useful for example, if you're marshalling an unmarshalling JSON and you want to remove fields that are empty when you're writing them out because you don't want to have all the fields in their empty values. Especially useful since Go's 0 values are pretty unique. Like,
Jonathan Hall:not a
Shay Nehmad:lot of languages represent Bool that isn't there is false or a number that isn't there is 0. Most languages have the concept of nil ability or something like that. So that sort of provides a good way to interrupt with a lot of the real world. However, if you look at the documentation for JSON, marshalling in Go, whatever, omitempty is not as simple as it is. Like if you're just working with simple values, you're just working with ints, bools, whatever, maps, it's pretty it's pretty obvious.
Shay Nehmad:If the number is 0, you're gonna emit it. However, time dot time as a field, omit empty does nothing because there's no sensible, interpretation of omit empty on a struct field. This is discussed within the proposal. It starts with time dot time and then gets expanded to all structs basically. You actually have to work with pointer to time dot time because pointer is a basic thing and you can you can it can be nil.
Shay Nehmad:Right? You can have a nil pointer and then if you get a nil pointer, it's it can be omitted because it can be empty. The proposals for vet to detect this, like, weird situation and just suggest, hey, you probably wanna use a pointer to time and not just time. This gets discussed a lot whether we should have something called omit 0 and omit empty, etcetera, etcetera. There's a lot of research here about places where this actually happens in the Go code and how would that be, affected.
Shay Nehmad:There's a crazy number here that 33% of omit empties are are meaningless, which for me was very very funny. And someone also here, I ran face first into this very bug, Daniel Marti, which we had on the show. I ran face first into this bug. I can really feel, like, his pain. Anyway, this is, accepted, which is very very I I think would be a great improvement to vet.
Shay Nehmad:I'm wondering if this is a problem with omit empty to begin with. Like, how is this even possible. Right?
Jonathan Hall:I I think it's hard for me to say exactly. I haven't been following the the new JSON encoding proposals really closely, But I know that this keeps coming up, the whole issue about emit empty and emit 0. It's it's just I mean, kind of like you said before, it's it's an ambiguity that different languages handle different ways. And JSON is a it's not a Go concept. So it it's where we it's sort of the border between Go and the rest of the world.
Jonathan Hall:So those ambiguities really start to shine in confusing ways when we're trying to interop with the rest of the world. So, yeah, I don't know. I don't think there's a clean solution. If there was, we probably would have found it by now. There's just a lot of ambiguity, and we have to come up with the solutions that the best in most of the cases.
Shay Nehmad:I think the the problem is is Go is pretty strictly defined. Like, you don't get the quote unquote, freedom of just like, yeah, I'm trying to, to JSON load s whatever Python object I loaded, it just works. Usually, you have to be a bit more explicit than that, and the reason all these things are kinda spiky and can cause bugs is because that doesn't really gel well with Go, which is funny to say because obviously Go is super good for web work and whatever. But I don't know. This is, obviously, I think a good, it's a great improvement because 33% of people are not gonna get this this bug anymore, but I think people who are gonna get this linter warning are gonna be like, wait, what?
Shay Nehmad:This didn't work? But, you know, if they didn't notice it, maybe it's not that important. Right? Maybe the the field has always been passed.
Jonathan Hall:Yeah. I I I can see Stack Overflow exploding with repeat questions of this. What does this error mean? Why am I getting this?
Shay Nehmad:Yeah. Actually, in the original, post by, Josh Bleakius Snyder, he's like, this is a common source for package JSON confusion, and it's already spawned a handful of proposals. Things like adding an omit 0 option and no nil struct tag to marshallnil slices and not null, and supporting 0 values of struct with omit update like this has been raised before. It's been accepted now. It's I think it's actually been mentioned in change lists as well or someone already did like an implementation.
Shay Nehmad:So it might, join us pretty soon, which is pretty cool. Last proposal on the docket.
Jonathan Hall:Yeah. Let's change gears here a little bit and talk about something completely unrelated to vetting and JSON. We have a new proposal, and this one might sort of make your head explode a little bit since we're talking about Go, which is famous for its go routines and all that stuff. But the proposal is to add a new package called runtime slash main thread that has a single method in it or single function in it called do. Mhmm.
Jonathan Hall:And all do does is execute the callback function you pass to it. But it guarantees that it's executed in the main go routine or the main thread, I should say. Why would you ever want that? I can hear people thinking.
Shay Nehmad:Like most Go programs don't run on like specific threads. Right? That doesn't matter. I just have my Go routines. They're green threads, whatever.
Jonathan Hall:Yeah. Exactly. But for, in particular, for certain c Go programs or c libraries, some c libraries, are required to run-in the main thread. So this would be a way to allow you to do that. The proposal goes on to talk about how there are better ways to accomplish this.
Shay Nehmad:If I'm running in a goroutine, isn't that a green thread? Doesn't it count as the main thread? Or does it actually spawn like a different thread and then my c code won't work?
Jonathan Hall:Yeah. I think it definitely can do that, in in certain circumstances. Yes. It can spawn a new a new thread and then your c code won't work.
Shay Nehmad:That's interesting. I wonder what's like the c, code that caused this thing to get implemented. Right?
Jonathan Hall:Yeah. Anyway, it's a feature I might be using just because I don't do or I don't intend to be doing c go code, but maybe I will at some point. But I can see how it very much be, valuable if you are doing that and and need that that sort of control.
Shay Nehmad:Yeah. Specifically, things like find already did that, like in their event loop in their main thread. They I think they call, like, runtime dot lock OS thread when they in it or things like that. Find the GUI library, which we talked about a lot, seems to do that already.
Jonathan Hall:Mhmm.
Shay Nehmad:But I I really like the the addition here of someone suggesting, you know, you wanna since it can panic, do. If if Go isn't in control of the main thread, it might panic. So maybe you wanna check if you can do it before you do it. So there's a suggestion to add to the API, can do, which sounds very, like, preppy. Right?
Shay Nehmad:Can do Yes. Can do attitude. But it would be a shame when it's, when it returns false. This is the, you know, the sorts of proposals where, I like that we can interrupt with other things, in the real world. One time JSON, one time c.
Shay Nehmad:But just why can't everything be pure Go, and then we won't have to like, the entire operating system from top to bottom. Just one big Go, binary. Why wouldn't that work, John?
Jonathan Hall:I can't think of any reason why that wouldn't work. But that I'm going to talk about.
Shay Nehmad:New proposal. Implement Windows in Go.
Jonathan Hall:Cool. That would solve a lot of the Windows incompatibility problems, wouldn't it?
Shay Nehmad:It would solve a lot of problems, I think. Cool. So these are the 3 proposals we wanted to mention. Let's quickly do a lightning round. Lightning round.
Jonathan Hall:So the first one I wanna talk about is a little library called QRand. If you don't think, math rand v 2 is good enough or crypto rand is good enough, you might try QRand. What does it do? It gives you quantum random numbers. It does this by talking to the ANU quantum numbers, API.
Jonathan Hall:You didn't need an API key, although it's free for certain low volumes of usage. This library comes from, John Aranda who we've had on the show before. I haven't used it, but it's just cool. Quantum is cool. So, you know, if you want some quantum random numbers, now you can do it.
Shay Nehmad:Yeah. There's a nice quote in the read me. Random numbers should not be generated with a method chosen at random. Like, only use this if you think you need this. Right?
Shay Nehmad:Well, my thing for the, blog post is not really my thing. It's, Mihai's thing because he posted it on the channel. Thanks, Mihai. It's a really good, blog post called I Stan Clearing Maps, No Cap by Phil Pearl. It's just a story of someone, debugging an issue with map and capacities at work, a very real blog post about a real thing, and it references a rejected proposal, which is my favorite kind of proposal, the only one I like to submit, ones that get rejected.
Shay Nehmad:And it just shows, like, a benchmark of, hey, why this, took so much time, something that I ran into at work, and also a very, boring, solution at the end that's very problematic, which I really liked. So go read it. I'm not gonna spoil the ending. And that does it for the lighting round.
Jonathan Hall:Dun dun dun. Cliffhanger.
Shay Nehmad:Mhmm. Cool. Let's move to the ad break.
Jonathan Hall:Alright. Well, thanks for listening to our episode today, this week. If you enjoyed this episode, be sure to rate it or review it on wherever you listen to your podcasts and share it with a friend or a colleague or a fellow student or your pets or whoever would like, word-of-mouth, because that's how our shows, is spread. We don't pay for any advertising. So, yeah, the best way you can help support us is to just share the show with your friends.
Jonathan Hall:You can also support us on Patreon if you want to. This is a hobby, and it's not free. Wanna help with the hosting and editing fees? Cupago.dev, you can head over there and click on the Patreon link and become a supporting member. Do we have new ones this week, Shai?
Shay Nehmad:No. But, actually, we have a churning member, a person who left, and we totally respect that as well. We appreciate your patronage while you were here. Yes. That's solely fair as well.
Shay Nehmad:A few programming notes. We are at the month of December, which is cold and also full of holidays and many, many things to do. Next week, we should be fine. 19th December, I'm on vacation, and we are looking for a replacement co host. If you wanna step into my smelly shoes and, co host the show with Jonathan and 19th December is free, talk to us.
Shay Nehmad:Send us a message on our, Slack, hashtag a cup ago. You can find us on the channel. You can DM us as well. But, yeah, we need someone to fill in for me because, I can't do the 19th. And 26th is like Christmas, so we're gonna take that week off.
Shay Nehmad:Also, very very excitingly, this is gonna be our 91st episode. Meaning, we are creeping up on a century of a cup ago, which is totally not my expectation when we started the show, and it's pretty amazing. No. John and I talked about how we're gonna, like, celebrate or do something, and we think about doing a a live episode just with y'all, like, having everybody on the call and just sort of a online meetup, live episode kind of thing. If that sounds interesting, let us know.
Shay Nehmad:If that sounds horrible, let us know as well, on the channel. We might I will send out a survey so you can upvote and downvote when this episode comes out. And, yeah, if we have a lot of, engagement
Jonathan Hall:That that episode will probably land around little or late February depending on how many weeks we skip between now and then.
Shay Nehmad:Yeah. Maybe we'll do, like we wanna keep it in February. Maybe we'll do, 5 episodes a week. We'll just do a couple Goathon. That sounds pretty horrible because we'll run out of the stuff to talk about pretty fast.
Shay Nehmad:But, yeah, we are thinking about doing a live episode to celebrate the fact that we've done a 100 of these things, or we will do a 100 of these things, which is pretty exciting.
Jonathan Hall:Yeah.
Shay Nehmad:So if that sounds interesting to you, let us know on the Slack channel and, we'll make it happen. And that does it for this episode this week. Bye, program exited.