HNHacker News
TopNewBestAskShowJobs

dureuill

456 karma · joined July 24, 2021

submissionscomments
dureuill··on Ask HN: For those running Rust in production, do you build on a remote server?
I build locally. On my projects compile time has been much better than in our C++ projects (which is bigger, but still I'd say that rust compilation isn't slower than c++'s)
dureuill··on Rust – A hard decision pays off
I mean, it's only natural.

I have been using C++, Python and Rust professionally, the developer experience is simply one order of magnitude better with Rust. The tooling is excellent, a sane compilation model brings you a lot, the type system is very helpful. Compared with C++, I measured x3 productivity on writing initial code on a project (sometimes C++ was the rewrite, sometimes Rust was, so not this kind of bias). Compounding maintenance, I expect it to tend to 1 order of magnitude in time.

Meanwhile, using Python can sometimes feel magical, but I have to maintain a library written in the language, and I can feel that it hasn't been optimized for this use case. It is terribly hard to keep backward compatibility, adding typing annotations is somewhat useful, but has terrible ergonomics, ensuring no regression is a pain that translates to endless suites of unit tests even for trivial matters ("be your own compiler" will never be a great idea IMO, although tooling like pylance does help a bit).

Meanwhile the rearguard is defending for new projects some kind of "No true Scotsman"ish modern C++ delusion, that I am still looking for and that moves like goalposts in every discussion I have with its proponents. My only explanation for the phenomenon is that it is fueled by hubris and sunk cost biases, because my experience with the modern idioms is that while they bring significant improvements, they are still very subpar compared to the expectations brought forth by a modern language, and memory safety related CVEs are still being written everyday in C++.

So, what should I do? It is true that, in more than 15 years of coding, Rust represents a revolution in programming in my eyes. Should I sit idly while others are missing on it and someone is wrong on the Internet?

dureuill··on Why should I have written ZeroMQ in C, not C++ (2012)
Yes we've been using this. Unfortunately it is not standard and iiuc msvc has no equivalent?
dureuill··on Why should I have written ZeroMQ in C, not C++ (2012)
Exceptions are nothing like Rust's Result.

- exceptions don't appear in the signature of a function

- you don't have to handle exceptions explicitly, while you cannot access the value of a Result without explicit error handling

- Exceptions are implemented like Rust's panic. The error path in exception is more costly, while the nominal path is supposedly less so, due to less register and branch pressure than the result type that at least has a discriminant to check.

Exceptions are such a different way or handling errors from Result that my team finds itself reimplementing Result types in C++ again and again. Alas, it is neither standard nor ergonomic in C++

dureuill··on Using unwrap() in Rust is okay
You could go:

    result.unwrap_or_else(|| todo !())
(unimplemented! is for missing functionality in a given version, todo! is for missing functionality during development)

But using unwrap for these kinds of TODO is ok, code review won't let unjustified unwraps to pass

dureuill··on Using unwrap() in Rust is okay
not sure what you're referring to, but yes having a first iteration of code with unwrap here and there, and then a second one with proper error handling is a viable strategy. the "loudness" of unwrap makes it super easy to notice any leftover in code review
dureuill··on Using unwrap() in Rust is okay
not sure why you're getting downvoted. maybe the scope of what you're saying ('plenty of "production grade" crates unwrap [when they shouldn't]') calls for a reference? Or maybe because you're singling out Rust developers while the issue is certainly observed in all languages with similar mechanisms (see unchecked exceptions abuse in java, or aborting asserts abuse in C)

Anyway i wouldn't say "plenty", but i did came across crates (parsers :/) that would unwrap on malformed input. the workaround is to encapsulate their use in a catch_unwind.

for the record, i had a similar issue in a c++ lib where the author elected to abort on the unsupported input, so i'm somewhat thankful that the idiomatic mechanism is panic (which is recoverable if needs be) in Rust

dureuill··on Safety: A comparaison between Rust, C++ and Go
was not aware of crubit, so thanks for posting. i'm trying to follow closely what's happening in this space
dureuill··on Programming languages endorsed for server-side use at Meta
> C++ has a standard library and smart pointers that eliminate a lot of errors with dangling pointers, and if people use those exclusively

You can't use smart pointers exclusively, because there is no "smart observational pointer", and there cannot be one, because that would be a reference type checked by a borrow checker, which is exactly what rust uses.

You can emulate it with shared pointers, but then you're left with basically a reference counted language. Why not using swift at this point? Also this creates a semantic impedance mismatch that tends to manifest with cycles.

Source: walked a codebase that would (ab)use shared pointers

dureuill··on Performance comparison: counting words in Python, C/C++, Awk, Rust, and more
Programming language efficiency from a developer's standpoint is not measured in bytes written in the source code, because typing characters is never the bottleneck when writing code.

Even if it were, most code isn't "fire and forget", and so for most code the cost is dominated by maintenance cost, which has more to see with reading than writing code.

Languages that are concise are so because they either express information very densely, or express less information (via for example ignoring error handling or making it implicit with exceptions). In practice I find that such languages are much harder to maintain, because the missing information has to be rebuilt by the reader.

dureuill··on What is `Box<str>` and how is it different from `String` in Rust?
I mean another explanation is that GUIs take a tremendous amount of time and investment, especially in today's environment.

C++ was out in 1985, and qt's first version wasn't until 1995, with kde starting in 1997. And these were simpler times.

I'm very not convinced that lack of GUI is a rust specific problem

dureuill··on Building a Cloud Database from Scratch: Why We Moved from C++ to Rust
> Just my experience, YMMV.

Indeed. IME (around 10y C++, mostly c++14 and c++17, and 6y Rust), I measure x2-x3 velocity in Rust, a lot of which comes from the tooling, a part of which from ub-freedom and much easier and safer parallelism, and the rest from the expressive type system and functional polish.

This is for initial development. Factoring in the maintenance over the years I suspect it tends to an order of magnitude of difference.

dureuill··on “Should we give (Rust for Linux) a try for this coming merge window?”
I would not say that Rust is easy to use; rather, it is hard to misuse.

The guardrails make it harder to shoot the proverbial foot, but also to get code to compile at all.

Well, at least at the beginning. One becomes used to the so-called "compiler-driven development", at which point it becomes a breeze.

dureuill··on Our Experience Porting the YJIT Ruby Compiler to Rust
While I did not use C++20, I did follow its new feature set, and did not see anything able to address the issues of C++:

- no way to express "lifetime relationships", they remain in comments or force you to work around the problem by using copied objects or worse, shared pointers. This resulted in very real bugs in our code due to a library returning structs that had to live shorter than some other object, without it being clear from the name of the struct. Coincidentally, this same library has a rust implementation, where keeping instances of this struct for too long is a compiler error.

- no blessed way to express thread safety in the type system

- terrible build system without a blessed package manager, which is not about to change because:

- they are still headers everywhere. While modules are technically in C++20, tooling is not ready today (save for MSVC). The module implementation is also dubious in that it seems to cater to any niche use case in existence which adds a lot of complexity (and new opportunities for ODR violations...), instead of going "clean slate" and providing a simple system (preventing the split between declaration and definition and not being orthogonal to namespaces would have been a good start)

- no ergonomic sum types. Sum types are very important to model business logic and it is hard to go back to languages lacking them. There are discussions of pattern matching for C++ but it's not in C++20.

Several of these issues are impossible to fix in an existing language without breaking an unreasonable amount of existing code, so I don't see future versions of C++ reversing the statu quo. I also don't really trust the committee to achieve simple, ergonomic solutions, when I look to eg what was done with modules or coroutines (here I heard that the solution is to use third party libraries, but while it is tractable in Rust it is much less so in C++ due to the lack of satisfying tooling).

You're welcome to elaborate if you disagree though.

dureuill··on Our Experience Porting the YJIT Ruby Compiler to Rust
While true, I believe it doesn't significantly change the tradeoff between Rust and C++.

Also, nothing in the post lets us infer that the author doesn't know C++11 and later.

dureuill··on Our Experience Porting the YJIT Ruby Compiler to Rust
I find your remark strange: the author is mainly comparing the scalability of Rust vs C.

C++ does provide tools to build scalable software, and was already doing so in 1998 (few new features on this front since 98 I guess? Maybe modules, but using them for portable development in 2022 looks difficult given their state in compilers that aren't MSVC). I don't think this is a reason to prefer C++ over Rust (if anything, the tools for encapsulation and modularization provided by C++ are way less convenient and efficient than Rust's--speaking from experience of C++14 and Rust here). Also C++ has the massive drawbacks of lacking ADT, forcing headers on users (which is elaborated in the post I believe) and not offering a "safe mode" like Rust does (the tooling is also massively better, but somehow cargo felt like a hindrance to the author of that post, so there's that).

It did surprise me that the author wouldn't elaborate on why C++ was not chosen, when her argument made it look like it could provide some of the advantages she found in Rust. However, she doesn't *have to* elaborate on every possible subject in that post, and implying she doesn't know the language (anymore) because of her not focusing on the reasons she didn't use it looks like a dubious stretch.

dureuill··on Will Hare replace C? Or Rust? Or Zig? Or anything else?
i think the real mistake was to have "exclusive references" be called "mutable references" in the language. I've taken the habit of saying "mut" as "mutually exclusive" for references. Of course you can't have each Statement keep an exclusive reference to a db object. They're exclusive!

You need shared references for your DB, implying you need interior mutability. This is how Statements are implemented in real-world rust database drivers such as rusqlite (any operation on a db is done through a shared reference). The fact that a very real package is doing it proves that the pattern you're talking about is, in fact, possible.

dureuill··on Will Hare replace C? Or Rust? Or Zig? Or anything else?
a very narrow sense representing 70% of all security vulnerabilities at microsoft and google (self-reported). i'd say it's a class of vulnerabilities worth eliminating, especially when the "cost" is getting a competent and standard package manager and a general focus on correctness that ultimately increases developer productivity and ergonomics (compared with C++, IME)
dureuill··on Will Hare replace C? Or Rust? Or Zig? Or anything else?
exactly. if i'm writing safe rust and encounter memory safety issues, their origin is with my dependencies, and my responsibility is limited to having chosen such dependencies.

In practice, this makes vulnerabilities in eg. argument parsers (like the recent "baron samedit" vulnerability in sudo) incredibly unlikely.

dureuill··on Will Hare replace C? Or Rust? Or Zig? Or anything else?
The original filenames will be lost though, if they weren't utf-8.
dureuill··on Will Hare replace C? Or Rust? Or Zig? Or anything else?
thanks, i appreciate the detailed response. I do believe, though, that "least quirky", while definitively important, is not the most deciding factor here.

Axum is very young (was announced <1y ago), it has good momentum, is based on hyper and built by the tokio team. On the other hand, it has few actual projects built with it, I couldn't find a guide for it like actix or even Rocket have (it has some documentation in its docsrs documentation, but it is pretty minimal). Crucial questions like how to handle configuration, integration with database, autoreload, are left to the examples at best.

I have no doubt that these things will come if the framework matures. I'm just questioning if it should be the default choice right now, as opposed to in a year.

(Btw, I would absolutely recommend against Rocket right now, even though API wise it clicked the best with me, until it gets more maintainers and development resumes)

dureuill··on Will Hare replace C? Or Rust? Or Zig? Or anything else?
signs that things might not be that easy, i'd say that the answer is rather "actix-web". axum has tokio's momentum, but a much shorter track record than actix.
dureuill··on Lifetime Annotations for C++
Interesting! You're correct that it was not on my radar, don't really know why.

Looking at the repository, it looks like the output is a bunch of extern "C" functions, though. Does that mean that one must call eg destructors by hand? How are C++ exceptions handled? Is this sound in the presence of non-relocatable types (eg std::string)? If so, how? Also, this only handles the C++ -> Rust direction, right?

Anyway, thank you for letting me know of this project!

dureuill··on Lifetime Annotations for C++
This is where I stand right now, too. I recently published an overview of Rust <-> C++ interoperability[0], and cxx is the most effective tool available IME, but OTOH even cxx is not there yet (mainly missing bindings for Option and iterators). However the space, especially with autocxx, is evolving rapidly.

[0] https://blog.tetrane.com/2022/Rust-Cxx-interop.html

dureuill··on Lifetime Annotations for C++
note that IME, pyo3 was nowhere near as stable and reliable than pybind (or boost::python), at least at the time I last used it (2y ago? I remember soundness issues around inheritance, and I got a bona fide segfault without any unsafe). Their packaging tool, maturin, was already insanely good by then though.
dureuill··on EU negotiators agree new rules to rein in tech giants
This is not what I mean. I mean make it mandatory for these networks to allow interconnection with eg the fediverse, so that I can connect with people on Facebook or Twitter without having an account on these services myself. Currently users are captive to a network, not due to an impossibility to recover their data, but due to the fact that their friends are using that network and that network is not interoperable. Basically I think networks like Facebook and Twitter are so big at this point that they should be infrastructure.
dureuill··on EU negotiators agree new rules to rein in tech giants
i mean forcing the dominant networks to interoperate with the fediverse. i can open as many diaspora and mastodon accounts as i want, i will still be alone because everyone i know is on twitter and facebook. make it mandatory that facebook and twitter lets me connect my fediverse accounts and i can connect with my friends regardless of their network of choice
dureuill··on EU negotiators agree new rules to rein in tech giants
good news. we also need interoperability requirements for social networks. like twitter and facebook must be mandated by law to provide access to their networks to smaller networks. only then would people be free to leave these networks without suffering from "network effect"
dureuill··on Things I hate about Rust, redux
Or implied by the #[keep_calm] attribute
dureuill··on CXX – safe interop between Rust and C++
That attempts to provide it. I have been trying to use autocxx for a while, without success at the moment.

It is very actively developed though so I trust that we'll get there eventually.

← PreviousPage 5 of 7Next →