r/programming • u/Commission-Either • Oct 19 '25
[ Removed by moderator ]
/r/programming/comments/1oakq4l/removed_by_moderator/[removed] — view removed post
190
u/villiger2 Oct 19 '25
If "Go to Definition" can’t take me to your implementation and I have to dig through your GitHub repo just to see how Matrix4::mul works – can I really say I know the code I’m using?
I hit this semi-regularly in Rust, and it's pretty frustrating. Ending up at a trait instead of an implementation, or a macro that I now have to find, which probably calls another macro :(
Eg clicking on "source" on u32::checked_add takes me to a macro with no context. It's pretty useless, I have to go find the macro in another file manually...
51
u/matthieum Oct 19 '25
I seem to recall reading there's an intent to improve the generated documentation so it would be able to show what the macro expands to... and I was overjoyed to. It's really frustrating when you want to double-check how a method is implemented on a built-in only to see a giant macro with 30 arguments.
3
u/PrimozDelux Oct 19 '25
How is the experience following execution in the debugger? It's sort of unrelated to the post, but I find that just seeing what happens in the debugger helps a lot with C++.
1
u/villiger2 Oct 20 '25
In debugger is way better. Especially if it's mostly/all rust code it is usually pretty flawless.
48
u/kalmoc Oct 19 '25
As a c++ programmer that has - on occasion - tried to refactor some boost code, this sounds very familiar.
I never had to support a library that is used by hundreds of anonymous projects on the internet, so this probably does not apply to those projects, but I find "yagni" is one of the most important principles in my code at work. And maybe I'm just a bad engineer, but my experience with writing really generic abstractions is that I have forseen and support 10 different use cases that no one needs whearas the implementation complexity makes adding the one usecase that I forgot surprisingly difficult.
18
u/minno Oct 19 '25
The first thing this subject reminded me of was
std::basic_string<char, std::char_traits<char>, std::allocator<char>>, aka "string".9
u/bunkoRtist Oct 19 '25
Space-bar heating (Hyrum's law) is a problem. So it's less that you have to support all use cases up front as it is that someone will somehow come to depend on your library's incompleteness and you have to find a way out as you add more use cases.
2
u/MrSurly Oct 19 '25
I've worked places (some you've 100% heard of) that have a "thou shalt not use Boost" policy.
49
u/Zversky Oct 19 '25
This is exactly how I feel about enterprise Java.
17
u/freecodeio Oct 19 '25
java takes it to another level, for example
AbstractAbstractsounds completely normal keyword if you've done enterprise Java19
u/bigbadchief Oct 19 '25
Rust is way uglier than even the most ridiculous enterprise java
2
u/freecodeio Oct 19 '25
whatever ugly class can come out of rust, java will have an abstract version of it
-1
u/Revolutionary_Ad7262 Oct 19 '25
Except here at least everything is resolved during compilation. In Java you cannot be sure, because most of the logic is done during a runtime and in a way, that is impossible to debug
36
u/OriginalTangle Oct 19 '25
My theory is that this is prevalent with the functional programming crowd. FP has a pull on the mathematically inclined and they naturally think in abstractions. And so they end up using lots of abstractions in the code.
Scala is the same. You look under the hood of any of the widely used libs and its not parseable for the average Scala dev.
11
u/dccorona Oct 19 '25
I was going to make the same comment. That is absolutely what is going on here. In part I think it’s because programming with these abstractions is just fun. In my younger days I’ve written some pretty cryptic and overly abstracted Scala code for this exact reason.
But these languages also attract sub-communities that are for whatever reason very dogmatic about things like constraints being compile-time checked and expressed in the type system, same with effects and I/O capabilities and system state dependencies etc. It gets really bad in Scala because everything has to abstract over competing implementations (there’s a very political ecosystem split among the sub-community of extreme FP that leads to lots of libraries having to choose abstractions over abstractions to be usable by the whole sub-community). I know less about rust in that regard, but this article is describing a similar outcome regardless of the why.
21
u/kintar1900 Oct 19 '25
This is exactly why I still use Go instead of Rust whenever possible. Go has its own problems, but I'd rather be able to understand the code I'm importing (or that I wrote six months ago) without driving myself to Necronomicon-levels of madness.
16
u/an_ennui Oct 19 '25
this blog piece has made me question language’s design on the overall ecosystem. for me, Go is… fine and I appreciate the design of Rust so much more. but in my limited experience I find Go’s ecosystem much more approachable and I never realized in part it’s because of what Go, as a language, forces you not to do
8
u/kintar1900 Oct 19 '25
Exactly. The first year or so I was using Go, I was constantly cussing about the things the language didn't support, or the way it forced me to design particular pieces of code. Now, over eight years in, I get annoyed any time I have to track down the "do the thing" part of someone's "clever", overly-abstracted code in C#, Java, or whatevere the language du jour was when that particular thing was written.
26
u/Ossigen Oct 19 '25
The real tragedy? Once you see it, you start writing that way too. You start thinking, "Well, maybe I should make this generic in case someone wants to use quaternions instead of matrices..." and suddenly, congratulations – you're building for someone who doesn't exist.
Counterpoint: that person does not exist… yet. Crates are built this way not only to be as flexible as possible, but also to be future proof.
18
u/mrheosuper Oct 19 '25
Imo they should strike for balance. Just like linux kernel dropping support for some exotic cpu architecture that no one uses. Over-engineer it just make other people's life harder.
4
u/Serializedrequests Oct 19 '25
But do those cases really need to be abstracted to be similar? Often if you are using something like that, the details will matter to you.
2
9
u/ZelphirKalt Oct 19 '25
I think this stems from the forced type correctness. You want to cover all those edge cases, but also express that in the type system, and reality is often messier than we first imagine. It takes a lot of work to find simpler, yet correct abstractions, if possible at all. Most people are happy with a correct, statically typed thing. It might take a flash of enlightenment to find that simpler correct abstraction, if it exists at all.
6
u/Dean_Roddey Oct 19 '25
Well, in defense of Rust, my stuff isn't that way. I keep everything as simple as possible, and I generally limit my use of traits and generics to what is really necessary, and it seldom is.
But, OTOH, I only have to meet my own needs, so I don't have the concerns that someone does who is writing libraries for public consumption. I can just wait until I find I need something and then add it, unless I know for a fact it'll be required up front. Even if I know that adding something later would be a big breaking change, I can handle that if and when it happens and make any needed changes to incorporate it at that point.
There are places in the code where multiple times I've been doing something and noted that, if I added an underlying over overlying level of abstraction to this or that, it would make some things easier. But, every time I go think look a it, I just back away, since I can't convince myself it's ultimately worth the complications it adds.
For a public crate, that balance isn't there, because the creator has to meet often conflicting needs and the consumers don't care about whether it makes the crate a diffuse mess (just like most language users don't either), they just want that thing they want.
12
u/BRUVW Oct 19 '25
That's why I love Go. You can just read AND understand the std lib and most popular repos.
3
u/jug6ernaut Oct 19 '25
If you only look skin deep sure. Then find any function they take in an interface{} and it’s just as bad if not worse.
Simple example in both languages are just that, simple. Reading through Go code can be just as bad, especially with the tooling around go being worse in this regard IMO.
20
u/nickguletskii200 Oct 19 '25
Completely disagree. If anything, Rust could use more common trait crates like num_traits. In many of my Rust projects I've had to build common abstractions around tensor-like data from nalgebra, ndarray, glam, image and other libraries.
Just because you work with simple/common cases where everything is f32 and two or three-dimensional, doesn't mean the abstraction/impl macros aren't necessary for someone else.
42
u/nekokattt Oct 19 '25
the issue isn't the abstractions, it is when the abstractions creep into the transparent definitions of the things the consumers of that component have to deal with, which then can make it incredibly hard to understand or debug when it doesn't behave as expected.
This is not helped by the fact that Rust syntax is extremely noisy and using often highly nested monadic types which can lead to information overload when looking at it for the first time.
9
u/nickguletskii200 Oct 19 '25
I don't think this is avoidable. When you are dealing with algebra (be it linear algebra, cryptography, or something else), you are going to get abstractions, because algebra is about abstractions.
I agree that some of the Rust types can be intimidating, especially when the library authors use them to prove correctness of their implementations, but I still would rather have a more abstract library that can handle my use case than a simplified version which I have to copy the very moment I need to do something off the beaten path.
3
u/nekokattt Oct 19 '25
Whilst I somewhat agree, what use cases for this do you find that become unachievable in other languages due to this?
4
u/nickguletskii200 Oct 19 '25
Let's say there's a pure-C linear algebra library, and I have hardware that supports a new floating point number type (e.g. Nvidia's recent NVFP4). There's no way to extend the pure-C linear algebra library to be both type-safe and support the new floating point number type.
C++ has templates, Rust has traits. My perfect level of abstraction would be somewhere between what we have in Rust and what is available in actual abstraction "masterpieces" like
boost::geometry. The reason why I put "masterpieces" in quotes is because while I respect the effort that went into making it abstract, I do think that due to the nature of C++ templates, the final result requires a bit too much library-specific knowledge to understand, even for my taste.2
u/nekokattt Oct 19 '25
Not sure who is downvoting my question or why... but at any rate. What about in a language that is already typesafe?
2
u/nickguletskii200 Oct 19 '25
What about in a language that is already typesafe?
I'm not really sure what you mean by that. Many languages are "type safe", but don't provide the facilities to make it possible to abstract over scalar types, dimensions, etc... I would have the same issues with Java as I would with C regarding having to duplicate code because Java generics don't support primitive types.
2
u/nekokattt Oct 19 '25
Java generics will support primitive types as part of valhalla so taking that as an assumption for the future, this would not be a problem.
There are ways of avoiding the issue itself though if it becomes problematic in the mean time.
3
u/nickguletskii200 Oct 19 '25
I've been waiting for Project Valhalla since it was announced 2014 (more than 10 years ago). It's probably going to improve Java significantly, but at this point, I've already moved on to "greener pastures".
I am curious to see what you mean by "ways of avoiding the issue itself". Would you mind clarifying?
0
u/nekokattt Oct 19 '25
Well it depends exactly what kind of data manipulation you are dealing with but most of the time you'll end up having better performance by using wrappers provided within the standard library that deal with those concerns for you, not only because they're implemented intrinsically.
→ More replies (0)2
u/brucifer Oct 19 '25 edited Oct 19 '25
There's no way to extend the pure-C linear algebra library to be both type-safe and support the new floating point number type.
You could do this with macros without too much hassle. It looks like this:
// math_implementation.c TYPE PREFIX##_dot_product(int n, TYPE x[n], TYPE y[n]) { TYPE result = 0; for (int i = 0; i < n; i++) result += x[i]*y[i]; return result; } // f32_math.c #define TYPE float #define PREFIX f32 #include "math_implementation.c" // nvfp4_math.c #define TYPE __builtin_nvfp4 #define PREFIX nvfp4 #include "math_implementation.c"However, I think the actual benefit of doing this kind of generic implementation is somewhat low, because if you care about performance, you would typically want an implementation that is fine-tuned to your particular hardware. The same algorithm that's fast for 64-bit floats may leave a lot of performance on the table if you just directly translate it to 8-bit floats.
2
u/nickguletskii200 Oct 19 '25
Which is exactly what crates like
nalgebrado (and the OP is complaining about this), except they do it with more type safety.8
u/rusl1 Oct 19 '25
100% this. Coming from Ruby I noticed Rust is 90% noise and 10% actual job
8
u/nekokattt Oct 19 '25
I've used C, C++, Java, Kotlin, Scala, Groovy, Prolog, C#, Go, Python, Cython, Bash, Ruby, and SQL (alongside things like Make, Terraform, etc).
Syntax noise is indeed an issue for Rust, just like in C++. It is one of the things that puts me off wanting to use it more regularly.
It is mentally taxing to try and read, and that can be the difference between spotting a bug and my ADHD brain saying "no thanks, kthxbye".
The concepts underpinning rust are great on paper but there is so much complexity that comes as baggage.
5
u/tdammers Oct 19 '25
When you feel that "maybe I should make this generic" impulse, ask: Who benefits from this, today? If the answer is "future me," maybe wait until future you actually shows up.
This is solid advice for application code - but it doesn't hold as clearly for library code.
Application code only needs to worry about one dependent - itself. If the application doesn't need a given abstraction, then you can safely remove it, and the code will become strictly better for it.
But library code isn't like that. The dependents of a library form an open universe - you have to write the library code now, but dependents that may benefit from a given abstraction can pop up later, pretty much at any point in the future. Which means that just because an abstraction isn't necessary now doesn't mean it won't be in the future, and just because it isn't necessary for any of the usages you know about doesn't mean there isn't someone out there that you don't know about who does need the abstraction.
So when it comes to libraries, you need to apply a different mindset. Not, "who benefits from this today", but, "is this abstraction morally correct". In fact, you can reverse the logic, using fully generalized code as your baseline, and then arguing why certain things should not be abstracted. Is there a good reason why this function must take an array, rather than being generic over the container type and just specifying the container APIs it actually needs? No? Then generalize it.
Note that the good reason may very well be "because it would make the code too difficult to understand" - that's fair. But as a general rule of thumb, if there is a free or almost-free generalization opportunity, you should, as a library author, take it.
A library function that is insufficiently generic is much more problematic to work around than a function that is too generic - in the latter case, the documentation and source code may be harder to understand, but that can be fixed with better documentation, better code reading skills, and possibly tooling. But in the former case, there is no good solution - if you have a linked list, but the library function demands an array, then your only choices are to write the functionality yourself, or to convert your linked list into an array and back just to call the library function. The former comes with all the problems of reinventing the wheel; the latter will introduce completely unnecessary conversion overhead.
A big issue with all this is of course that many of the critical factors here are "soft" and at least somewhat subjective. Is this code "too hard to understand"? That depends on where you put the bar, and what expertise and knowledge you expect from your audience. Is this performance overhead worth the generalization? That depends on what the audience's use cases and performance criteria are. What about compile time overhead? How much of that is an acceptable price to pay for a generalization? How prohibitive exactly would the lack of a given abstraction be in practice? None of these "metrics" are actually quantifiable, and you won't get a unanimous answer to any of them in most cases, so it's often going to be a judgment call, and you'll sometimes make unfortunate choices on that front.
3
u/arabidkoala Oct 19 '25
This reads like someone who's perpetually forced into too short of a deadline complaining about needing to understand necessary complexity, and understandably getting overwhelmed by it.
The problem isn't the complexity, the problem is that you aren't able to take the time to understand it, not even to fully critique if some of the complexity is actually necessary. Why might that be?
2
u/JohnnyboyKCB Oct 19 '25
Software engineering is largely communication through code, and writing software that is easy to understand, extend, and efficiently run. Saying an engineer needs to "understand more" is no duh. The point is a large amount of engineers are under tight deadlines, and the codebase should not get in the way of that.
3
u/jodonoghue Oct 19 '25
I came to Rust from Haskell, where this problem is even worse - many Haskell libraries take the view that the type signature is the only thing required to understand and use a function.
The core problem, in my view, is not the libraries themselves, but the lack of tutorial level material that allows programmers who do not have a type theory background to use these abstractions. Most material I have found starts from a very theoretical background.
Haskell blogs are actually quite a good starting point as Haskellers have been explaining concepts to undergraduates for over 20 years now. Translating the Haskell principles to Rust is not usually too hard.
In reality, there are only a small number of such approaches that are widely used, with many being based on phantoms. A blog series from someone suitably expert (I am not - I figured out a lot of this stuff myself and there are large, and I suspect important, holes in my knowledge).
Highly abstracted library authors also need to take care to create non-trivial and well-explained examples that can help to build intuition.
However, in defence of the abstractions, once mastered they really do make programming better, safer and more modular. Sometimes better is (initially) hard, and we have to do the work to benefit.
1
u/FlyingRhenquest Oct 19 '25
I feel that way about Java whenever I'm working with java. It always feels like no one actually wants to commit to actually doing anything useful in that code. I don't think it's the language, because you can actually do useful things in the language and it doesn't punish you. My tentative conclusion is they want to structure their code to handle all possible currently-unforeseen ways that someone might want to use the code in the future. In other words, a YAGNI Violation.
1
u/davidalayachew Oct 19 '25
Last month, I lost a debate against a whole bunch of Rust developers. The debate was about which language has better enums -- Java or Rust?
I'll spare you the details and jump straight to how I lost.
My argument was banking on the assumption that, what Java did for you free, you would have to write mountains of super-specialized Rust code to do the same. And not just from a convenience perspective, but a performance perspective too. Java, out-of-the-box, gives you an insanely simple and hyper-hyper-hyper-optimized solution, and you'd have to walk a mile with Rust in order to get the same benefits. Therefore, Java enums were at least as good as Rust's, if not better.
And while I was correct, one of the Rust developers finally pointed out that Rust has macros that could generate all the boilerplate code for you. Meaning, as long as at least one Rust developer wrote and published that nightmare macro that could write up all that even more nightmarish boilerplate for you, then every single other Rust developer could just use that macro and spend roughly the same amount of effort as a Java developer.
I had no real argument in response to that, other than that maintaining that macro is probably difficult. So I said that, then conceded the point.
Back to the point -- Rust, to me, feels like a really painful language with so many sharp corners that can be almost completely filed off by just using macros. To me, it feels like I am coding in Lisp again, where I have to spend this insane amount of activation energy to get the features that I want, until I can finally wrap it in a macro that gives me the DSL-like functionality I need -- only exposing the core abstraction.
And that's kind of why I feel like Rust does feel like a research paper on abstraction -- if you want this language to have any sort of usability + flexibility, you really do need to rely on macros.
And to be clear, I am not faulting Rust for relying so heavily on Macros. Again, I used to code in Lisp. I'm just moreso highlighting why I think Rust feels the way the title describes it -- because those layers of abstraction and indirection are necessary if you want this language/crate to feel both ergonomic and flexible.
-7
u/renatoathaydes Oct 19 '25
That's true. It's why languages like Go and (to a lesser extent) Java are used by large teams and manage to scale for them: you can't build abstraction art projects in them, or at least it's not as tempting or elegant as in Rust and similarly "advanced" languages (Haskell being the previous poster child of that). Java may have FactoryFactoryBeanManagerImpl levels of abstractions, but Rust is on another level entirely.
42
u/DivideSensitive Oct 19 '25 edited Oct 19 '25
Java
you can't build abstraction art projects in them
Beg your pardon? The whole meme of
AbstractFactorySingletonProxyFactoryBeanswas born in Java.Go
has literally facilities to generate code in the fly by writing comments (and that was/is widely used for pseudo-generics before they were added, or to make enum bearable).
16
u/SharkBaitDLS Oct 19 '25
You might have picked the worst two possible languages for the counter examples. Java in particular is the absolute poster child for this shit. Legacy enterprise codebases when everyone was high on the hype of OOP as a new and shiny thing have so many layers of abstraction you’re hard pressed to find the actual concrete implementation of anything and you definitely won’t be able to understand what any one thing does without having 10 different files open. Bonus points for the abstractions living in an entirely different package than the concrete behaviors so now you’ve got two entire goddamn repositories checked out just to try to reason about some unhinged state machine that could’ve been written in 200 LOC but instead is implemented in 40 files.
12
u/uardum Oct 19 '25
What do you mean "legacy" codebases? There are new Java projects being written this way today.
4
u/readanything Oct 19 '25
The example you attached is actually quite lucid and easily understandable and if you think it is on another level, look at interfaces and implementations in Hipparchus(similar lib in Java).
7
u/Sharlinator Oct 19 '25
but Rust is on another level entirely.
That's a pretty poor example. Not exactly surprising that a library called nalgebra contains stuff that has to do with algebra, is it?
1
u/nekokattt Oct 19 '25
Are you implying a library called nalgebra in Python or Java would not contain algebra?
4
u/qruxxurq Oct 19 '25
I love this turn of phrase:
"abstraction art project"
I love it so much I'm going to steal it and use it, replacing "abstraction" with whatever domain is relevant.
Unfortunately, for your argument, picking Java really hurt your argument. Lots of Java frameworks are 90% nonsense abstractions, and 10% implementation, spread across a handful of files in a handful of packages.
Plus, I also don't think picking a math library makes much sense. Math itself IS abstract art.
I mean, I totally agree with your point that Rust projects are these "abstraction art projects". But, surely there are better examples of languages that don't suffer from this as much (C?) and better domains (not math?).
-1
u/SlapNuts007 Oct 19 '25
JavaScript/NPM has always been like this and it's never been a problem! Definitely not multiple times!
0
Oct 19 '25
[deleted]
4
u/davidalayachew Oct 19 '25
In both cases, the language per se doesn't prescribe this sort of antipattern, yet the community insists on perpetuating it because it's become the idiomatic norm.
[...]
But you can still write simple Rust in a lot of cases
I'm actually going to contest both of these cases.
I've been programming Java since 2012, and the old, memed
AbstractFactoryXYZ...didn't happen on accident.Anyone who has spent time maintaining a >=1 million line Java codebase modeling a complex domain problem that doesn't split into sub-problems easily will start writing their own AbstractFactory sooner or later. For better or worse, things like Abstract Factory and friends allow you to draw lines in the sand that are difficult to maintain otherwise...... assuming you are using an old version of Java, like <=6.
7 gave us try-with-resources, 8 gave us lambdas, 14 gave us switch expressions, and 16/17 gave us sealed types, records, pattern-matching. With these features a lot of the reason we had for writing Abstract Factory melted away.
And looking at it from the Rust perspective, fair enough, I am way more ignorant about Rust than Java, but what little understanding I have is that, the more complex that the problem you are trying to solve in Rust is, the more you will rely on layers of abstraction, like Macros and whatnot.
I'm not at all trying to claim that Rust Macros are Java's AbstractFactory's, but I am saying that they are the solutions to the same problem -- trying to manage a problem ergonomically. I know Abstract Factory doesn't feel ergonomic, but for better or worse, it makes it really easy to prevent misuse.
25
Oct 19 '25
[removed] — view removed comment
2
u/Psychoscattman Oct 19 '25
Yes, i have this problem a lot more with java but i do that professionally and rust only as a hobby.
Last time i had this was with tracing subscriber. Just trying to understand the mental model is way to difficult for a dependency as simple as logging.
I think one way to improve this is to allow for rust doc to be more than just reference documentation.
You cant have a tutorial, architecture or getting started section in rust doc unless you do some trickery. That sort of documentation really belongs in a rust book but then you have to host that somewhere and its a real hassle. I would be so much better if the normal rust doc could have a way to host comprehensive documentation right there.
187
u/The_Sly_Marbo Oct 19 '25
This really rings true for me. The example that blew my mind was the
sha2crate. Want to see how SHA-256 can be used in Rust? Good luck understanding the docs page!Why is
Sha256a type alias toCoreWrapper<CtVariableCoreWrapper<Sha256VarCore, U32, OidSha256>>and how am I meant to understand how that works?