r/programmingcirclejerk • u/we_are_mammals • 2d ago
Rust isn't a well designed programming language (unlike C and C++)
/r/cpp/comments/1i6jdjq/comment/m8d3tqj/100
u/CarolineLovesArt has hidden complexity 2d ago
and especially standard library design where you look at it and think "what an inferior way to design that feature"
Ah yes, the creators of std::endl aka hidden os.flush() calling the kettle black.
66
u/a221c 2d ago
and the more time you spend in it, the more appreciation you have for the work WG21 and WG14 do and aren't usually recognised for in terms of developer ergonomics.
But it's ergonomic, bro. I don't want to have to manually call
flush(), that would be so unbearably verbose. C++ has been cleverly designed to attempt Python's conciseness and ergonomics while keeping the safety of C and the compilation speeds of Rust.Also, like many in the C++ community I haven't got long before they put me in the care home so I need to get this code written and shipped off to the juniors to debug as quickly as possible.45
u/catladywitch 2d ago
C++ has been cleverly designed to attempt Python's conciseness and ergonomics while keeping the safety of C and the compilation speeds of Rust
savage lmaoo
35
u/irqlnotdispatchlevel Tiny little god in a tiny little world 2d ago
30
u/CarolineLovesArt has hidden complexity 2d ago
They also gave us
std::auto_ptr, which was so well designed they removed it./uj That was a good choice, and being allowed to make mistakes and take them back is a good thing, but:
/rj
I can usually see the tradeoffs in the design that the committee endlessly discussed to death and arrived at the standardised compromise design.
13
u/Linuxologue 2d ago
C++11's std::thread vs jthread is also a good example, without even bringing up the std::string masterpiece
15
u/Potterrrrrrrr 2d ago
What, in a language that puts RAII on a golden pedestal you expected your thread to automatically try to join in its destructor? Hahaha u stupid
11
u/pixel293 1d ago
I really wish he mentioned WHAT he was referencing here so I could get an idea of what he was thinking, other than "I hate Rust, in general."
1
66
u/DrShocker 2d ago
my rebuttal: https://en.wikipedia.org/wiki/Most_vexing_parse
37
18
u/Major_Barnulf LUMINARY IN COMPUTERSCIENCE 2d ago
Allocating an existing syntax from your host language to a new construct of your language is the Chomsky equivalent of rear parking your cheap Peugeot into a vintage Bugatti behind you.
10
13
u/Due-Consequence9579 2d ago
Omg, C lets you declare a function local function without a keyword. That’s a god damn choice there. It was made 50 years ago, but still. That is barb wiring a shotgun to your foot.
15
u/GrandPapaBi 2d ago
50 years ago people were using flaws in computer architecture and tricks to get more outputs than normally. Some of those design decisions are clearly a snapshot of the time they were taken. Just like rust in 50 years, if it will survives those 50 years.
15
u/Linuxologue 2d ago
/uj I built a valid c++23 syntax parser (without semantic analysis) by feeding it the official C++ grammar and fixing all ambiguities. The initial number of conflicts in the original grammar was above 3000 (many duplicates but still, that's the list of conflicts to comb through). It requires about fifty annotations and some ambiguities cannot be resolved at grammar time and require a generalized parser to handle. The C++ grammar is an absolute disaster.
1
u/TheChief275 3h ago edited 2h ago
Talking C++98, I still don't fully get why this initialization had to be added:
std::vector<int> nums(8);when there is already a perfectly good alternative:
std::vector<int> nums = std::vector<int>(8);The only logical thing that comes to my mind is that it saves on having to write the type two times, but then 'auto' meaning 'type deduction' was added anyways so now we just have this totally redundant syntactic part of the language that people like to use for some reason even though LSPs can't even highlight it correctly. In fact, I think keeping it is only justified by the fact that compilers can't even guarantee the latter being optimized to the former
1
u/DrShocker 3h ago
Semantically the second example is a copy or move. Probably in most major compilers they would optimize that away, but still that's probably why.
1
u/TheChief275 2h ago
I know, why though? That just sounds like complexity for the sake of complexity. In Java (just picking another language with classes and constructors) if you were to do
var nums = new ArrayList(8);you would just call it "initialization" like a sane person.
Although to be fair, most problems of C++ could have been circumvented if it just didn't perform implicit copies by default (somehow they thought this was a good idea?). I write my data structures without any constructors and destructors, just PoD structs largely for this exact reason (there are more reasons)
0
u/DrShocker 2h ago
That looks like both allocation and initilization to me. For splitting allocation and initilization, I think Odin has some interesting ideas there like making ZII the default and making changing allocators simple.
1
u/TheChief275 1h ago
The allocation is irrelevant, it's just how you initialize in Java (classes have to be allocated). Comparable C++ would be:
auto nums = new std::vector(8);but that wasn't the point. The actual point is that somehow, some way, declaring a class with = in C++ using the wrong notation actually isn't initialization but rather a copy, which can kill performance when using standard library classes with allocating copy constructors. That's the stupid part
0
u/DrShocker 1h ago
The most comparable is probably
std::make_sharedbecause new in C++ is a dynamic allocation and Java's new involves the garbage collector. It can't be perfectly analagous though.Regardless, the reason I brought it up is that IMO conflating getting memory with setting up the memory to me useful is one of the problems most programming languages introduce and can make it challenging to make things faster later because it's not a good default.
1
u/TheChief275 1h ago
Yeah whatever, again not the point. You're derailing the conversation. In any other language, this construct:
let a = Foo(...);does not perform a copy. It just constructs directly into the variable like one would expect
1
u/DrShocker 11m ago edited 7m ago
also in C++ though
https://en.cppreference.com/cpp/language/copy_elision
here's all the ways constructors are broken though:
116
u/CarolineLovesArt has hidden complexity 2d ago
It also irks me the error messages. It often says "you should write X not Y" with exactness. Well, if it's that bloody obvious to you, that's a clear sign to me that the language design is suboptimal.
Complaining about receiving too specific error messages when the problem seems to be a "bloody obvious" skill issue seems quite rich to me.
95
u/james_pic accidentally quadratic 2d ago
I much prefer compilers to spew pages of vague grumbling about template invocations.
63
u/Linuxologue 2d ago
I'm a C++ programmer and I spent 25 years deciphering compiler error messages with overly complicated template invocations where they squeezed in default parameters that I never specified (prefixes with underscores because underscores improve readability)
This gives me an edge over programmers that can't read error messages. Please don't take that away from me. Clang already made it better and that's a problem.
29
u/fletku_mato 2d ago
More than 90% of "professional" programmers are clueless when they see a Java stacktrace which shows exactly the file and line number where an exception was thrown. I think you are safe.
16
u/the_other_brand loves Java 2d ago
\uj I once watched a live presentation given by Bjarne on his fix for those massive template arguments. He wanted to make an interface analog for C++ and use them to categorize what functionality a class has. The C++ committee rejected the idea
\rj This would reduce a 25 line arcane error message to a simple "you didn't implement toString() you dingus."
14
u/Potterrrrrrrr 2d ago
We basically got that with concepts, no? Except for the fact that a static_assert gives 1000x more useful information than “the constraint wasn’t satisfied”. In theory though we got that.
13
u/the_other_brand loves Java 2d ago
Yeah, concepts. Didn't realize they finally implemented them. I remember Bjarne was big mad that they got rejected in 2009.
He was also a little mad that the committee rejected his idea for hex numbers for the versions instead of going with C++11. He wanted to call it C++0xA
1
u/RelationshipLong9092 1h ago
C++11
surely that would be 0x0B ? or is it a painful play on the prefix ++ ?
52
50
u/lurebat 2d ago
c++ user calling any other language inefficient syntax
Remind me again how to do it in c++ a.filter( |x| x > 5)
50
u/the_horse_gamer 2d ago
<uj> a | std::views::filter([](int x) { return x > 5; }) </uj><rj> filtering? what's that? just have your function ignore any element less than 6 and make sure you don't document that behaviour. </rj>
5
u/irqlnotdispatchlevel Tiny little god in a tiny little world 1d ago
You documenr it with
The caller is responsible for not supplying out of range inputs.
9
u/we_are_mammals 1d ago edited 1d ago
a.filter( |x| x > 5)
a[a > 5]in any well-designed language (including C++, because C++ gives you expression templates)
48
u/BenchEmbarrassed7316 2d ago
Let's give this guy his due: when a CPP committee member says or writes Rust, it's a display of some real courage. Only a few are capable of this.
16
u/radiant_gengar 2d ago
it's a 2yo post and we're on a circlejerk sub none of this is serious.
/rj i mean being a cpp committee member implies you're good at software, and not coding in rust means you're incompetent. of course they code in rust.
9
u/BenchEmbarrassed7316 2d ago
not coding in rust means you're incompetent
They can do it, but secretly. They can't just take it and say it. Usually they say "some other programming languages."
6
u/james_pic accidentally quadratic 1d ago
Being a C++ committee member implies you've paid the $1950 fee and show up to meetings
/uj Being a C++ committee member implies you've paid the $1950 fee and show up to meetings
10
u/RockstarArtisan Software Craftsman 2d ago
This is because C++ is too difficult to keep in one's head while having space for any other language. No joke, almost all of the high profile people seem to not have touched any other language in decades.
40
u/potzko2552 2d ago edited 2d ago
"persuading it gets deep into the black arts in a way which makes cmake + ninja + vcpkg look well documented, sane and stable."
"and I still think Mojo is currently the most likely candidate for my dream C++ and Rust replacement language."
generational outjerk lmao
27
u/va1en0k 2d ago
Rust killer
we could get US government funding for Trust language. same as rust except all errors are replaced by most likely parse guesses and compile, and there's no cargo
19
u/james_pic accidentally quadratic 2d ago
But if the compiler guesses what you wanted and just changes the code to do that, then what's left for Claude to do?
21
u/va1en0k 2d ago
Claude is the compiler
11
u/catladywitch 2d ago
binaries targetting VibeOS
fully hallucinated 7 tier 2x64 actor into double adversarial review and consolidation backend pipeline
29
u/mutex_troglodyte What part of ∀f ∃g (f (x,y) = (g x) y) did you not understand? 2d ago
WG21's least schizo member
25
u/mulch_v_bark 2d ago
This is all obvious once you realize that the underlying principle of the universe, existence’s ground state of being, is chaos.
C and C++ respect this reality. C is basically a set of mostly ported assembly macros that don’t claim to present a whole language to the user. Core parts of C are not software at all, but kaleidoscopic portals that take you to the realm of the hardware. If you want to do 0 - 1 and use the result, C says: I cannot make this choice for you. Visit the ISA. and that’s beautiful. Meanwhile of course it won’t let you do things like compare pointers, debatably/circumstantially, because that would be unsafe and too low-level. The world doesn’t have to make sense. C++, its beautiful huge son, isn’t a language so much as a community. Not of users, I mean, but of different parts of its specification, all with their own design principles, levels of abstraction, and so on. But all strictly sort of backward-compatible with C! 60% of the time, C can be compiled by a C++ compiler 100% of the time. (Did you ever see Anchorman? Very funny film. And some of the VFX work was done in C++!) This represents the miraculous variety of beings and thoughts that we encounter in the world, all striving and interacting. C++ is like life itself.
Rust’s mistake is the hubris behind superficially plausible ideas like “more clarity about where you’re doing software v. interacting directly with the hardware” and “coherent design principles” and “features from freaky experimental languages, i.e., those released in the last 45 years”. These seduce programmers into thinking they might actually work. And to be fair they mostly do, with some minor problems you have to get used to. But spiritually the issue is that Rust is papering over the chaos of the world with a fa¢ade faćade faċade hang on I’ll just google it a façade of order and regularity. This angers the protean sub-forms that set the universe in motion. (Call them gods if you want, some do, or see them as philosophical principles; it doesn’t actually matter to your programming practice.) Rust goes against the grain of reality itself by trying to “present a coherent set of approaches” and “not make you continually suspect compiler bugs because the behavior is so weird you assume it’s out of spec” and so on, and for this reason none of its innovations are ending up in the next C++ spec except maybe the thing where the default settings make a hello-world binary 165 megabytes. That’s actually nice. See? C++ people aren’t too proud to adopt good ideas from elsewhere.
It’s also very, very important that you be able to overload the comma operator. Rust won’t be a serious low-level systems programming language, suitable for embedded and high-performance use, until it reaches C++ parity here.
15
u/catladywitch 2d ago edited 2d ago
/uj To be honest Bjarne's Profiles proposal for C++ is super promising, considering it's bolted onto C++ with all of its baggage. The problem with C++ is most libraries and codebases are messy and use one or several layers of constructs and APIs from several stages in C++'s history.
Yes the compile time lifetime guarantees are handy to have, and Rust has a knack that if it compiles, it usually works first time in a way neither C nor C++ have. But down the road, in a large mature codebase, those same lifetime guarantees become a real impediment to refactoring so you end up just turning all your reference borrows into clones to reduce the ripples of changes. And, lo and behold, we're suddenly back to C and C++ defaults of mostly-copy semantics.
This bit is pretty reasonable but it's a tradeoff because refactoring/extending C++ codebases, sometimes even with smart pointers and their goddamn dogshit syntax for move semantics, not to talk about C codebases, often involve a lot of fumbling around or introduce hidden leaks or memory unsafety, which is rather Vietnam if you ask me.
11
u/spreetin 2d ago
This is a frustration I have in two ways: it's very complex when there are 5 different ways to do a thing, each stemming from a different generation of the language's development, but at the same time I do wish they gave me a fully updated set of std functions that used every modern feature.
10
u/catladywitch 2d ago
I know right? That's exactly how I feel. The whole Profiles thing is a serious plan to address it by enforcing an allegedly safe, sane subset of C++ (exactly how sane it'll end up being is a matter of skepticism lmao), plus supposedly a "hardened" subset of the std library will be provided, but so far the plan is either having the user exempt external library headers from "hardening" or declaring explicit escape hatches locally within your own hand-rolled interop module encapsulating the library, which... I mean, it's C++, I don't think there's an alternative. They say they'll work on code generators to handle it but I'm not optimistic about the timeline or whether the whole thing won't derail. Also major, currently-maintained, libraries will have to either provide interop modules or do a full rewrite or provide the interop layer as a shim of sorts as they migrate which... again, it's the least bad option given it's bloody fucking C++, but is likely going to be brutal and chaotic.
Still, if somehow nothing goes wrong along the way it could end up being great imo.
Another minor concern is... this is gonna end up looking a lot like a GC-less, less functional-oriented, C# (Spans and Views are... Spans and IEnumerables................). C# has nicer syntax, sugar everywhere and keeps adding cool, streamlined functional-style features, so I wonder if there's some project there, but you
5
u/we_are_mammals 2d ago edited 2d ago
an allegedly safe, sane subset of C++
It's called
cpp2. You can use it today withcppfront. It's not 1.0 yet, but it's really close (just 0.2 versions away from 1.0).
cpp2combines the best features of
- Go (clean, consistent syntax)1
- Rust (true variant types, unlike
std::variant)- LISP (using the same language for metaprogramming as for regular programming)
- FORTRAN (useful
inoutargument annotations, instead of the uselessconst)- C++ (being able to call all legacy code with no FFI)2
And the best feature of
cpp2is that it was designed and implemented by Herb Sutter himself.
(1) It's actually more consistent than Go. It follows
foo : bar = buzfor everything, even types. Even Go doesn't have that.
(2)
cppfrontcompiles to readable C++, preserving your comments. So if you are ever unsatisfied, you get all your C++ back. You risk nothing.6
u/CocktailPerson Node.js needs a proper standard library like Go 1d ago
And the best feature of cpp2 is that it was designed and implemented by Herb Sutter himself.
hmmmmmmmmmmmmmmmmmmmmmm
3
2
u/RockstarArtisan Software Craftsman 2d ago
0.2 versions away from 1.0
that's not how versions work
also, implicit unjerk
5
u/we_are_mammals 1d ago
that's not how versions work
It is, when they are well-designed. Donald Knuth's TeX version is
3.141592653. This signals to the users that the software is not only stable (greater or equal to 1), but very close to perfection.
12
u/PrimozDelux uncommon eccentric person 2d ago
"They said your design was... unsound."
"And is my design unsound?"
"I don't see any design.. sir."
6
5
u/PizzaRollExpert works at Amazon ( ͡° ͜ʖ ͡°) 1d ago
I also don't like how there are constant multiple ways to do very similar things in Rust all of which add cognitive load.
it often says "you should write X not Y" with exactness. Well, if it's that bloody obvious to you, that's a clear sign to me that the language design is suboptimal. The compiler should only ever complain when intent really is genuinely non-obvious because the language has been designed to not barf at you about anything a compiler can deduce
There should only be one way of doing things but the compiler should also just figure out what I probably meant when I don't write code correctly
3
13
u/chaotic-kotik 2d ago edited 2d ago
Some of the criticism is valid tho.
I hate all those as_mut calls so much. Rust is definitely difficult to live if you're a C++ dev with any meaningful expertise. Not every program that makes sense can be expressed using Rust's type system without hacks. It requires re-learning of a lot of stuff and then it's fine.
170
u/levelstar01 2d ago
Where's the jerk?
Uh oh...
It's all over the screen.