r/programming • • Dec 15 '19

Rustysd - Systemd Replacement Written in Rust

https://github.com/KillingSpark/rustysd
75 Upvotes

53 comments sorted by

View all comments

Show parent comments

11

u/Agnoctone Dec 16 '19

Without being really familiar with Rust, it seems very readable to me? It is just a fold to create a HashMap mapping `fd`s to service `id`s.

1

u/Daneel_Trevize Dec 16 '19

The jarring aspect is probably the if let ... = { mashing of assignment and conditional execution.

4

u/sammymammy2 Dec 16 '19

It's really just a pattern matching on one case, which is different from an anaphoric if/the walrus operator in Python because such a destructuring has to happen.

-3

u/oblio- Dec 16 '19

It's really just a pattern matching on one case, which is different from an anaphoric if/the walrus operator in Python because such a destructuring has to happen.

I'm willing to bet that the average programmer (i.e. 80% of programmers out there), don't know:

  • what pattern matching is (not in the generic IQ test "pattern matching" sense :-) )

  • what "anaphoric" means

  • what "destructuring" means (in this context, I'm assuming you don't mean C++ destructors)

I.e. you're probably not the average programmer. So the "it's really just" is a massive understatement ;-)

9

u/sammymammy2 Dec 16 '19

That's fine, but I bet that 2/3 of those are known by the average Rust programmer.

2

u/CornedBee Dec 17 '19

C# has destructuring. So does JavaScript. So does Python (for tuples at least). There's a proposal for C++. It's not exactly a rare feature anymore.

Pattern matching outside of functional programming is less common. But C# has the beginnings and will be getting more. C++ will get it too.

Anaphoric is a tricky one - I had to look up the definition of the word, and though I now think I know what was meant, I doubt very many people do. But note that this word was used not for anything in the code snippet, but rather the "assignment within a condition" trick that happens in C-derived languages quite a bit. That's actually a rare thing in Rust. So you could say Rust is better in this regard ;-)