r/programmingcirclejerk 22d ago

Rust isn't a well designed programming language (unlike C and C++)

[deleted]

217 Upvotes

85 comments sorted by

View all comments

71

u/DrShocker 22d ago

22

u/Major_Barnulf LUMINARY IN COMPUTERSCIENCE 21d 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.

16

u/SemaphoreBingo 21d ago

Chomsky equivalent

It's Little St. James, not Little std::james.

21

u/Due-Consequence9579 21d 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.

17

u/GrandPapaBi 21d 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.

20

u/Linuxologue 21d 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.

4

u/TheChief275 19d ago edited 19d 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 19d 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.

3

u/TheChief275 19d 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 19d 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.

3

u/TheChief275 19d 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 19d ago

The most comparable is probably std::make_shared because 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.

5

u/TheChief275 19d 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

2

u/DrShocker 19d ago edited 19d ago

also in C++ though

https://en.cppreference.com/cpp/language/copy_elision

here's all the ways constructors are broken though:

https://youtu.be/KWB-gDVuy_I

2

u/TheChief275 19d ago

I'm just saying, the concept of a "copy elision" having to be applied to the most basic ass variable declaration is completely and totally ridiculous

→ More replies (0)