|
|
Log in / Subscribe / Register

Code Review

Code Review

Posted Nov 14, 2025 11:02 UTC (Fri) by bredelings (subscriber, #53082)
In reply to: Code Review by Vorpal
Parent article: Rust in Android: move fast and fix things (Google Security Blog)

> That would certainly mirror my own subjective experience of coding in Rust: once I get the compiler to accept my code (which takes longer than in C++ sometimes), it usually works correctly on the first try, or only has some trivial logic bug ("oops, I forgot to actually write out the result to a file").
>
> My educated guess as to why this is, is that some of the non-memory safety features of Rust help: in particular sum types and linear types (well, affine types really).

Yes, people say the same thing about Haskell -- once you fix all the compile errors it often works the first time. And Rust and Haskell have very similar type systems.


to post comments

Code Review

Posted Nov 14, 2025 16:38 UTC (Fri) by develop7 (guest, #75021) [Link] (8 responses)

This is precisely my first ever Haskell open-source contribution experience: locate where and what to change (with grep), change stuff the way you need it to be, address all the compilation errors, get a working binary, see it works flawlessly first time, submit a PR, prepare for major refactoring suggestions, get accepted after minor changes, mind blown because it was never a thing in my 15 previous years in software development.

7 years later, it works that way in ~80% of cases, way more often than it ever was with mainstream.

Code Review

Posted Nov 14, 2025 18:43 UTC (Fri) by Vorpal (guest, #136011) [Link] (7 responses)

Interesting. I dabbled in Haskell many years ago, but I lost interest somewhere between monads and applicative functors (I think that was the name). Haskell was too much abstract math for me.

Pure math is not my thing. I'm far more towards the applied side of things, if I can't see a concrete use case for it, my eyes glaze over.

Rust hits that sweet spot: built on fancy math, but unless you are literally working on the compiler itself you don't need to engage with the theory behind it.

Code Review

Posted Nov 14, 2025 19:22 UTC (Fri) by tialaramex (subscriber, #21167) [Link] (2 responses)

Even inside the compiler, only a relatively small portion needs you to understand any deep theory of program transformation. A lot of the Rust compiler is either turning a correct Rust program text into abstract syntax, or diagnosing some mistake which rendered your input not a correct Rust program in the way most likely to result in you going:

"Oh! Yeah, that's wrong, I will fix it"

and rarely that you say instead:

"Stupid compiler. It's not wrong, either shut up and accept what I wrote or explain clearly the problem"

I had a Rust diagnostic that I felt was less helpful than it should be. I grep'd the error text, found a constant with that text as its definition (this is all memory so details may be wrong) and then found that constant used only once, at the site emitting the diagnostic text. I read surrounding code and intuited how to write a better diagnostic, and yeah, first time it compiled it actually worked - as I got more familiar with the surrounding code I actually added some useful extra stuff until I was happy that anyone seeing this diagnostic was getting the best I could give them. One thing I realized part way through is that we're not on the happy path - nobody is ever going to curse that my diagnosis code is inefficient, because their program is wrong, and I'm telling them why, if the program wasn't wrong my code never runs at all. From "How hard can it be?" to a (nightly) release with my fix took less than one week. Rustc's reviewer was very helpful in shepherding me through and identifying anywhere my change did need small improvements to hit their quality goals.

Non-technical advantages of rustc

Posted Nov 15, 2025 10:37 UTC (Sat) by farnz (subscriber, #17727) [Link] (1 responses)

Your comment about improving a diagnostic brings up one thing that the rustc project gets right, and that helps Rust's adoption; diagnostics (both lints and failures) are continuously being improved, and the people behind the compiler are supportive of efforts to make the diagnostics better.

This sort of work isn't always seen as valuable - after all, an error like "problem in type unification: cannot meet constraints for arg, arg is parameterized type T, T is required to implement Debug + Send + Sync, but supplied value param has type MyParamType, which implements Display + Send + Sync + Unpin + RefUnwindSafe + UnwindSafe" contains all the information you could possibly need to diagnose the bug, but "param is of type MyParamType, which does not implement Debug, which is required in funct(param) by fn funct<T: Debug>(arg: T)" is so much more helpful to the user, even though it has strictly less information than the first form.

Non-technical advantages of rustc

Posted Nov 16, 2025 2:37 UTC (Sun) by tialaramex (subscriber, #21167) [Link]

AIUI One of the things which consciously drove that, and which is as often a source of conflict on LWN as the claims of improved correctness, is Rust's tag line: "A language empowering everyone to build reliable and efficient software"

Because we're not "empowering everyone" if we've made it easy for you to attend our conference but practically impossible to understand our compiler warnings.

Seeing this tag line from other angles also encourages other technical changes, for example Rust often goes out of its way to have the obvious thing you'd write be efficient rather than try to teach Rust programmers to write something else that is already efficient - for beginners this means it's more likely that the Rust program you wrote, though perhaps not very sophisticated, has excellent performance anyway, but even for experienced Rust programmers it means often you don't need to figure out a clever way to write what you meant efficiently, the obvious way to write it is optimised anyway.

Code Review

Posted Nov 15, 2025 15:04 UTC (Sat) by develop7 (guest, #75021) [Link] (2 responses)

> I lost interest somewhere between monads and applicative functors (I think that was the name). Haskell was too much abstract math for me.

I've been there too! But that time I've decided to try skipping things that don't click yet and just "fix the darn thing" instead and that worked way, way better than I've expected. That's what I call programming in an _actually_ high-level programming language.

Monads-wise, here's a simple explanation why we _all_ need them: https://philipnilsson.github.io/Badness10k/escaping-hell-...

> Pure math is not my thing. I'm far more towards the applied side of things, if I can't see a concrete use case for it, my eyes glaze over.

Makes two of us, but Haskell is not about pure math — our monads are more like a pattern, typechecked by a compiler. If anything it is most down-to-earth lazy functional programming language.

Code Review

Posted Nov 17, 2025 8:55 UTC (Mon) by taladar (subscriber, #68407) [Link] (1 responses)

The biggest thing that I took away from using Haskell for a few years is that abstract code is actually a lot simpler to reason about than code with concrete types.

That is because abstract code makes it explicit which operations you are allowed to perform on the values you operate on which means this set is much, much more constrained than the operations you could perform on any given concrete type. In particular the absence of a way to create arbitrary new values of a type usually makes reasoning a lot easier because every value of the type you return must originate with a value you pass into the code.

Code Review

Posted Dec 13, 2025 9:20 UTC (Sat) by Chousuke (subscriber, #54562) [Link]

That's actually mathematically provable, to a point. The more abstract a (pure) function type is, the fewer possible implementations it has.

For the simplest example, there's only one function with the type a -> a.

Code Review

Posted Nov 19, 2025 19:59 UTC (Wed) by donbarry (guest, #10485) [Link]

From Edsger Dijkstra's "How do we tell truths that might hurt?" list of programming truths:

"Programming is one of the most difficult branches of applied mathematics; the poorer mathematicians had better remain pure mathematicians."


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds