Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
"You can make memory safe programs if you know how to manage memory" 🤔 isn't the whole point that the language helps you not having to worry too much about just that...?
-
retoor121598d@ScriptCoded it takes some time but at a certain point, you won't have segmentation faults anymore and you have tools to find leaks to be sure.
Rust doesn't really has a standard afaik. That's one of the differences with C. Rust is still heavy in development to be able to join Linux kernel development. Current stable rust is unable to compile kernel features. There's a kinda fight between the C and Rust devs on the kernel. The C devs refuse to heavily refractor the very well tested and proven in production C code what is quite understandable. So the Rust guys have to make the changes. The changes require changes to the language and so the rust devs are a bit stuck.
C is clearly the lowest language transpiler to ASM there is (linus torvalds knows what ASM C will produce from out of his head), won't see it beaten soon. Especially with the attitude we have to software these days. "Everything seems to run on our current hardware".
Rust is still young, it'll probably get there -
chatgpt5348d@retoor
Yes, Rust has a standard library called "std" which provides essential core functionality such as data types, I/O operations, and concurrency primitives. Additionally, Rust also has a standard library documentation called "The Rust Standard Library" to help users understand and utilize the functionalities provided by the standard library. -
You can make memory safe programs in C if you are a genius who never makes mistakes.
-
@retoor C may be the easiest high level language to compile in your head, so to speak. Once you've read disassembly for a while it just comes naturally. The good thing about that is you don't have to do much guessing in regards to anything, particularily performance, because even at a glance you can get a good idea of what the compiler is going to generate.
People simply forget that the job revolves around telling a calculator which operations to perform. They may not like it, but that's the job. In truth, learning to read code way uncle Linus does is more beneficial than reading any fucking book.
Except the Dragon Book, maybe. MAYBE. -
retoor121598d@Liebranca ah yes, the dragon book is a legend. Will buy directly, I hope it's a bit affordible at least. Just by understanding (lib)c and Unix api I also think to understand much. I've rebuild existing software quite a lot since nearly everything is based on it. So far, I didn't find the motivation yet to learn ASM. I know some history regarding register names and did some things in it but can't write it. strcmp of libc is written in ASM to apply simd, that's interesting. I'm the proud finder of a typo in the glibc source code somewhere in strcmp
-
atheist99308d@Liebranca for most performance stuff where you're decompiling I'd say c++ is as good as c. Vtable function calls are hard to understand but they're also slow.
-
Nah, Rust's syntax is miles ahead of C. It's more consistent, intuitive and expressive. Can't do `let [a, b, ..rest] = &list;` destructuring in C can ya?
IMO Rust is also just a better language than C. Not that C is bad for what it is, but it's a language that was invented 20 gazillion years ago -- as a portable assembly, mind you --, so obviously Rust could learn from decades of language design -
@atheist They're not too far off. Idiomatic C++ may generate more complex code at times depending on which features you use. But predicting what day-to-day stuff will compile to is usually about the same.
-
C/C++ chads unite!
C++ is slowly getting better tools. I think we might be going to C++17 (or higher) at work. Woot! I did mention to my boss that we may end up not being able to find capable C++ devs if people are afraid/dislike the language. He mentioned a lot of schools aren't even teaching it. Seems so weird as C/C++ still have a lot of projects depending upon them.
Not sure I am a good example of a C++ dev. I use new all the time. But our framework depends upon this. We also do the big no no of type puning. -
what a daft argument, and how incredibly overused in spite of that!
You can make memory safe programs in Assembly too. You can make class hierarchies and interfaces in Assembly too. Why bother using another language?
Because the point of languages is what you CAN'T do, or more precisely, what has to be clearly marked. Memory safety doesn't mean "your programs can be memory safe". If it meant that, the entire infinite set of Turing-complete languages would be memory safe. Memory safety means that there CAN'T be a memory bug outside an unsafe block. ... -
... It means that when your code gets reviewed by the 512'th time because someone somewhere in the ecosystem invited the NSA, Mossad and FSB into every Linux server in existence, the reviewers will not have to read all 100k lines of garbage business logic written by undergrads with zero job experience because they basically need half a career in their portfolio to even be considered for an unpaid internship, just those 30 lines of unsafe code where you implement a specific optimization you needed.
-
The point of Rust is that you don't have to be highly trained or vigilant, you can just write code. I agree that it's missing a ton of features and it's not really mature yet, even though "mature" is such a fuzzy term that there will be at least two decades between when I consider it mature and when C developers finally have to admit that it's as mature as any other lang, but the single benefit that I don't have to think about safety is important enough that it overrules any difficulty arising from the language's lack of maturity.
-
Ideally, the goal of C++ within the next 5 years should be to get to a point where an external safety investigator will be able to similarly skip over 99.9% of a C++ codebase which exclusively uses bounds checked access, ranges and smart pointers and simple cases of references and is therefore automatically verifiably lifetime safe, and manually prove the remaining 0.1%. They are making good progress by the way, I'm rooting for them, because the C++ type system is fantastic and I would really like to use it.
-
@Demolishun I think Herb Sutter charted a 10 year plan in 2019. I would never accuse Herb of having realistic ambitions, but I think that his grandiose plans can get people on board so I adopted that rhetoric. Also most of the external pressure for safety is coming from political entities which pretty much only communicate in the form of very optimistic plans. The NIST won't take "It'll be done when it'll be done" even though on some level they probably know that's the only real schedule.
-
retoor121597d@12bitfloat in c you can contribute to the Linux kernel. Rust lacks a lot of features. There is no stable rust compiler for the Linux kernel. Only some patched nightly build. Rust is toys comparing to C
-
@retoor Rust definitely isn't a toy, but it's not as mature as C yet. Rust has only existed in it's final form for 10 years, give it some time
-
@12bitfloat I don't think this is even close to Rust's final form. There are at least 4 major pending type system features that are waiting for the new trait solver which is slated to become generally available next year. Const is still kind of a pariah. FromResidual is technically viable now but we just can't agree on its semantics. That will affect almost every function in crates that takes a callback.
-
@12bitfloat But I guess you can chalk up all of that as library dev concerns. It's true that application development has been pretty much unchanged for a while.
-
@lorentz Fair enough, I meant it more like "in the current 1.0 form where backwards compatibility is guarenteed". Before 2015 Rust was changing daily in big ways, it was kinda crazy
-
retoor121596d@12bitfloat I know, my last comment was "it'll get there". More and more apps I use are written in Rust. But DAAMN cargo is heavy. And Rust also does the terrible microframework stuff of JS? Doomed. People really should start to care about dependencies again. I installed a loc application (lines of code) with cargo. My laptop almost crashed, hundred dependencies or so pulled in. JS and Rust people are kinda the same huh :P
-
@retoor its supposed to be an anti style or something. People are afraid of pointers or something. If you assign it to a smart pointer its supposed to be okay then.
-
retoor121596d@Demolishun i consider nothing wrong with any pointer. I think they're easy as F. But there are books with more than 200 pages, only about the pointer
-
@retoor I'm not sure what to think about the dependency situation in Rust
Yes Rust uses more smaller dependencies, but unlike JavaScript, these libraries are overwhelmingly high quality and non-trivial -
@retoor Raw pointers don't carry any ownership semantics which can lead to various bugs
If you get passed a raw pointer, do you now own the pointer? Should you free it or does somebody else free it? Is it just temporary? If it is, what is it's object lifetime?
That's why it's recommended to use smart pointers, because it's harder to misuse them (and they will clean themselves up, which is nice) -
@12bitfloat most of the time I set the objects parent to something else (Qt). So when it deletes everything deletes. Yeah, you gotta clean things up, or know how to clean them up.
-
@retoor The problem is manual lifetime management, the source of the majority of recorded critical security bugs. That's what smart pointers were built to replace, and that's why new is only marginally better than malloc.
-
@Demolishun Of course, you just gotta not make mistakes and then things won't go wrong! Why has no one ever thought of that?
-
@Demolishun If you use a shared_ptr it should work by itself (not in Qt though) (well, and also not bidirectional parent<->child relationships, but that's a topic for another day)
IMO that's one of the beautiful things about C++ which Rust took inspiration from: Being able to build zero-cost(-ish) abstractions which do the right thing and make it harder or impossible to use incorrectly
For example, in my code base there is not a single point where I have to manually clean something up. It just all happens automatically for me (assuming I don't have rc cycles lol)
It just makes your code so much cleaner and more robust, I love it -
retoor121596d@12bitfloat that's with Java just the same right? And python or js?
This is where it's all about: Memory usage: 53329112 allocated, 53329075 freed, 37 in use. 37 is just idle value of my server. No valgrind issues, nothing. I've overwritten the original malloc, realloc and strdup and free so they count. I can show this statistics whereever i want. Also at quit of the application. Maybe that i should at a thread lock around upping the values, but they only up, they don't read or so. So hmm. But point is that i'm directly aware if there's a leak. All my tests end with these statistics. All (28) components are tested with own test framework that communicates with smileys. The framework is just a check at exit for memory usage and assert() to test smth. Every good assert is a smiley. It were dots before.
Edit: bit vague output btw, third four? -
@retoor Looks good I guess lol
I'm not saying you can't make a working program with raw pointers
But I really believe higher level abstractions like smart pointers let you program so much quicker without sacrificing much or even any performance -
@12bitfloat I am warming up to smart pointers for sure. Its just most of our codebse is C with Classes or Qt.
-
retoor121596d@12bitfloat I've just installed alpine linux on a laptop. How hard i will regret this? Will add xfce
-
Counterpoint: in fringe cases, ownership requires transfer, and so more boilerplate is needed, eg https://github.com/Liebranca/...
The idea that higher abstraction is (by itself) better is downright kindergarten. Good code always takes time when dealing with a complex system.
Related Rants
I don't really understand all that love rust gets. It's syntax, better than C++'s, isn't better than C syntax.
You can make memory safe programs with C, just if you know how to manage memory, and you should only if you know how to. Bigger ecosystem for C/C++.
C23 waay better than any rs standard.
PS: I used both C/C++ and Rust
rant
rust
comparaison
cpp
c