Couple of weeks ago there was a post here calling for more content to be posted in this sub, so I figured you might appreciate the content. As a project, Biome is also helping a lot of web developers become interested in Rust, since many of our contributors make their first-time Rust contributions there.
arendjr
Please, please make a blog and spew your tirades there 😂
So to put it all together
ComplexEnum = Nothing | TaggedU32 | (bool x String)
? Is that correct?
Pretty much, yeah. But just be aware the tags are effectively unique constants, so each has only one value. For consistency I would write it as:
ComplexEnum = Nothing | Something(u32) | LotsOfThings(bool x String)
In this notation,Something(u32)
could also be written as 1 x u32
because tags are constants.
take in user sourced input without any sanitization
But that’s exactly the problem: these applications were sanitizing the input using the APIs provided by their language standard libraries. Except that sanitization proved insufficient because the requirements for sanitization differ greatly when the command is interpreted by cmd.exe
as opposed to running regular executables. This is such a big footgun in the Windows API that it was overlooked by seemingly every major programming language implementation out there.
It would print “&& rm -rf /“ and nothing bad would happen.
That’s entirely dependent on the application. In many cases the command would be hard-coded in the application, in which case you’re right. But some applications have good reasons to pass user-supplied arguments to scripts. Imagine a case where an application generates PDFs through a batch script, for instance. It might make sense to let users specify the filename, but then it does need proper escaping. In such a case it’s a huge risk if it turns out the escaping rules suddenly changed because Windows silently invoked cmd.exe
under the hood.
It’s a bit arguing about semantics really. But Rust and Haskell are merely the first ones with patches out. The issue affects other languages as well, including Java, Node.js, Python and seemingly every language with Windows support. I think it’s fair to call it a Windows problem, since it affects everyone there.
But languages like Rust and Haskell are promising their users that they are protected from this kind of behavior, which is why they want to patch it quickly. Some of the others merely updated the documentation, effectively saying yeah it’s a risk. Java went as far as saying they won’t fix the issue.
It also seems harsh to say iterators aren’t a zero-cost abstraction if they miss an optimisation that falls outside what the API promises. It’s natural to expect collect to allocate, no?
You're right, I wouldn't say iterators aren't a zero-cost abstraction. But most abstractions are also leaky -- it's just the extent in which the leakiness is exposed that makes them more or less effective. As such, saying to just use retain_mut
instead of the iterator approach highlights the shortcoming of the abstraction. But if the same results could be achieved while still using the same iterator, that would make that abstraction more useful and consistent. And that's great, because that means we need to worry less when using iterators :)
The composability doesn't have much to do with whether it's a reference or a move, it's because it bypasses usage of the Iterator
methods. Iterators chains can consist of filter
, map
and other operations, which allows various functions and/or closures to be composed together. Whereas with retain_mut()
there isn't really a chain and functions you may otherwise use in an iterator chain become harder to (re)use.
Thanks! That’s very much what I was looking for!
That was a super interesting and informative read! Exactly what I was hoping to find when I posted this, thanks!
Almost nobody uses the TypeScript compiler for transpilation. I think most people nowadays use either Esbuild or SWC for that. The advantage that Biome has is that we already have the parsing and the serialization infrastructure and can add features like that with relative ease. For users that means fewer dependencies, less configuration, and less room for error.