text stringlengths 0 2.35k |
|---|
**Carl Johnson:** Yeah. So I said before that the old knob that we had for controlling garbage collection was based on the percentage of new memory, versus old memory. And so Twitch had this really funny idea where they said, "What if we just allocate a bunch of memory that we don't need, and let's keep it around?" And... |
**Johnny Boursiquot:** \[laughs\] Ballast. |
**Carl Johnson:** It's like, we're going to allocate a gigabyte that we don't need, just for good luck. But basically, what that did was it sort of tricked the garbage collector into thinking that, "Oh, well, you've allocated 300 megabytes of new memory, but you still have that giant two gigabytes slab that you're not ... |
So it was just a kind of funny way of tricking the garbage collector into triggering at different times. But I think with the soft memory limit now, that should hopefully be obsolete, because it was definitely-- it's one of those hacks where it's like, it's genius and it's idiocy at the same time. You're like, "I can't... |
**Johnny Boursiquot:** \[laughs\] Yeah, simultaneously. |
**Carl Johnson:** It's like, you're so proud of them for figuring it out, but also you're like, "You're just allocating memory for no reason? It doesn't do anything? It's just there for good luck?" |
**Mat Ryer:** Okay, Carl, this one I don't quite understand, and I haven't run into this, and I think I've probably got code out there that has this same bug in it, but there's a new abs() method on a time duration. And this is different to you just doing it yourself, isn't it? |
**Carl Johnson:** Yeah. So this is a bug that bit me in production. And so then after I had been bitten, I was sort of thinking like, "Oh, this is so annoying. How did this happen? How can I prevent it from happening again?" And then I realized I could open an issue on the Go Issue Tracker and see if I could fix this i... |
\[34:05\] So essentially, the problem is that a time.duration underneath the hood is just an Int64, right? It's just a regular number, and it records the number of nanoseconds since some epic-- I guess it's not even from an epic, it's a duration. So it's just an absolute number of nanoseconds, right? Well, I guess the ... |
And then it turns out that the way that integers are stored in computers, there's always one more negative number than there is positive numbers. It's just like a weird computer fact that you learn in college, where they're like, "Oh, yeah, the way we store numbers - we always make sure that there's one more negative n... |
So I took the two times and I subtracted the one time from the other. Once I subtracted the two times, if the duration I got back was negative, I converted it to positive, right? And then if it's less than a minute, then it was within the time. And if it was more than a minute, it was outside of the time. |
Well, the problem was, like I said, durations are just stored as integers, and there's one extra negative second that can't be represented as a positive second. So if you just do the naive thing of multiplying a duration by minus one, if it's negative, it's not going to work. It'll stay negative. And so I was like, "Wh... |
And so time.duration.abs, or .abs - it's a new method, it's on duration. All it does is if you have a time and it's positive, it doesn't do anything. If it's negative, it converts it to the positive time, unless it's that one extra second, that one extra nanosecond that can't be converted to positive, and then it conve... |
**Mat Ryer:** Yeah, that's really interesting. So just to summarize that - because it's just an Int64 under the hoods, under the covers, there were more negative numbers, and so you can't just rely on doing the absolute that you would expect. And so this method does it properly. I like that. |
I think any time there's weirdness at the edges, it's very difficult to find them, because probably in all your test code you're putting in numbers that really make sense, and you test it all - well, you think you're testing it all kind of perfectly - and so you can miss those edges. And I think fuzzing probably may he... |
**Carl Johnson:** Yeah. This was before Go 1.18, so the fuzzer didn't exist. Or I guess here were ones that were not in the Go tool that I could have been using. But yeah, it was a very annoying bug, because if you had the same two values and you just flipped them, and instead of subtracting A from B, you subtracted B ... |
**Mat Ryer:** Johnny, tell me... You wanted to talk about generics. |
**Johnny Boursiquot:** \[37:47\] Yeah. It's kind of hard not to, given that it's the new and shiny toy that we all have on our hands. Really, this is just a single use of generics in the 1.19 release planned, just a single standard library package. I think the significance of that, or how little generics is being used ... |
So generics is a big change to a language, and the Go 1 compatibility promise is still being what it is today, and to this day, even after such massive changes to the language; it's really one of the things that I like most about Go, right? You don't have to really change the way you write Go for that. There has been o... |
**Mat Ryer:** Yeah. But what about like-- I thought when generics would land, we'd get some common, obvious things solved for us, like a slices package that does slice operations, but in a strongly typed way, things like this. But we don't see them yet, do we? |
**Johnny Boursiquot:** Not yet. I think, as Carl mentioned earlier, the experimental package, \[unintelligible 00:40:07.23\] has some things in there related to generics, the constraints package, for example, which definitely has featured in tutorials and talks and whatnot. \[unintelligible 00:40:18.07\] generics is on... |
These are things that I think are going to continue to surface. I think you're going to get a swelling of these common patterns, common set of things that both the community and the core team are going to discover and bubble up. They're going to find their way through the whole experimental process, right? Basically, m... |
It's all experimental at this point, so again, basically, taking a very deliberate approach. And people are going to write their own -- until the standard library gets some of these things, until the language itself gets some of these things, people are going to write their own implementations for the use cases you've ... |
\[41:41\] Data structures are going to basically see a huge benefit from the use of generics. Like, how many ways do you want to implement -- I mean, you want to be able to implement a binary tree that can work with different things. You want to be able to work with a linked list, or some set or some--these sort of com... |
So as we've seen in the past, we can expect the community to come up with-- there will be some popular packages that use generics, that provide some of these basic data structures and things like that. And over time, you may see the core team take a page from these things and implement in the standard library proper ve... |
**Mat Ryer:** Yeah, sounds good. Sounds great. Okay. There's a new era coming too, Carl, isn't there? The HTTP max bytes era. What is that? |
**Carl Johnson:** Yeah, this is a thing. So in the HTTP package there is the max bytes reader. And what this lets you do is it's a little bit of-- it's not quite a middleware. There is a middleware. There's a max bytes middleware as well that uses max bytes reader. But max byte reader, basically what it lets you do is ... |
So there had been an issue open for years to fix this. And finally, there was sort of consensus that like, "Oh yeah, let's go ahead and do it. This is a good idea. Nobody thinks this is a bad idea." And so again, it was one of those things where I was just looking at the Go issues page, I saw an issue, it seemed like i... |
**Mat Ryer:** Yeah. |
**Carl Johnson:** I think actually with this one -- I had it done before Go 1.18 came out, but I was saying before that there's that Go release cycle and there's a freeze period. So I finished this one day after the freeze had started. And so I sent it in and they said, "Sorry, mate. The freeze has started. We'll see y... |
**Mat Ryer:** Oh, wow. So they really mean it. |
**Carl Johnson:** Yeah, they don't get around with the freeze. |
**Break:** \[45:02\] |
**Mat Ryer:** Yeah. So you mentioned that hack of checking the actual string, and I've run into this myself before, and actually run into a bug where the string I was checking from the error - it worked on my machine, but then, for some reason, it ran on a place where the language was different, and the error message i... |
**Carl Johnson:** It's a type that you can check with \[48:17\] But yeah, one of the things when I was implementing this is - so there's a new error type, and I have to give it error string method. And so what string should this error return? Well, if it was like a normal error, it should go ahead and return something ... |
**Mat Ryer:** That could be a vet check that we have, that looks for that string and see if you're doing that check, and say, "Oh, did you know? Thanks to Carl - he's fixed this - you can do it in this better way." |
**Carl Johnson:** Yeah. I mean, I feel like I was just like the last person in a chain of-- like, if you go on GitHub and you look at the issue for this, you can see so many people there with the exact same idea, saying "Hey, this should really be a type. It's kind of a pain that I have to like check for the string. It... |
**Mat Ryer:** \[50:14\] Nice. |
**Johnny Boursiquot:** Now you've made his book out of date. |
**Carl Johnson:** Oh, yeah, that's true. He has to update a new edition, make it more work for him. |
**Mat Ryer:** That's not part of the backwards compatibility promise, to be fair, is it? \[laughter\] |
**Carl Johnson:** Well, the old code will still work. It'll still work, what's in the book. It's just now there's an easier way to do it. |
**Mat Ryer:** Yeah. Can you do a pull request to his book? Actually, how hard was it to-- like, was there any discussion around the design of that? Was this something where you had to kind of advocate for one way to do it? Were there competing ideas? Or was it just sort of like the community had come to the conclusion ... |
**Carl Johnson:** There was a little bit of discussion. I mean, it's such a simple thing that I feel silly for talking about it on a podcast... But it's true that there was a discussion. So one of the issues is in Go there's two different ways that you can make a new type. You could just say "type max bytes error int 6... |
So then there's two ways of doing that. You can say `type maxBytes error int64` or you could say `type maxBytes error struct int64` And if you do it in the struct version, then that lets you add more fields later. |
**Mat Ryer:** Right. |
**Carl Johnson:** But if you do it in just the plain version, then you're really committing and you're saying, "I guarantee that I'm--", at least going back to that Go 1 compatibility promise, "I don't think I'm ever going to have to add a second field." And so I don't think they're ever going to add a second field. I ... |
**Mat Ryer:** Yeah. I think that's such a good lesson, I think. And that's something that I advocate for that a lot, of like, give yourself more options in the future. Yes, it would be very satisfying if that type was just a number, just an Int64, but give yourself more options in the future. |
Another example is in data, if there's a bullying field that's representing some kind of status, like active or not active, I'll probably go for a string that says active or inactive or something, because what if I have other statuses in the future? I don't then have to go and change those types. So I can't like that w... |
**Carl Johnson:** Yeah, it's just a little bit of future-proofing. Yeah, it's interesting to see when people come together and they're debating these different APIs... Things just improve. It's definitely improved me as a programmer to sort of be in the issues, and like, you know, I'll have my first suggestion, and som... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.