Episode 113: The C++26 Pipeline Operator with Barry Revzin!
40 minAudio
In this episode, Conor and Bryce talk to Barry Revzin about the pipeline operator |>, C++ Ranges and more! Link to Episode 113 on Website Twitter ADSP: The Podcast Conor Hoekstra Bryce Adelstein Lelbach About the Guest Barry Revzin is a senior C++ developer at Jump Trading in Chicago, a research and technology driven trading firm. After programming for many years, he got really into the nuances and intricacies of C++ by being unreasonably active on StackOverflow (where he is the top contributor in C++14, C++17, and C++20). A lot of his C++ knowledge comes from just answering questions that he doesn’t know the answers to, especially when he answers them incorrectly at first. His C++ involvement escalated when he started attending standards committee meetings in 2016, having written dozens of papers for C++20 and now C++23. You might know him from such features as <=>, pack expansion in lambda init-capture, explicit(bool), conditionally trivial special member functions and, recently approved for C++23, deducing this. Outside of the C++ world, Barry is an obsessive swimming fan. He writes fun data articles for SwimSwam and also does analysis for the DC Trident, a professional swim team featuring Olympic Gold Medalists Zach Apple and Anna Hopkin, managed by two-time Olympian Kaitlin Sandeno. Show Notes Date Recorded: 2023-01-15 Date Released: 2023-01-20 Iterators and Ranges: Comparing C++ to D to Rust - Barry Revzin - [CppNow 2021] Keynote: Iterators and Ranges: Comparing C++ to D, Rust, and Others - Barry Revzin - CPPP 2021 Kona Photo of Barry and Michael Swimming CppCast Episode 237: Packs and Pipelines P2011 A pipeline-rewrite operator P2672 Exploring the Design Space for a Pipeline Operator C++20/23 Ranges Libary Ranges-v3 Library Boost.Lambda Library Boost.Lambda2 Library TC39 Pipe Operator (|>) for JavaScript 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.
Barry RevzinHow do you write that as a lambda? Well, it's like open bracket, close bracket, open paren, auto ref, space it, close paren, arrow, decal type auto, open brace, return target, semicolon, close brace. So it's like it's something like 30 characters to three is is what the difference is.
ConorBut our guest today is Barry Revson. I'll do the introduction. Barry is an international keynote speaker. Probably actually, Bryce, I'm not sure if you know anyone that went faster from giving his first talk to international keynote speaker than Barry, because he gave one talk and then he gave one talk at C now, and then boom, that was it. Next talk, international keynote speaker. That's pretty impressive. It's an amazing talk. It compares, I actually don't know the title of it.
ConorIt compares D, uh C and Rust iterator models. Um fantastic talk. I'll put both uh the C now, and I think it was CPPP was the conference that you keynoted at. Yeah, that's right. So there's that. Uh he probably has my favorite C blog. Although it's not just about C, but out of all the blogs out there, his is my favorite. Um so definitely go check out that. And uh what else can we say? You're one of the most prolific paper writers um in contributing to the C language and library evolution.
BryceI don't know if anybody's done the numbers on it, but for C23, you probably wrote more papers than anybody else.
Barry RevzinI don't really count. Yeah.
ConorIt's probably uh I'm well, yeah. We'll put it out, we'll throw it out there to the listeners. I'm sure there's someone keeping keeping stats. Let us know where Barry ranks. If he's not number one, he's probably in the top couple because there's a ton of papers that you've written. Not just for the C23 cycle, but going back. And I'm not sure what else should we say? Should we let you introduce the things that we haven't said? I'm not sure if you want to say where you work. Um some people do, some people don't.
Barry RevzinUh sure. Uh so I work at uh jump trading in Chicago, um, which is uh trading firm that does uh a little bit of everything. We trade everything, all asset classes, all time zones, all products. Um very cool place to be. I've been there for uh eight and a half years. Um it's a pretty nice place. Uh outside of the C world, um, I guess I'm uh very big into swimming, um, which is something that a lot of people don't know about me. Um it is something that if you see my tweets, they're kind of divided into two categories of like random C things and whatever's going on in the swimming world.
Barry RevzinUm briefly there was this uh professional swim league called the ISL. I'm hoping it comes back, but we'll see if I not um and I was involved in that, which is which is a ton of fun um for a fan.
ConorYeah, do you run the swim swam? I know I've seen swim swam. Is that something separate that uh I think if you go if you YouTube your name, you'll get your two C talks, and then you'll get some swimming related things.
Barry RevzinUh yeah, so Swim Swam is like the premier swimming media organization. Um if you if you want to know swimming news, that's definitely like the place you want to go. Um it started, I don't know, maybe 2012, 2011, somewhere around there. Um and I I contribute to it periodically. I write like random data articles, I run numbers for them on a bunch of stuff. Uh definitely definitely didn't found it or own it or anything like that. I just I just contribute periodically.
ConorOkay, just a platform that you contribute to. Yeah. And also, too, so were you uh did you s I think you told me this. You swim you sw you used to swim, um, but now you don't swim as much and you run, or so do you do both now, or are you primarily a runner? Because I'm not sure if you've listened to the most recent episode, but Bryce is thinking about becoming a runner, and I know that you at least have been going on runs because I've seen you tweet stuff about it over the past year or so.
Barry RevzinYeah, definitely, definitely run and swim. Um I'm much better at swimming than running. Uh, but it's obviously a lot easier to run because you just like put on a pair of shoes and just go. You don't need to like plan pool time and get there. Um actually that was one of the really nice things about the the about the Kona meeting is that it's it's just on the ocean. Um so I don't have to like plan to go swim. I just walk out into the ocean and go, and I'm already there, which is which is super nice. So like during that meeting every day at lunch, I would just go swim um along with like Michael Park and Matouche.
Barry RevzinIt was super nice. I could I I could see why people like Hawaii, you know.
ConorOh yeah, I don't recall where I saw a photo. It might have been on Twitter, but there was a photo of you, Michael Park, and was it Matush as well? Like there's a few of you also I think you were in the water, uh, and I was like, damn, that looks quite nice. It was it was awesome.
Barry RevzinBecause it's it's like swimming, except you're in the ocean and there's you know fish. Um on one of the days I nearly ran into a sea turtle. Uh which is yeah, I'm just like, I'm I'm kind of you know, I'm I'm doing my thing, and like there's this like I I see this blob out of the corner of my eye, and I was like, whoa, what what was that? And it's like a turtle, so I'm just like start following around for a few minutes.
ConorWow. That's awesome. I thought you usually um the sea turtles are pretty uh pretty timid, like they don't get too close.
BryceNo, they're they're actually they're they're pretty like they don't they don't really give a f about you. They really yeah, like if you're at some of the beaches in uh in Kona, um and like they think that there's some food like near an area where they are, they'll just come on up.
ConorReally? I thought I guess my impression of that is that I've only been to Hawaii once, but when I did go, I went uh what do you call it, snorkeling. And uh they told us to like uh give the turtles a lot of space.
BryceYeah, so so so and it's uh it's actual actually state law that you're s you're supposed to give them like a a good, you know, uh I don't know, twenty feet or so, you're supposed to sort of stay away from them. I don't know why that is. I don't know if it's that like it's really easy for humans to to harm them, but I I think it's that like they don't want them to like get too used to um uh like being around humans, and I I think that they also can like give you a pretty nasty bite. But I do know that it's like a it's like a state law.
ConorWell, uh we gotta cut this out then because clearly Barry was breaking state laws. You're lucky to do that.
BryceI don't I don't think it like I don't think it really counts if you're just like swimming around and like the sea turtle just like that's an officer! He approached me I just don't think I don't think that's I don't think I don't think Barry's gonna get in trouble for that.
ConorWell, we apologize if uh the C community loses uh a luminary figure, an international keynote speaker, because we we're Barry can still write papers for jail.
BryceAnd you know, the the ja the jails in Hawaii, not not to offend the great state of Hawaii, but you know the airports in Hawaii are like all outside, so I'm sure the jails in Hawaii probably have like a nice pool.
ConorAll right. Well, stay tuned, folks. We'll we'll give you live updates as to uh Barry's uh incarceration status.
Barry RevzinNot not where I thought this podcast was going.
ConorYeah, well, you know.
BryceYeah, no nobody ever knows what this podcast was.
ConorChaos with sprinkles of information. That's our that's our tagline that one someone on Reddit gave us. Um Well, speaking of chaos, I mean we can we I'm not sure if you had plans of what you want to talk about, Barry. Definitely at the top of my list is your pipeline operator papers, uh, because it's probably for C26 the number one thing that I'm excited for, uh given that we have now a bunch of ranges uh adapters in C23, specifically a bunch that don't work with the pipe operator, which we can talk about in a second.
ConorBut before we launch into that paper and then also the uh error propagation paper, because I want to talk about that one as well. Is there anything you want to, because you know you've written so many papers, you know, obviously active in C. Anything you want to start off or things you want to say? Oh, we should also mention you were a guest on CPP cast, which is back, but you were a guest back before it took a hiatus. We'll put that link in the show notes where I think you talk about I think pipes is in the title of that episode.
Barry RevzinSo yeah, I was talking about yeah, I remember talking about a pipeline there too. Yeah. Uh yeah, I mean we can talk about whatever. I have no particular agenda.
ConorAlrighty. So, I mean, uh Bryce, you can go Google this paper. Have you read the paper, Bryce? Probably the pipeline. Well, so there's two papers, and we'll get Barry to give us uh a little background both, but there's 2011, which was the first paper, and I believe that was published in 2020, I'm gonna say, but I could be wrong about that. But there's more recently uh a paper, what's the number? 2672. Um looks like there's only R0 at the moment, and that came out in October of 2022. That paper is entitled Exploring the Design Space for a Pipeline Operator, which it starts off by sort of referencing the Yeah, I've only read the first one.
ConorYeah, it's it starts off referencing 2011, but then talks about the fact that there's a number of different models. And anyways, I'll throw it over to you, Barry. You can give us an overview of the paper and uh in however much detail you want, and then we can talk about is it gonna show up in C26? Um, are people for it, against it, etc.? Over to you.
Barry RevzinYeah, so um, so that second one is uh I think the right way to describe that second paper is abusively long, uh, which is how which is how Zach Lane described it, and I think that's that's kind of appropriate. Um we'll we'll get into that in a bit. So the idea of the operator is that so we have we have ranges, we have range U3, and the way that ranges works is it has certain kinds of algorithms are things that you can pipe into, right? So instead of writing f of x, you can write x pipe f.
Barry RevzinUm and those algorithms are all the range adapters, right? So you can have some range pipe into views transform, piped into views filter, piped into views join. Um and that gives you this nice linear flow um of the work that's being done, um, which which makes it like much nicer to read. Um since a lot of these things, once you get to all the a lot of the adapters, take a second argument in addition to the range, and trying to write that um as just function calls tends to be very tedious because you have you have to like read it all inside out, um, which is which is you know, I I find it a bit hard to read.
Barry RevzinBut in it, like that syntax is really nice, but it has like two problems. Um, one is that it it requires some library machinery to implement, um, and that library machinery doesn't lend itself very well to providing good diagnostics. Um so if you write something like use transform r, comma f and f isn't like a valid um like function for that range, you're much likely to get an error that says something like that than if you do r piped into transform of f.
Barry RevzinUm and this is because like the in the first case you're actually trying to call the thing, and in the second case you're trying to call some pipe operator that ends up being removed from consideration. Um so you'll tend to get errors for like other pipe operators that aren't relevant. Um so that's not the best. Um the other problem is that there's a bunch of other algorithms that you can't pipe into. Um so like all the all the things that like are typically referred to as algorithms, like all the stuff in stood ranges. Um because typically what you do is you build up your pipeline and then you consume it somehow, right?
Barry RevzinYou um the you either just iterate over it with a for loop or you pass it into like now we're gonna have ranges two and C23 to like turn it into a collection. Um, or you you just use something like, I don't know, ranges min or ranges max or ranges fold or something. Like you consume it with some kind of algorithm. Um but you can't pipe into those algorithms because we just decided that that wasn't that wasn't a thing. So you you kind of go back to this inside out style. So you have to write like ranges min and then your pipeline instead of just doing r pipe to transform pipe to min, um, which is something that you can write in in other languages.
BryceWasn't it quite intentional that we made um things like ranges fold, like the algorithms not pipeable because they weren't lazy?
Barry RevzinUm so yeah, there it's intentional that the adapters, and then so in Range G3 also has actions which which aren't lazy, they are they are eager as well. Those are pipeable, um, but but not the algorithms. I don't I don't really think of that distinction as especially meaningful. Um piping I think of as then why didn't we make the uh the algorithms? Well part of it is just like that's that's just like more work that you have to do. Um there's also this issue of not everything can be easily made pipeable, um, because you don't always have this clear way of determining whether your call is a full function call or a partial function call.
Barry RevzinUm so some of the easy examples with range adapters are things like zip and concat, where you can't differentiate between which kind of call you're making, because well, they can just take an arbitrary amount of ranges. Um so zip zip A is uh is a valid thing, and you you have no way of knowing at the call site if which which uh that you meant it to be like a partial invocation.
BryceThis is also a problem with the things from like the sender's proposal, like things like when all anything that's like variadic like that, it it you can't really make a payable.
ConorYeah, is this is that so that's something I noticed when I I'm not sure if you saw that tweet, but I tweeted a couple weeks ago that I realized GCC trunk, aka what will be 13 when they release it, has implemented all the range adapters from C23. And while I was, if you actually look at the code example, it's zip transform, zip adjacent, I think as well, and then the pairwise specializations, none of those are at least in the GCC implementation, and I didn't go take a look at the standard pipeable. Yeah, they're not they're not, they're not gonna be able to do that.
Barry RevzinThat's how they're designed.
ConorYeah, um, yeah.
Barry RevzinSo the transforms have this other problem in that the first the first argument is the function. Right. So if they're pipable, that's not really like the model of piping, because we piped the first argument and you'd you'd want to pipe the second. Um so so this is basically the genesis of this paper, is that we have this one problem that getting the piping to work requires library machinery that's just like tedious to implement at best and isn't great for diagnostics at worst. And then there's all this other stuff that we want to make pipeable, but doing so is possible but but just tedious.
Barry RevzinUm and with like we could do it for the standard library algorithms, but that doesn't help user algorithms that they might want to write. So this is like just like more tedious for everyone. Um so it it would be nice to have a way of getting the like syntactic benefits of this without all of the complexity and all the machinery. Um so this is this is where like the pipeline idea was born. Um well I mean like I should say born. I we didn't like invent this concept. This this concept exists in other languages before before us.
Barry RevzinUm and this is I I say us because uh Colby Pike, um better known as Vector Bull, um is is the first person that I saw pushing this idea. So he's he's my co-author on that initial paper. Um and so the first revision of the paper, the first thing that we tried to do is just define the simplest model, which is that x pipeline f of y evaluates as f of x, comma, y. Like we take the argument on the left hand side and a call expression on the right hand side, and that is evaluated as the left-hand argument as the first argument.
Barry RevzinIt gets like inserted into um the first slot of the call. So there's no like there's no intermediate expression like f of y is never evaluated, doesn't even have to be valid. Um it's just a single thing. Um and so this is this is like a fairly simple thing to to explain. Um it behaves a lot like member function call, if you think about it, right? Like x dot f of y, what that does is it shifts x over to be the first uh argument. Um and especially now with deducing this, like it it really does behave like that. Like it like we're moving this this this parameter around and making one function call.
Barry RevzinUm so that was that was kind of the initial uh design that we had. And this was the 2011. Yeah, so that's that was the R0. Um and so it turns out, as as with a lot of things that are seemingly simple, um, there's a lot of interesting things to think about in the space. One ends up being, well, what's the precedence of this thing? And it and it and it kind of turns into like a surprisingly weird thing to consider. Um so one example might be so if okay, so x pipeline to f of y validates as f of x, comma y, what does like f pipeline to f open paren y close paren open paren closed paren mean?
Barry RevzinUm which of the two function calls are we moving x into? And the same kind of holds for other kind of like post-cific expressions. So you end up kind of wanting to have it to have very high precedence because it behaves a lot like dot. So you want it to behave like dot. And there are a lot of kind of interesting things there. Uh but then we kind of started talking about well, like there's a lot of other interesting things you might want to do with piping. Uh so the zip transform example you brought up, you don't want to pipe into the first argument, you want to pipe into the second, um, maybe even the third, depending on what you want to do. Um, so wouldn't it give more flexibility if we open up to the user where we're moving this argument into?
Barry RevzinUm so like if there's a placeholder that we could that we can pipe into.
BryceWell, well, there's there's also the case where you might want to uh uh pipe it into multiple arguments. Right. Like yeah, and and that also becomes useful if you um it when you want to do like more complex things, like you know, fork join style models, which you can sort of emulate with some sort of like tuple-like object where um you know you you do something uh like similar to similar to like a zipper or like a win-all in senders. Um but then like later in the chain you want to decompose it into its constituent parts.
BryceUm and maybe you want to call a function where you want to say like call this with you know the first and third argument of this couple um uh as the as the uh the two arguments of this function. But it it uh without um with the m with without a model that has a placeholder, it's a little uh uh tricky to do that cleanly.
Barry RevzinYeah, so placeholders are also interesting because they all uh arguably they make it more clear what's going on. Like if you see this expression on the right hand side and you see the placeholder, you kind of know that like, okay, well this is this is where the argument on the left is going. Um but then once you get into place. So one of the interesting issues with multiple placeholders is like, okay, well, if the left-hand side is an L value, then having multiple placeholders, okay, well that that's obvious, right? You evaluate the left-hand side once and you just like use it in both places. But if the left-hand side is an R value, well, like what do you actually do with it?
Barry RevzinUm you definitely don't want to evaluate it twice, because that just seems totally totally wrong and very surprising. Um, but if you evaluate it once, do you like give it as an R value in both places? Do you like escalate it to be an L value? Um that's that's kind of hard. Like I don't know what the right answer for that is. So like I I think in the in the in the last paper, I'm um I suggest escalating it to be an L value. Like evaluate it once and then treat it as an L value multiple times. Um uh alternatively make it ill-formed if it's not, um if it's uh not an L value.
Barry RevzinBecause you can always stick in a function in the middle to turn it into an L value and then pipe that L value twice if that's what you really want. Um, but at least then it's explicit. Um so this is kind of what I mean by like once you start diving into things, there's all these like weird issues that come up. So one is like, okay, like where can you pipe things into? Um because one of the things when you look at it syntactically, you you have this expression and then you have pipeline, and then and then you have stuff. So like it really looks like you're always evaluating the left-hand side, right? Um, so you don't necessarily want to allow piping it into a location that it wouldn't necessarily be evaluated in.
Barry RevzinUm so for instance, like x piped to like y or placeholder, well, that you're not always evaluating that that expression then. So like if you unconditionally evaluate it then, but then use it in a context that it has short circuiting, like that's kind of weird. And then like what if what if you then use it in an unevaluated context on the right-hand side? Like you have an expression, then you pipe it into like decal type of that expression. Also, like, well, it looks like you're evaluating it, but you're but you're not if we think about the expression rewrite. So like is that something you want to allow or no?
Barry RevzinSo this is this is why the paper ends up being abusively long, uh, because you have to deal with all this stuff. Um where it gets even more interesting is that like once you have placeholders, you can think about like, well, what does the we have this right-hand expression that has placeholders in it, but like what is how does it behave? Like if you look at that thing in like if you look at like f open paren, let's say dollar is our placeholder, like f open paren dollar close paren. That's kind of like a lambda, right? You you can kind of think about it as like, well, I'm just constructing a lambda with placehold on the fly and then invoking it.
Barry RevzinUm it's not exactly that.
BryceAnd and in fact, in the in the old library only boost lambda model, the uh uh like that's how you would write a lambda function is you would have these um these like underscore one, underscore two, underscore three uh uh placeholders that were these you know magic objects, and you could do like underscore one plus three, and then that would give you back a lambda that would To take one argument and then that would add three to it. And I I still know some people who use that library, even though we have C11 lambdas, because it's such a f when you're doing something that the that the library when you fit into one of the use cases, like you know, adding up some things that the library is really good at, um, like it's much more concise to just write your lambda that way.
Barry RevzinYeah, absolutely. And there's actually there's a new boost library called Boost Lambda 2 that Peter Dimoff wrote a couple years ago. Um and it's I mean it's it's fantastic. So when I was implementing zip um as part of like so Tim Song wrote the paper for zip, and then I implemented it kind of from spec to make sure that all the wording was right. Um and I use BoostLambda 2 for all the implementation because a lot of a lot of the stuff, so you think about like so zip, the iterator is like a tuple of iterators, and every tuple operate, every like iterator operation is an operation on like through this tuple, right?
Barry RevzinSo it's either like a tuple transform or like a tuple for each or something. Um and all the functions that you want to do are like trivial. So like dereferencing zip iterator is like dereferencing all the underlying iterators of the stuff into a tuple transform. So with boost lambda two, how do you how do you write the function that is dereferencing the first argument? Well, it's star underscore one.
BryceYeah.
Barry RevzinUm how do you write that as a lambda? Well, it's like open bracket, close bracket, open paren, auto ref space it, close paren, arrow, decal type auto, open brace, return, star it, semicolon, close brace. So it's like it's something like 30 characters to three is is what the difference is.
BryceYeah.
Barry RevzinUm so yeah, this kind of so you know this kind of like placeholder stuff, if if we could have it in lambdas directly, would be super useful. Um so once you start dealing with placeholders and pipeline, well, that lends itself to like, well, what if you use that same technology to actually construct a lambda directly? Like, what if we had a new kind of lambdas that was just based on placeholders? Um and so there's a whole section in the paper of like kind of exploring what that means. And like what kind of syntax could we use? And what how do we like differentiate it from the lambdas that we have today?
Barry RevzinAnd and how do we um how do those apply?
BryceSo if we if we had that new sort of syntax, would you then instead of having placeholders directly in the piping operator, would it just be that you just say that the right-hand side is a you know a function object, and then just the the convention would be that people would use the abrupt the super abbreviated lambda um uh syntax to write them? Or would you still want the placeholders directly in the piping syntax?
Barry RevzinI think you'd still want the placeholders directly because there's a few there's a few significant differences in why you wouldn't want it to just be a function call. Um one is for lambdas, like we'd still need capture. Because we we even even with the placeholder case, like we we we're still C and we don't want to do either like you wouldn't want to pick like an implicit capture, so you you'd have to you'd want to make it explicit um for one reason or another. But then it's not really a function call because like if we know we're piping, we know we're evaluating this directly.
Barry RevzinUm so we don't want to like introduce another scope, um, which is particularly important because like one of the things, once you get into the placeholder land, um you can put an arbitrary expression on the right-hand side of pipe. Uh you we just give pipeline extremely low precedence, and then you could do things like you know, maybe the motivating use case is doing like f of placeholder, but you can also do f plus placeholder, f times placeholder, right? You can use placeholder as like a substitute for parentheses. Um but importantly, one of the things you can do is co-await placeholder, co-yield placeholder.
Barry RevzinUm and and so like if you if you want to do like the covertine operations, then you you can't make it uh a function, right? Because you can't introduce that other other function scope because then you break co-routine mess.
BryceUh yeah, that's a good point.
Barry RevzinWhich is actually one of the places where this whole like, well, what if we think about it as like a language bind kind of model kind of breaks down? Because if you want to support co-wait, um, which I think makes perfect sense to support, um, then like that doesn't really work by thinking about it as a function, so it's like uh I don't know. It's it's it's kind of like a weird thing.
ConorOne of the things to ask you, and actually you might not know the answer to this question. I think you and I, well, at the end of the paper, you sort of articulate between the design choices what you're what you are in favor of, and pipeline plus placeholder is definitely something you want, which is definitely something I want as well. Not just for the fact that there are a number of range adapters that I mentioned before that don't work with the pipe operator and the fact that they don't work with uh the algorithms in the you know std colon colon ranges namespace.
ConorIt also enables you to do the duplicate things, which is a whole other thing that I like because you can technically mimic some of the composition patterns that you get from combinatory logic, which is like a big thing that I really like. However, there are some people that are against the placeholder and I I think one time I I tweeted something and then Gasper replied, Gasper Asman, who is uh member of the C um committee, and he said, please no, don't put the placeholder uh in.
ConorAnd I think I asked why, but I don't think he replied. Do you know what like the main sort of drawbacks other than because I know the paper mentions that it's a bit more verbose in the case where you have to, you know, you have a bunch of unary things, and yes, having to have having to spell out the unary thing is a little bit uglier, but in my opinion, that's like a weak argument that you're you're getting uh something less verbose uh compared to like giving up the flexibility that you get with the placeholder. Do you know what potent potentially Gasper and other folks that are against the placeholder what their motivation for that is?
Barry RevzinOr so I think their verbosity is a significant argument against um for what I hear from people. Um and it's even something that I um that I've seen multiple people suggest like, okay, well, placeholder, but allow the placeholder to be optional so that you can pipe to something like f paren paren and have that work as if you like as if you had the placeholder. Like if there's no placeholder, then it has to be a function call, then you stick it into the first argument kind of thing.
BryceThere are even people that that argue against the the need for the paren. Like like um when we were standardizing ranges two, there was a um uh a point of contention about whether you'd need to write like x pipe ranges two with empty parens or not. Um you know, it so I I I I I think that there is there is a great desire for conciseness from uh certain set of.
ConorJust to clear up the ambiguity for the listener, this is ranges colon colon to, not like a second version of ranges that we're introducing. Yes. It's hard to speak about that one function.
BryceOr or maybe maybe a simpler way to explain that is like there are some people that if you have like x pipe f empty parens, some would argue that it'd be more elegant to have just x pipe f.
ConorYeah. It's definitely more elegant, but like, you know, we're the language that Barry just spelled out our lambda is like uh you know, yeah, we're we're not an elegant language in in many ways.
Barry RevzinSo yeah, so the two I think I think they're actually slightly different arguments. So the argument for two, I think, is a little bit different in that if you look at all of our unary um adapters, you don't have to put parens for any of them. Right? So if you apply it to views reverse or views join, um you can put the parens, but you don't you don't have to. They work they work without it. Um in fact I've I like I never see anyone write parens. Um and and so that works. And so in that sense, if you think about like two to uh like std vector, close bracket, um that is unary, right?
Barry RevzinLike I'm just piping a range and I'm converting it directly to a vector. Um so so why is that the one unary adapter that I have to put parens in? Um like you can it can take other arguments, um, but I think the overwhelming common use case will be that it won't take any. Um and the only reason actually that it takes parens is that we're not even sure if the core language uh blesses the implementation approach to getting rid of the parens, like if that is actually valid um per the language.
Barry RevzinUm so it's it's not even like uh this is like a structural design reason why the the parens are super important. We're just like not sure if it's uh actually legit. Um but but the other for pipeline specifically, um so this is this is what I find interesting is that so there's a JavaScript proposal for the pipeline operator, and and I link to it in in all the papers. And there's been a lot of discussion on there over the years about various designs, and they they're they've gone through like the same kinds of like, well, like there's like three or four different models for pipeline and which is the right one.
Barry RevzinAnd they've also um seriously considered this like um use a placeholder, but like make it optional, and what does it mean for not having a placeholder? Um and one of the issues is that like the optionality does add complexity to the design, right? Because you have to determine what that means. Um and in particular, like if you want x pipe f to automatically mean f of x, but you also want x pipe to f open paren like close paren to mean f of x, um how do you like so does no placehold holder mean you call the right hand side, or does it does no placeholder mean you insert into the right hand side?
Barry RevzinUm, do we have different rules for f versus f paren paren? This this adds complexity. Um there's also discussion there about um and some of it was like more specific to JavaScript, like we wouldn't have this problem. Um but like how do you know that the user intended to do this or not becomes more of an issue. Um and the the way that they're leading is is mandatory placeholder. Um because like placeholder stuff, once you have placeholder at all, that's that's complexity, right?
Barry RevzinBecause the the simplest version that was like the R0 version that we propose, where the right hand side has to be call expression, then you just like stick it into the left hand side. Like that's a that's a fairly simple thing to explain, and it's a fairly simple thing to implement. Um and I can even I can say that because like I implemented this in Clang and it did not take me very long. Um and like it was probably not the right way to implement it in Clang. Like I didn't like create a new AST node, I just kind of hacked it into like the regular function call node. Um but it it's like a very simple thing to implement. Um, versus placeholder is much more complicated, and you have to deal with like, well, what things can you placehold into and not, and can you use it more than one time?
Barry RevzinAnd like, what about lambdas? Um but but it lets you do so many more things and it adds a lot more explicitness um to it. And so I'm not sure in the grand scheme of things that saving one to three characters per expression like ends up being like a make or break kind of thing.
BryceYeah, I can't I kind of I think I agree with you. And I I think that there's a uh if we're going to do a link language if we're gonna add new language support for a uh a pipeline operator, surely one of the rationales and motivations for that is to uh enable pipelining um of things that we can't do today. Um and I think a lot of those cases, a lot of those more interesting cases, like ones that Connor and I have talked about on this podcast before, um, would really benefit from having the placeholders.
BryceSo if if we're if we're going to go through the trouble of adding language support, I think we um we would use lose a ton of utility if we don't have uh uh placeholders. And uh a world with with optional placeholders would mean um uh you know you'd essentially have two syntaxes and and there would be a lot of potential ambiguities and there'd be more things people would have to learn. Um and I don't mean like language ambiguities, I mean just like you look at the code and you're like, huh, what does this mean?
BryceLike mental ambiguities. Um and I I don't think that the uh the additional you know a couple characters you have to type is that bad. And I also think honestly that it'll be a lot um a lot more teachable. Um you know, when you explain like the pipe piping to people today, you usually tell them it's like Unix, you know, like gels, it sort of works like this. Um and that's like a good analogy, but that that sort of assumes that the way that like a Unix gel pipeline works is like this intuitive thing.
BryceAnd it is an intuitive thing because we all know it, but I think it's not necessarily natural. I if you just look at some of these examples in the paper with the uh placeholder syntax, I think if you showed somebody who had no um who had knowledge of C, but had no knowledge of, you know, uh pipe, the pipe operator, um uh and no knowledge of like ranges piping and no knowledge of Unix shells, I think that they would look at that and they probably understand what what it meant. Um yeah.
ConorAlright, chip it. C plus plus 26.
BryceUm what was like so what do you what do you think the odds are, Barry?
Barry RevzinUm I don't I don't know.
ConorYou don't you don't put bets on your own paper? I I don't.
Barry RevzinUm well like also because like I don't even know what the right answer to any of these questions is. So uh I mean I know I know what some of the wrong answers are. Like there's a pipeline model where you just where the right hand side just invokes, you treat the right hand side as a function and you invoke with the left hand side, which is like the F-sharp model. Um that's definitely the wrong model for C, because that doesn't help us at all. It just like makes everything more verbose. Um so I know some wrong answers, but like I don't I don't know what like the right approach is.
BryceUm that that is the inverted invocation in the paper.
Barry RevzinSo that that works very well for languages like F-sharp that have like a lot of other languages support for like curring and partial function application. Um we don't have any of those things. And without those things, that that model just doesn't make any sense.
ConorYeah. Um that's something that's something that I think about when you're talking about sort of the elegance or the lack thereof in C is that for languages that you know function invocation typically requires parentheses, like it's you you end up in a completely different space than when you're you know comparing it to a language like Haskell or F sharp because those languages one are functional at their core, and two, like the it's just completely different. Like the way that you do uh you know quote unquote piping in Haskell, like it's uh completely designed around the fact that those languages you know have, like you said, partial application and and currying.
ConorAnd you can do like things super uh nicely like flip, and it's just you know flip and f insert that in front of a function and you've you've swap the order that you pass arguments. In order to do that in C, you know, you're calling a template metaprogramming function and boost HANA that you know does the same thing, but it's it's nowhere as easy as just putting a function in front of your other function. And you know, yeah, uh it's just a different, you know, the there's a part of me that's like, oh yes, I want this beautiful, elegant model, but like we're not Haskell, we're not F sharp.
ConorWe can't get that. And uh yeah, you have to, at least for me, I put my elegance like heart on the shelf and say we're in C LAN, let's just get the flexible thing and uh sort of live with it.
BryceUm so I I think there's another uh uh potentially big advantage to uh language support for a pipeline operator that we've maybe not talked about before, um, which is uh like ranges piping is cool and all, but there's like a lot of library machinery that uh you need to do to make it work. And um uh there's this sender's proposal, which is a proposal for you know this asynchronous programming framework for C, which also has uses the piping uh syntax.
BryceUm and also has a lot of language, a lot of library machinery to uh to support that. And I I think that um uh having this in the language would maybe not drastically reduce the the the inherent complexity of these big library proposals, but I think it would it would it would decrease the complexity somewhat, and that I think is you know a worthy thing to do. Yeah.
Barry RevzinYeah. I would say I guess as far as like odds go, it really depends on because there are people that think that placeholders are obviously the correct design, and and a design without placeholders is totally unpalatable. Um and then there are people that think that placeholders are bad uh because they add complexity and they add verbosity to what will be the overwhelmingly common use case where you want to pipe into a function call and you want to pipe into the first parameter. Um and so I think I think it largely depends on what the relative sizes of those two groups end up being.
BryceUm to some degree, you know, the the existing uh uh piping that we have in ranges, it's not like we're just gonna get rid of that. So the people the people who don't want uh placeholders um uh or who want placeholders to be optional, then that syntax, at least for ranges, is gonna be there forever.
Barry RevzinYeah, we can't really get rid of it.
ConorYeah. All right. Well, we're I think roughly 45 minutes into this, and we and uh that's about like the halfway mark. I have no idea how I'm gonna cut this up, but before we move on to uh the next paper, um, and maybe we'll maybe we'll turn this into like a mini Rust episode because we're in our Rust phase of our podcast. We've temporarily turned into a Rust podcast, kind of. Stay tuned to hear Barry's thoughts on the Rust programming language in part two of this two part interview. Thanks for listening. We hope you enjoyed and have a great day.
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:...
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:...
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...
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...
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:...