Pipelining might be my favorite programming language feature

https://news.ycombinator.com/rss Hits: 27
Summary

Epistemic status: Don’t take it too seriously. Or do. idk, I can’t stop you. Pop culture reference. Toggle original/dithered image Pipelining might be my favorite programming language feature. What is pipelining? Pipelining is the feature that allows you to omit a single argument from your parameter list, by instead passing the previous value. When I say pipelining, I’m talking about the ability to write code like this: fn get_ids(data: Vec<Widget>) -> Vec<Id> { data.iter() // get iterator over elements of the list .filter(|w| w.alive) // use lambda to ignore tombstoned widgets .map(|w| w.id) // extract ids from widgets .collect() // assemble iterator into data structure (Vec) } As opposed to code like this. (This is not real Rust code. Quick challenge for the curious Rustacean, can you explain why we cannot rewrite the above code like this, even if we import all of the symbols?) fn get_ids(data: Vec<Widget>) -> Vec<Id> { collect(map(filter(iter(data), |w| w.alive), |w| w.id)) } I honestly feel like this should be so obvious that it shouldn’t even be up for debate. The first code example—with its nice ‘pipelining’ or ‘method chaining’ or whatever you want to call—it just works. It can be read line-by-line. It’s easy to annotate it with comments. It doesn’t require introduction of new variables to become more readable since it’s already readable as is. As opposed to, y’know, the first word in the line describing the final action our function performs. Let me make it very clear: This is an article hot take about syntax. In practice, semantics beat syntax every day of the week. In other words, don’t take it too seriously. Second, this is not about imperative vs. functional programming. This article takes for granted that you’re already on board with concepts such as ‘map’ and ‘filter’. It’s possible to overuse that style, but I won’t talk about it here. You already agree with me Here is a feature that’s so bog-standard in modern programming languages that it barely fee...

First seen: 2025-04-21 12:35

Last seen: 2025-04-22 14:41