Live data from Hacker News

Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

risingwave-labs.com

271–280 of 307 posts

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#271

Earlier quoted context omitted.

OOP is not C++ best practice these days. For me C++ best practice is: - Smart pointers - auto and const references all over the place - RAII - Pure data structs - Free functions - A little bit of templating but not too crazy Modern C++ reads a bit like JavaScript strangely!

> OOP is not C++ best practice these days. I didn't say it was. I didn't say anything about best practice, only about familiarity.

Good point. Bad ideas don’t die, only practitioners

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#272

Earlier quoted context omitted.

Indeed, but to be fair, Rust's smart pointers can be used to create memory leaks just as easily as C++'s. (Overall I think Rust is a much better language than C++, though).

You don't even need a smart pointer: `let bar = Box::leak(foo);`

Full example of a Rust program that leaks memory: `fn main() { Box::leak(Box::new(0)); }`

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#273
post #80

Earlier quoted context omitted.

I'm quite nooby in both Rust and C++, but for the little interactions I had, I felt like Rust had a much clearer path forward than C++ when I was in doubt, and "how to write in good style" was more obvious. This leads me to the assumption that building a Rust culture is probably easier than building a C++ culture, because it is easier to get junior developers and those coming from other languages up to speed.

Yep. The one big beginner “mistake” I see people make in rust is overusing Box / String / Vec. Rust code that allocates everywhere can be even slower than javascript. The reason? Malloc is slower than you think. Slower than short allocations in V8 or Go. If you want performance, make friends with &str, &[], >, bumpalo, SmartString and SmallVec. (Or similar crates). Removing allocations from the hot path can improve p…

> Slower than short allocations in V8 or Go

Slower than V8, definitely possible. Slower than Go, very unlikely, since it doesn't have a generational or compacting gc.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#274
post #168
post #77

Earlier quoted context omitted.

There are settings you can place in .gdbinit to avoid stepping in to internals of anything you don’t want to step into, be it std library classes/functions or your own code. Much nicer than hacky ifdefs.

> There are settings you can place in .gdbinit to avoid stepping in to internals of anything you don’t want to step into, be it std library classes/functions or your own code. This is exactly what I need. For both, C++ and Rust smart pointers. Can you share any more info on how to set this up?

On mobile at the moment so can’t check my .gdbinit, but a quick search turns up this page which seems relevant:

https://sourceware.org/gdb/onlinedocs/gdb/Skipping-Over-Func...

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#275
post #115

Earlier quoted context omitted.

I would love to hear more about "fsync saga" if you have any references. I know that PostgreSQL had "problems" with fsync(), but they never ended. They just accepted defeat, but so would everyone else who relies on filesystems to store their data. It's even more ingrained than that. The way hardware works, and, especially, the communication protocols around it (eg. SCSI or NVMe) are structured, fsync() is always goin…

See this chain of articles: https://aphyr.com/posts/284-jepsen-mongodb The mongodb organization repeatedly poo-pooed the issues with data loss, and only after repeated public exposure of the issues did they do anything about it. I don't know why people aggressively deny this when anybody can just google it and judge for themselves.

Thanks! This was very interesting. But, did they actually fix this? The three posts are about the problems, but they go up to 3.X version of MongoDB, and the most recent seems to be at 6.X.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#276
post #107

Earlier quoted context omitted.

Segfaults happen, you run valgrind/asan/tsan etc. As long as the codebase is not horrendous its easy to fix. Third party packages complicate things, have to choose/use wisely/appropriately

In Rust they are really rare. Like vanishingly small numbers of them. C++ definitely. SegFaults happen. Sometimes they are even in prod. Rust not so much.

So far there isn't that much stuff written in Rust, so, any non-trivial Rust program will link with a bunch of non-Rust code. On the project I worked on, we had to link with SPDK for example (a rather big iSCSI server implementation).

C++ has been around for... what?.. 40 odd years? And any non-trivial project still links with C libraries.

I don't see this problem somehow going away in Rust w/o some revolutionary changes in operating systems, which is the major supplier of decrepit but unavoidable libraries you have to link with in order to get anything done.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#277

Earlier quoted context omitted.

This is the one issue I personally have with C++. How do I `pip install boost`?

Note that a lot of the pip projects are implemented in C++. You install packages for the environment you are targeting. A lot of folks use Conan or vcpkg for pure C++ dev.

Sorry, I was using `pip` as an example of an easy build system to use to get stuff working. Is it as simple as `conan install boost` within a projects dir?

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#278

Earlier quoted context omitted.

Says who? I love prototyping things in Rust.

Both viewpoints make sense; whether Rust is good for prototyping depends on the domain. If it fits the borrow checker well (like in CLI apps, stateless servers, data transformation) then the borrow checker fits beautifully and seamlessly. In other settings (complex turn-based games, some compilers, GUI), the borrow checker can cause some artificial complexity and prototyping slowdowns compared to other paradigms.

I guess it depends on your point of view. For me, having Rust catch issues even when prototyping makes me enjoy prototyping more. I absolutely hate (even when prototyping) when I try to run something, it chugs along for a bit, and then hits a runtime error due to some stupid typo.

In fact I like Rust for prototyping precisely because I don't yet have tests, and the extra compiler diligence frees me to focus on the prototype.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#279

> Rust is easy to learn. For seasoned C++ programmers, Rust is easy to learn. When they first start out, Rust learners usually spend most of their time making sense of ownership and lifetime. Even if they don't explicitly express these concepts in code, experienced C++ engineers always keep these two concepts in mind when programming in C++. Finally somebody understands this.

As someone with a passable level of modern C++ exp it took about a week to pick up Rust. Syntax was the time sink...

Though, people tend to gloss over that C++20 is decently comparable to Rust in terms of semantics and safety, the issue is very few C++ codebases are modern and the footguns are still lurking for the careless.

That said, Rust iterators are very nice and the async story completely mocks the C++20 coroutine nonsense.

Re: Building a Cloud Database from Scratch: Why We Moved from C++ to Rust (2022)

#280

Earlier quoted context omitted.

Hot take, I feel like people that complain Rust is hard typically write bade code in other languages. Rust is just preventing you from making common mistakes or using patterns that make your code hard to reason about and debug later.

As a fellow Rust user, please stop saying this. Not everyone who codes like us is a bad programmer. It's this kind of sentiment that gives us a bad name. Rust may influence us into patterns that are better in some (likely even most) situations, but not always. Sometimes the situation calls for other approaches, and that's okay.

Think you're misunderstanding the OP. Do you think rust is hard to use?
Post reply on HN