Skip to content
PodSubs
ShowsPeopleGuestsJobsNewsEvents
More
BlogPodCred
Menu
ShowsPeopleGuestsJobsNewsEventsBlogPodCredNetworksSign in
Join nowSign in
  • Shows
  • People
  • Jobs
  • News
  • More
    • Guests
    • Events
    • Blog
    • PodCred
    • Networks
    Join nowSign in

ADSP: Algorithms + Data Structures = Programs

ADSP: Algorithms + Data Structures = Programs artwork

Episode 179: CheckGrade, ACCU & CppNorth

Apr 26, 202423 minAudio
ShareXLinkedInFacebookWhatsAppEmail

In this episode, Conor and Bryce chat about the CheckGrade problem, ACCU, CppNorth and have a guest appearance from Bryce’s mom! Link to Episode 179 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Twitter ADSP: The Podcast Conor Hoekstra Bryce Adelstein Lelbach Show Notes Date Recorded: 2024-04-17 Date Released: 2024-04-26 CheckGrade Tweet Ruff (Python Tool) Software Unscripted Episode 69: Making Parsing I/O Bound with Daniel Lemire The simdjson library CppNorth Composition Intuition - Conor Hoekstra - CppNorth 2023 Intro Song Info Miss You by Sarah Jansen https://soundcloud.com/sarahjansenmusic Creative Commons - Attribution 3.0 Unported - CC BY 3.0 Free Download / Stream: http://bit.ly/l-miss-you Music promoted by Audio Library https://youtu.be/iYYxnasvfx8

Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.

Transcript

From the show. Tap a time to play from there.

BryceUm wait, hey mom, you want to say hi? That's good podcast content.

Bryce's MomSo here's the magic number. The magic number is two? Yes. Can you tell me what it's the number of at the ACCU conference?

BryceI do not know.

Bryce's MomWell, I just came back from the bar and I counted two women. Amongst maybe, oh, I don't know, 50 or 60 computer bros.

ConorWelcome to ADSP the podcast, episode 179, recorded on April 17th, 2024. My name is Connor, and today with my co-host Bryce, we chat about the problem that took Twitter by storm, check grade, get a guest appearance from Bryce's mom, and talk about our acceptances to the CPP North conference.

BryceSo we should we we should we gotta talk about one other thing because it's it's so topical and you you just you're just gonna have to find a way to work it into um you're just gonna have to find a way to work it in. Sorry.

ConorWe will see. Maybe, maybe not.

BryceLet's let's talk about check grade.

ConorOh. Oh yeah.

BryceI mean you wanna you want to summarize for the listener what what Czech Grade is?

ConorNo, no, you're the one that uh brought the tweet up. Uh so you do you tell your story how you because I only stumbled across it because you sent it to me, so you you tell the uh origin story.

BryceSo Czech Grade has been a collective um Twitter code golf moment that has been unfolding this week where some some poor soul tweeted about this problem, and then uh everybody on the internet and their dog um had an opinion, and uh there at first there were a lot of serious opinions and responses uh posted, and then there were a lot of um uh amusing ones posted.

BryceUm but uh the problem is uh so we got a function check grade. Um check grade takes an integer that is a a a score or grade. So it's it's between zero and a hundred. And it's going to return you a string, or really just a character, um, of a letter grade, um, you know, a being ninety and uh up up to a hundred, um, or really ninety and higher, b being eighty up to ninety, c being uh uh 70 up to 80, d being 60 up to 70, and uh F being anything uh below um uh 60.

BryceUh so this poor poor soul um uh called this the arrow anti-pattern because the first version that he wrote or that he tweeted about had like a big nested if loop, a bunch of nested if statements. Sorry. Um so he had like an if score is larger than or equal to 90, then return A, else, and then the else logic had you know if score larger than or equal to 80, et cetera, et cetera, et cetera, recursing down to um to handling you know all the cases.

BryceUm and uh his refactoring that he posted as a reply, um, and this this guy was writing code in Java. We're not gonna hold that against him. Um his refactoring, he creates a dictionary of uh integers to strings and then looks them up in the dictionary. Um and that is not the worst possible solution, but it's a pretty bad one. Um uh because like like why use a dictionary when you could just like use a simple array?

BryceUm and some people posted responses that just used a lookup into a simple array. Um but as other people pointed out, like anything that's gonna involve a memory access is gonna potentially be slow, and you could just do some clever math instead. Um so yeah, and and it just sort of spiraled out, and people, you know, people had opinions about like, okay, should you do this with a switch statement? Should you is it okay to use early returns, like just switch over the um the grades or just like have it some if statements with early returns.

BryceUm and uh yeah, I mean, like like you know, if you look at the if statement with early return, it it does look pretty elegant, but apparently some people really dislike early returns. I think I saw Jonathan Mueller post something about it. I started seeing a bunch of C people posting about it. Um and my my of course, the first first and immediate reaction was um, well, okay, how do we write this in a way that um uh can be lowered down into SIMD masks and will not actually have any branching?

BryceAnd some people, some people came up with clever solutions that'll that'll do that. Um I don't have any of them in front of me, but there's some stuff you can do with some uh uh like divisions and some and multiplications and some clever math where it'll just get you to the right answer um uh without needing any actual branching. It may not be the cleanest code, but it is gonna be pretty fast code. Um, or at the very least, um pretty uh yeah, I'll I'll stick with fast. It may not be efficient code because it may be doing um uh maybe more math heavy than you'd want, but in a parallel context, that's fine if it avoids um uh you know thread divergence.

BryceYeah, but uh I I suppose I just wanted to get my two cents in on this. Um I suppose I my the solutions I probably liked best were those clever, those clever mathy ones or the like uh lookup and a constant array ones. Um because I think that a compiler will lower the lookup in an array um down to something pretty good. Um uh like into like some sort of like jump table or something, um, or it'll just lower it down into the clever math.

BryceUm but I haven't looked at that deeply. Um but I do feel I do generally feel for this fellow who posted this solution, who posted this problem because um uh it got like 600 retweets and like four million views and um a lot of people shit on his uh on his answer. Um and uh you know I think I think somebody you know wanting to find a better way of doing things, uh even if they're even if their first attempt isn't isn't that great, like you know, just getting out there and and making the effort and asking for help is like that's more than what a lot of people do.

BryceSo uh yeah, like I feel like that should be encouraged, not uh uh punished by the internet.

ConorYep, we will link the tweet. My my couple thoughts are one, I don't see what's wrong with early return. I mean, if it was in Python and you were using uh rough linter, like literally you could have just gone rough fix. I actually I should make a YouTube video. I'll make a YouTube video. What's like rough rough R-U-F-F? It's basically uh implementation of like every single type checker, linter, pep standard, formatter. It's like imagine all of the stuff in C, Clang format, Clang Tidy, ASAN, you know, FSAN, all the sanitizers, all the linters, CPP check, include what you use.

ConorImagine like someone created a tool that just re-implements all of that and they re-implemented it in Rust. That's what basically this Ruff project is for Python. So if you've heard of like MyPy as a type checker, or if you've heard of you know the PEP8, you know, standards and linters and stuff, they're implementing all of it. So uh the point is I don't actually know which one of the linters uh warns you about early return, but one of them does. And Rough comes with the similar to clang format and clang tidy where you can give it a dash-dash fix and it'll just fix it for you.

ConorAnd if you were to do this, like you know, if greater than 90 print or like return this else, then it indent, indent, indent. I'm pretty sure rough would just collapse all of that into like five if statements with returns uh because the the lint says like you don't need an else when the only like your previous branch is returning, which I think is completely uh great. The sad thing about Python formatting is that it's gonna put the return on a separate line, whereas I think it looks a lot nicer if it's just on a single line, but hey, that's just my personal preference.

ConorUm my second thought though is all this fancy math that you describe in order to get lowered down into SIM onto uh SIMD. Uh first of all, anybody's whenever anyone ever says SIMD, that's just a fancy way of saying array programming. And second of all, it's not it's it's not fancy math. Like my very first my first thought was like just do the early return to the side.

BryceYou're just gonna drop that on me and expect me to just take it.

ConorYeah. Like I've listened to uh I've listened to an episode on what is what is Richard Feldman's podcast called? It should be called the Rock Programming Podcast, but it's called functional something. Anyways, link in the description to the episode. And he has an episode where he talks to the implementer of simd.json. And every little tool and technique that they describe in that episode is just array programming. Like it's just array programming, building up masks instead of using ifs, et cetera, or finding indices.

BryceYes, but but uh I'll put in the caveat that sometimes you have to write code in a very specific way to uh uh to get it to vectorize correctly with a particular compiler or on a particular platform that is not like, yeah, sometimes you use high-level, like more um abstract ideas to uh write code that's gonna be SIMD efficient. But sometimes it's like, oh well, you know, like we uh we we need to use you know this math operation here instead of that math operation because on this particular x86 microarchitecture, um, you know, that's more efficient.

ConorOkay. So sure. Feel free to add that asterisk. But the what I was gonna say is that the fancy math is a subtraction, an integer division, and a maximum.

BryceYeah, but I think people don't like the fancy math because it's not so. That's not fancy math. That's not fancy math. Three binary operations. People don't like it because it makes it a lot less clear what the function is doing. It does make it faster, and I would definitely write that like, and if you want to know what the function's doing, like put the slow version in the comments. Like put the version that is cle that's easy to read, like that that's that's clear and concise, just put that in the comments, right? And then put the fast thing that like is not as clear like in the code.

ConorI I think it's uh red herring to say that it's harder to read. Just people people can look at an if you know a set of if statements and returns, and I guess because they're used to if statements and returns, but like in calculating an index and indexing into a string inside a one-line function that's called check grade, I don't think like anybody would have any Nah uh Buddy, I I disagree strongly.

BryceI th I think like if if if if if a human like thinks about like how our head processes it, um, like like how we would think about it and describe it describe it to other people, we would describe it closer to the early return if it like if version than to uh the indexing into a string.

ConorThis is why I said the other episode that the array community is the best community, because they think the right way. Everyone, it's easier for people to think about it that way because that's just the way that they've been reading code and writing code the whole time.

BryceBut if you're used to seeing this, like You're such an array language nationalist.

ConorUh I don't think it has anything to do with nationalism, but uh you know, replace that word with another word, and sure, just sign me up. It's it's the right way, it's the it's the way, it's the way to think. Everybody's everybody's hopping on the bandwagon. I mean, you hopped on the bandwagon. It's great, folks. We'll link the SIMD SIMD J JSON episode. We'll link the tweet.

BryceWell, uh, there's an there's an answer here that I gotta show you that I I think is somebody's serious answer, but I I deeply hope it's somebody's joke answer.

ConorWait, it hasn't shared yet. I mean, maybe it's not so bad.

BryceNo, it's pretty it's pretty bad, right? So what this person has is they have a switch statement where they've got um, you know, case 100 and then they have case 99, colon case 98, colon case 97, colon case 96, colon, case 95, colon all the way down to case 90. And they have formatted it nicely. And looking at it, it is not as bad as I thought because you know there's not actually that many cases that you have to handle. Um you only have to have like 40 cases, and then you can default to F for the rest.

BryceBut yeah, there's one person who seemed to and of course the person wrote C has a simple and elegant solution to this. So I'm gonna assume they're a C person, which is why they would they would consider this to be serious code. But yeah, their solution is just a switch statement with uh 41 cases and some nice formatting.

ConorYeah, I don't know why you would do this over the if returns, but I'm pretty sure he's just trolling or they're just trolling.

BryceAaron Ross Powell I don't think they're trolling because I've seen like I've seen people's answers to this who are uh uh not trolling and or who are trolling, and uh they make it a lot more ridiculous. This to me is somebody's attempt to make this particular approach look elegant. Oh I mean I don't know. It's it's not like it does actually look not that bad. Um looking at f at 41 case um statements here, like it's not as ugly as I thought it was gonna be.

BryceBut still, like, you know, like think about it, like think how bug prone this is. Like all you have to do is make one mistake in one of these. Like, you know, like you accidentally you wrote case 95 twice and in and you left out case 94, and then you've got this inscrutable bug in your code. Oh, people, people, people, people.

ConorWell, there you have it, folks. Hopefully, ACCU is good. I mean, by the time the listeners hearing me say that ACCU is over, but uh I hope you enjoy it.

BryceYeah, so um I am one, I'm gonna see you in July because I'm going to C North. Oh talk about it.

ConorMaybe I'll keep that in, yeah. Congrats. Uh which talk I also got accepted as well. So we'll both, you know, if you're going to C Parth.

BryceMy talk Think Parallel got accepted. Um, but uh uh I do not know what version of Think Parallel people will be seeing at uh at uh C ⁇ North. It might be a refinement of Think Parallel scans, it might be a different Think Parallel part.

ConorOh, you gotta you gotta bring us part two, because by that point the ACCU one will be online, and then uh you gotta you gotta keep the content coming. You've already talked about part two.

BryceI I think that C ⁇ North will likely be um the rolling reduce one.

ConorAnd that's fantastic because my talk is also a part two talk, not of an ACCU talk, but of the talk that I gave last year, composition of intuition. So we'll both be giving part two talks, which uh you gotta tell them to not schedule us against each other, because I want to see your talk. So that talk should be fine. I mean ours are ours are too closely related, right? Like algorithms and algorithms, you know?

BryceYeah. The talk I was really excited for at this conference is now scheduled at the same time as my talk.

ConorSo that's unfortunate.

BryceAnd and and yes, Kevin, I I I am talking about your talk.

ConorWell, yeah, hopefully you get to see it online.

BryceI know that uh Bjorn Fowler, he's given the closing keynote, and uh I always love his talk, so that should be um uh I'm pretty sure I will not be around for that, uh, because I'm I'm gonna be on a plane uh briefly after uh my talk going to uh uh Dingle, Ireland. And if you've never heard of Dingle, Ireland, that's because it is in the middle of nowhere. It is in Carey County on the far west, southwest part of Ireland.

BryceUm so yeah, I'll be there for a little while.

ConorFun? Why are you going there? Just for fun?

BryceMy mom has a friend who has a a house there, so we're going there.

ConorNice.

BryceYeah.

ConorGlobetrotting. Globetrotting? Yes.

BryceI it it's like it's bad, man. It's bad. I have um uh so the American Airlines uh like status qualifying year um starts March 1st, and uh it's what April 17th, and I have already nearly re-qualified for the top tier American Airlines status. I gotta, I gotta, I gotta take a break. I I've been on the I've been on the road too much.

ConorYour carbon footprint is probably gotta be one of the worst. Gotta be one of the worst.

BryceI am one of the worst, yeah. I am. I am. All right. Well, um, wait, hey mom, you wanna say hi? That's good podcast content.

Bryce's MomSo here's the magic number. The magic number is two. Yes. Can you tell me what it's the number of at the ACCU conference?

BryceI do not know.

Bryce's MomWell, I just came back from the bar and I counted two women amongst maybe, oh, I don't know, 50 or 60 computer bros. What's with that?

BryceI I think that that's probably a uh uh an accurate ratio. Although I will note that two of the keynotes are women.

Bryce's MomWell, maybe they were both there. I did actually think that the count was going to be three on my way to the elevator. However, it was just a guy with long hair and a ponytail.

BryceBryce's mom doing damage in her first appearance on the podcast.

ConorThat's not damage. This is is I think it's amazing that this uh I was like it's damage to whoever had the long hair.

BryceAnyways, uh Yeah, I'll look into it.

ConorI'll make it happen, folks. If I have to wake if I have to wake up at you know 3 a.m., uh, it's not it's not the most difficult thing I've had to do for ADSP the podcast. So uh we will do it.

BryceWhat is the most difficult thing you've had to do for ADSP the podcast?

ConorOne time I had norovirus when I was in Mexico on vacation, and I was deathly ill for like 48 hours, and the podcast had to be launched in that window of time. Luckily, it was it had been it had been edited, but yeah, I I was I like was barely moving and just curled up in a fetal position.

BryceYou were in Mexico dying of a virus and you still posted the podcast. And this is the first I've ever heard of this.

ConorReally?

BryceNo one never mentioned it. You never mentioned it, which is bad because like most podcast co-hosts, like you know, if if you were dying of something, you'd be able to contact your co-host and be like, hey, can you do this this week? But I'm not that type of co-host.

ConorNo, no, you're not. Uh um, and it's it's only like 10 minutes of work, the actual publishing slash posting of it, uh once it's edited. Uh yeah. So it it it still wasn't, you know, I hadn't broken my leg and was in the hospital and then had to get someone to bring my laptop so I could edit it while on uh you know.

BryceBut you do have a plan in case you've broken your leg and are in the hospital.

ConorI don't, you know, we're possible.

BryceI'll tell you what, Connor. If you're if you are under general anesthesia, um, nothing local, but if you're under general anesthesia, I will take responsibility for getting the podcast posted.

ConorUh sure. I mean, really, my my my backup plan is if like everything really goes terribly, all we need to do is record, and then we'll just I just won't edit it. That that, you know, I will we'll splice the tracks and it'll be like episode whatever, 273. I feel like I should knock on wood there, because that's gonna that's gonna be the one where I'm I'm in the hospital. And uh and then we'll just we'll just ship it. It'll it'll there'll be no jingle, there'll be no intro, and it will be explained in the unedited version, and uh and there won't be any show notes or anything, and and but it'll still get released as long as it gets published.

ConorThat's all that matters truly at the end of the day for us to hit our consistency, you know, week weeks, what is it, 179 at this point, uh as of this episode going out. So we're we're getting there, you know, we're getting there.

BryceWait, wait, is is is episode 200 gonna potentially be recorded when we're at C North?

ConorNo, I believe episode 200, which is 30 episodes away, plus or minus, and it's like four in a month. So that's gonna be uh several months. I think it's gonna be in September of this year. Um, okay. Yeah.

BryceAll right. Well, I I I really should go because I I desperately want to get to the gym.

ConorAlrighty. Good chatting. Enjoy the conference. Okay. And uh any any last words, Mom?

Bryce's MomHave a good time at the gym and break your leg on during your talk.

ConorThank you. All right. Be sure to check these show notes either in your podcast app or at adspthepodcast.com for links to anything we mentioned in today's episode, as well as a link to a GitHub discussion where you can leave thoughts, comments, and questions. Thanks for listening. We hope you enjoyed and have a great day.

BryceLow quality, high quality. That is the tagline of our podcast.

ConorThat's not the tagline. Our tagline is chaos with sprinkles of information.

Open the transcript file

Hosts and Guests

Nobody is credited on this episode yet.

Credit the people on this episode

Be the first to rate this episode

More episodes

All episodes
  1. Episode 313: C++26 Reflection vs CRTP, AI, Kids & More with Zach Laine

    Nov 20, 202647 minAudio

    In this episode, Conor and Bryce chat with Zach Laine about C++26 Reflection vs CRTP, AI, kids & more. Link to Episode 313 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP:...

    • Apple Podcasts

    Credit the people on this episode

  2. Episode 312: The C++26 Contracts Fiasco

    Nov 13, 202652 minAudio

    In this episode, Conor and Bryce chat with Zach Laine about the C++26 contracts fiasco. Link to Episode 312 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP: The Podcast:...

    • Apple Podcasts

    Credit the people on this episode

  3. Episode 311: Career Changes, GPUs & More with Zach Laine

    Nov 6, 202628 minAudio

    In this episode, Conor and Bryce talk with Zach Laine about his career and the career changes he has made. Link to Episode 311 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials...

    • Apple Podcasts

    Credit the people on this episode

  4. Episode 310: Leaving NVIDIA for... ?

    Oct 30, 202624 minAudio

    In this episode, Conor and Bryce talk about Bryce's next chapter and where he is leaving NVIDIA for. Link to Episode 310 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP: The...

    • Apple Podcasts

    Credit the people on this episode

  5. Episode 309: Default Construction & CppCon 2026 with Jason Turner

    Oct 23, 202629 minAudio

    In this episode, Conor and Ben chat with Jason Turner about default construction in C++. Link to Episode 309 on Website Discuss this episode, leave a comment, or ask a question (on GitHub) Socials ADSP: The Podcast:...

    • Apple Podcasts

    Credit the people on this episode