On the one side I really like c and c++ because they’re fun and have great performance; they don’t feel like your fighting the language and let me feel sort of creative in the way I do things(compared with something like Rust or Swift).
On the other hand, when weighing one’s feelings against the common good, I guess it’s not really a contest. Plus I suspect a lot of my annoyance with languages like rust stems from not being as familiar with the paradigm. What do you all think?
Depends on if you’re coding for critical infrastructure (i.e. - electrical grid), or writing a high performance video game that can run on older hardware.
We should absolutely have specific licenses like Civil Engineers do for computer infrastructure that is required for any software written for specific purposes. It would be a nightmare to implement, but at some point, it’s going to be needed.
writing a high performance video game that can run on older hardware
Unless it’s some really exotic platform, I’d honestly still say no. Rust has shown that memory safety and performance doesn’t have to be a tradeoff. You can have both.
But sure, if whatever you’re targeting doesn’t have a Rust compiler, then of course you have no choice. But those are extremely rare cases these days I’d say.
There’s always a trade-off. In rust’s case, it’s slow compile times and comparatively slower prototyping. I still make games in rust, but pretending there’s no trade-off involved is wishful thinking
They mean a trade off in the resulting application. Compile times mean nothing to the end user.
That may be true but if the language is tough to develop with, then those users won’t get a product made with that language, they’ll get a product made with whatever language is easier / more expedient for the developer. Developer time is money, after all.
You’d be better just using a managed languages in many cases.
With tiered jit and careful use of garbage allocations they can actually be the same or faster.
I don’t even think we really need to eek out every MHz or clock cycle of performance these days unless your shipping code for a space vehicle or something (But that’s an entirely different beast)
We’ve got embedded devices shipping with 1GHz+ processors now
It’s just time to move on from C/C++, but some people just can’t seem to let go.
Battery life is a reason. I’ve had clients come to me complaining their solution from another vendor didn’t last very long. Turns out it was running Java on an embedded device.
Because there is still market for small mcus. A 1GHz processor is a lot more expensive than a 32 bits 75MHz. If you produce even a low number of units, the price difference can be huge.
That is the mindset that gives us text editors using 100% cpu to blink a cursor because their css triggers a bug in the web browser they ship to render the text editor.
You can be memory save without shipping a whole browser, but disregarding power and memory efficiency will just make performance gained by hardware evaporate in overhead.
I’m just glad to see the White House listening to people who understand technology for a change.
We need legislators who aren’t all literally older than cryptography. If they weren’t bought and paid for by billionaires that would be nice too.
That requires a population willing to vote for such legislators.
It requires score voting so that, even if heavily gerrymandered, one can still meaningfully express a preference without throwing one’s ballot in the garbage.
It’s never throwing your ballot in the garbage though. I used to think the same way, but every vote on the left, even if for the lesser evil, even if they lose, moves the conversation to the left. When we all stay home you get maga nutjobs stealing the show running unchecked.
Last thing is that gerrymandered states are the EASIEST to upset by increasing voter turnout. To gerrymander effectively you have to put your opponent in dense areas they’ll win by a large margin, then spread your side so that you barely win the rest of the districts. That means that a 5% increase in votes on the left can take you from a loss to a nearly complete victory in a gerrymandered state.
Vote splitting on the other hand is a trickier beast, but in the end if all the left votes go to a moderate then that gives the left a lot of leverage because if the moderate candidate doesn’t bend to the left then they’ll lose the next election.
Always vote.
Don’t blame the victims for a sham of a democracy. FPTP is there to prevent anything outside of a two party system where primaries are filled with (fully allowed) cheating.
FPTP does destroy a lot, I’ll give you that, but municipal and regional elections have miserable turn-outs too and they have much more potential for perceptible change than state or national change.
In the USA things have to get way worse than they are now before they get better. A very very large percentage of voters would have to be fed up with FPTP to force change in that area. Also, they would have to be educated enough to understand that FPTP is a problem.
For one, FPTP doesn’t get enough credit for just how nefarious it is. And let me be clear: I am speaking of the presidential election specifically, though I’m sure this applies to many aspects of this “democracy” including state elections, etc that you mentioned.
Instead, the overarching establishment narrative likes to point the finger at the electoral college (which also quite heavily biases the power of votes toward voters in less populous areas and states).
Since the established oligarchs (who own the news outlets) tend to control information delivery in this country, how would you break through that wall? Would you engage in peaceful protest (or self immolation)? Well, they’ve got a playbook for that too. They will discredit you and make you seem unhinged. For proof of that, look at the way they’re delegitimizing the brave, selfless active duty Air Force member who engaged in peaceful protest by self immolation outside of the Israeli embassy against the Gaza war for just how easy it is. Most news watching voters probably already think he was crazy. It didn’t quite have the power that that act had during, say, the Vietnam war.
Since you’re here, I’m guessing you’re a software engineer. Do me a favor: Model the real world dynamics of a US presidential election using domain driven design, making sure to accurately represent the two objectively unfair stages:
Rule #1: All candidates must pass stage 1 to be eligible for stage 2.
In stage 1, feel free to cheat, commit fraud, and engage in any strategy you need to prevent anyone but the owners of the party’s preferred candidates from winning. After all, your party is a private organization that can engage in whatever unfair tactic they deem necessary.
In stage 2, (if you’re paying attention, you ALREADY have irreparably biased the possible outcomes by cheating in stage 1) because of FPTP, you can now simply choose between only two of the MANY, MANY parties.
If you designed a system like that as a software engineer, your colleagues would be at your throat about how flawed that design was. However, here in the US, that’s just the design of our dEMoCrACy oF tHa gReATeSt cOuNTry iN tHa wErLD! 🥴
Edit: That “much worse” statement seems to come from a place of privilege. Don’t forget that. RIGHT NOW, more people are homeless and destitute than any other time in MY LIFE (I was born in the late 70’s). And most people literally have no say in whether or not their tax money is being used to genocide Muslims overseas to make room for a puppet government. Remember: You’re an anti-Semite if you oppose genocide.
Leaders in Industry Support White House Call to Address Root Cause of Many of the Worst Cyber Attacks
And it’s called C/C++. It’s gotten so bad that even the friggin’ white house has to make a press release about it. Think about it, the place where that majority barely even understand the difference between a file browser and a web browser is telling you to stop using C/C++. Hell, even the creator and maintainers of the language don’t know how to make it memory safe. If that isn’t a wake up call, then nothing ever will be.
And this isn’t the first call! The IEEE also says more clearly: GTFO C/C++.
If you want memory-safe, don’t write C/C++. Trying to get that shit memory-safe is a hassle and a half. You’re better off learning a language that isn’t full of foot-guns, gotchas, and undefined behavior.
If you want memory-safe,don’t write C/C++.Fixed that for you. There’s no situation where you want buffer overruns.
There’s no situation where you want buffer overruns.
I want buffer overruns in my game consoles for jailbreaking purposes lmfaoooooo
If you don’t want
memory-safebuffer overruns, don’t write C~~/C++.~~Fixed further?
It’s perfectly possible to write C++ code that won’t fall prey to buffer overruns. C is a lot harder. However yes it’s far from memory safe, you can still do stupid things with pointers and freed memory if you want to.
I’ll admit as I grew up with C I still have a love for some of its oh so simple features like structs. For embedded work, give me a packed struct over complex serialization libraries any day.
I tend to write a hybrid of the two languages for my own projects, and I’ll be honest I’ve forgotten where exactly the line lies between them.
You’re better off learning a language that isn’t full of foot-guns, gotchas, and undefined behavior.
As a JS developer, seeing this quote about C/C++ for a change gives me unbelievable levels of schadenfreude
What memory-safe systems programming languages are out there, besides Rust?
Zig is better than C, but still a far stretch from the memory safety of Rust: https://www.scattered-thoughts.net/writing/how-safe-is-zig/
Also Swift!
Languages with GC
I appreciate your answer, but I mentioned systems programming, because I was more interested in languages that do not rely on a garbage collector.
To play devil’s advocate, most systems programming can be done even with a garbage collector. Midori was a project to build an operating system on a variant of C#, and although the garbage collector did impose technical difficulties, it wasn’t a dealbreaker. Go isn’t usable everywhere Rust is, but it can in fact be used for many things that previously would have been considered “systems” niches (which is part of why there was a somewhat prevalent misconception in the early days of Rust that they were similar languages). Prominent D developers have defended D’s garbage collector (even though it’s technically optional). Bjarne Stroustrup, the creator of C++, used to express great confidence that C++ would one day have a garbage collector.
…but you’re right, Rust and its rise in popularity (and, conversely, the C++ community’s resistance to adopt anything with garbage collection) have definitely narrowed the common definition of “systems programming” to exclude anything with a “thick” runtime.
I enjoyed the facts spit above.
Huh, I totally missed that my bad
Wasn’t Go designed to be a memory safe systems programming language? I haven’t really used it enough to see if it holds true, though.
No, Go will happily let you seg fault at your first convenience.
Segfaults aren’t particularly dangerous. They mean the problem was caught. The program usually just exits.
Failing to segfault, thereby allowing a bad memory access, is where the real trouble happens.
No, if you try to index something out-of-bounds it will panic, which is not a memory-safety gap.
Go is almost memory safe, but it does suffer from an issue with its thick pointers (type + address) that can cause race conditions to misrepresent the type of a data structure. This can lead to true segmentation faults and out of bound memory accesses, though it will probably be quite difficult (but not impossible) to exploit them.
I’m very flaky here, as rust is the big one, but I think zig and/or nim might be
Zig is better than C, but still a far stretch from memory safe: https://www.scattered-thoughts.net/writing/how-safe-is-zig/ I think Nim is better because it uses a garbage collector and doesn’t have any pointer arithmetic, but I couldn’t find as much on the topic.
let me feel sort of creative in the way I do things
🚩
they don’t feel like your fighting the language
I really understand what you mean wrt Rust. I really do - I was there once. But it’s a phase you grow out of. Not just that - the parts you fight now will eventually become your ally.
and let me feel sort of creative in the way I do things
I had the same experience with C/C++. But as the design grows, you start hitting memory-safety bugs that are difficult to avoid while coding - even after you learn how those bugs arise in the first place. Just a lapse of concentration is enough to introduce such a bug (leaks, use-after-free, deadlocks, races, etc). I’ve heard that C++ got a bit better after the introduction of smart pointers and other safety features. But, it comes nowhere near the peace of mind you get with garbage collected languages.
That’s where Rust’s borrow checker and other safety measures kick in. The friction disappears when you acquire system knowledge - concepts of stack, heap, data segment, aliasing, ownership, mutation, etc. These knowledge are essential for C/C++ too. But the difference here is that Rust will actually tell you if you made a mistake. You don’t get that with C/C++. The ultimate result is that when a Rust program compiles successfully, it almost always works as you expect it to (barring logical errors). You spend significantly less time debugging or worrying about your program misbehaving at runtime.
The ‘friction’ in Rust also helps in another way. Sometimes, you genuinely need to find a way out when the compiler complains. That happens when the language is too restrictive and incapable of doing what you need. You use things like
unsafe
,Rc
andRefcell
for that. However, most of the time, you can work around the problem that the compiler is indicating. In my experience, such ‘workarounds’ are actually redesigns or refactors that improve the structure of your code. I find myself designing the code best when I’m using Rust.C++ can have excellent performance without ever using a single pointer and avoiding unsafe functions like
gets()
- this isn’t necessarily a judgment on language - it’s a judgement on bad programming habits.Pointers fucking suck, in a modern C++ codebase everything should be pass by value or const/mutable ref. To my preference I’d rather drop mutable refs to force everything to be more functional but whatever.
I mean that’s just the problem with C++. There’s 17 different ways to do things, 2 are always wrong, 14 are contextual, and 1 is reserved for super special cases
And the one you choose is always the one that’s weak to the specific vulnerability you didn’t think of!
Pointers suck in C++. In other languages every single variable is a pointer and it works perfectly with no memory bugs and great performance.
Pass by value often uses too much memory. Especially if you have a bunch of simultaneous functions/threads/etc that all need to access the same value at once. You can get away with it when your memory is a few dozen integers, but when you’re working with gigabytes of media… you need pointers. Some of the code I work with has values so large they don’t even fit in RAM at all, let alone two or three copies of them. Pass by value could mean writing a hundred gigabytes to swap.
That’s one reason I mentioned pass by reference “smart” languages will do it automatically depending on the size of the argument, some languages (including my beloved PHP) even have a copy-on-edit functionality where everything is technically passed as a mutable reference but as soon as you mutate it (unless it was explicitly marked as a mutable reference) it will copy the original object and have you edit the copy instead of the original.
Is being explicit about when copies happen almost always a good thing - yea the overhead of that system is undesirable in performance sensitive situations - but for a high level scripting language it’s quite nice.
The way PHP does it is oddly smart
Working with habits is just not good enough. C++ has far too many footguns to be considered a safe language and there are frankly objectively better modern alternatives that you should use instead, perhaps except if you have a really large legacy code base you can’t replace (but even then, consider calling into it via FFI from a safe language).
Even if you tried to actually enforce these habits, you’d just end up inventing a new language and it would be incompatible with previous C++ too.
C++ is not a viable language for the future.
I get kinda bad vibes from this comment and I’d like to explain why…
If somebody said “We’re building a point of sale terminal and to make it secure we’re going to be using C++” I’d probably have a dumbfounded expression on my face unless they immediately continued with “because there are libraries we can lean on to minimize the amount of code we need to write.”
C++ has an extremely mature ecosystem - Qt is essentially it’s own language at this point! There are reasons to still consider building in C++ and saying “C++ is not a language for the future” feels dogmatic and cargo culty to me. Algol, Cobol and Fortran still have programming communities and while I agree that C++ is outsized in presence for the danger it presents there are still good reasons to choose it for some specific domains - high performance graphical programs being one of those in particular.
C++ has a plethora of foot guns and you need to be aware of them but when you are they’re easy to avoid in fact your quote:
Even if you tried to actually enforce these habits, you’d just end up inventing a new language and it would be incompatible with previous C++ too.Even if you tried to actually enforce these habits, you’d just end up inventing a new language and it would be incompatible with previous C++ too.
Is probably the thing I agree most with - well built C++ isn’t incompatible with regular ol’ C++ but it feels like a different language… but as a not too old old-man-developer different projects often feel like different languages - each company/project has tools and libraries they use and it’ll cause code written in the same language to read really differently… I’m a functionally oriented programmer with a pretty particular style, my C++, Python, Java, PHP, Node and Rust all look nearly the same except for language specific peculiarities.
So yea, discipline is needed and nobody’s default choice should be C++ but if you follow best practices your C++ can be quite safe.
… that all said… I fucking hate the concept of definition files being sseparate from code files so I’m not going to use C++ anytime soon.
Even references aren’t safe in C++ though, since there’s no borrow checker. Unless you copy everything or use reference counting types everywhere, you’ll still hit plenty of memory-violating footguns. But at that point, why use C++ at all?
just avoid all the bad stuff bro
If I was giving a tour of my kitchen and it included phrases such as “avoid using the leftmost cabinet of any set of two”, “the freezer doesn’t work but the fridge can be set to the same temperature”, or “the oven has been deprecated, just use the microwave”, you’d rightfully gtfo. Why is this acceptable of a programming language??
Rust does memory-safety in the most manual way possible, by requiring the programmer prove to the compiler that the code is memory-safe. This allows memory-safety with no runtime overhead, but makes the language comparatively difficult to learn and use.
Garbage-collected compiled languages — including Java, Go, Kotlin, Haskell, or Common Lisp — can provide memory-safety while putting the extra work on the runtime rather than on the programmer. This can impose a small performance penalty but typically makes for a language that’s much easier on the programmer.
And, of course, in many cases the raw performance of a native-code compiled language is not necessary, and a bytecode interpreter like Python is just fine.
Rust does memory-safety in the most manual way possible
The most manual way is what C does, which is requiring the programmer to check memory safety by themselves.😛
Also will say that outside of some corner cases, Rust is really not that harder than Java or Python. Even in the relatively rare cases that you run into lifetimes, you can usually clone your data (not ideal for performance usually but hey its what the GC language would often do anyway). And reliability is far better in Rust as well so you save a lot of time debugging. Compiles = it works most of the time.
C# dev with reasonable experience with java, python, and rust:
Rust is harder
The most manual way is what C does, which is requiring the programmer to check memory safety by themselves.😛
The difference is, Rust will throw a tantrum if you do things in an unsafe way. C/C++ won’t even check. It’ll just chug along.
Rust is really not that harder than Java or Python.
As someone who’s done all three, the fuck it isn’t.
If you are familiar with C/C++ best practices to any operational level, those things will translate over to Rust quite nicely. If not, that learning curve is going to be fucking ridiculous with all the new concepts you have to juggle that you just don’t with either Java or Python.
I like Rust a lot, philosophically and functionally… but it is WAY harder. Undeniably very hard.
Just try and do anything with, say, a linked list. It’s mind-boggling how hard it is to make basic things work without just cloning tons of values, using obnoxious patterns like
.as_mut()
, or having incredibly careful and deliberate patterns oftake
-ing values, Not to mention the endless use of shit likeBox
es that just generates frustrating boilerplate.I still think it’s a good language and valuable to learn/use, and it’s incredibly easy to create performant applications in it once you mastered the basics, but christ.
It’s mind-boggling how hard it is to make basic things work
It’s mind-boggling how broken basic things are.
I have not encountered anything broken, aside from maybe binary app docstring stuff (e.g., automated example testing).
On the contrary, everything seems precise, reliable, and trustworthy. That’s the thing to really like about Rust – you can be pretty much fearless in it. It’s just difficult. I die a bit in time any time I have a return type that looks like
Box<dyn Fn(&str) -> Result<Vec<String>, CustomError>>
or some shit . Honestly, the worst thing about Rust is probably that you have to manually specify heap vs stack when the compiler could easily make those determinations itself 99% of the time based on whether something is sized.
Software engineer for almost two decades at this point, programming off and on since a kid in the late '80s: Rust is harder. It did seem to get better between versions and maybe it’s easier now, but definitely harder than a lot of what I’ve worked in (which ranges Perl, PHP, C, C++, C#, Java, Groovy/Grails, Rust, js, typescript, various flavors of BASIC, and Go (and probably more I’m forgetting now but didn’t work with much; I’m excluding bash/batch, DB stored procedures (though I worked on a billing system written almost entirely in them), etc.)
That said, I don’t think it’s a bad thing and of course working in something makes you faster at it, but I do think it’s harder, especially when first learning about (and fighting with) the borrow checker, dealing with lifetimes, etc.
The availability of libraries, frameworks, tools, and documentation can also have a big impact on how long it takes to make something.
A better approach is the one Apple uses with Swift (and before that, Objective-C… though that wasn’t memory safe).
In swift the compiler writes virtually all of your memory management code for you, and you can write a bit of code (or annotate things) for rare edge cases where you need memory management to do something other than the default behaviour.
There’s no garbage collection, but 99.999% of your code looks exactly like a garbage collected language. And there’s no performance penalty either… in fact it tends to be faster because compiler engineers are better at memory management than run of the mill coders.
To be fair, Swift uses reference counting instead of garbage collection which has different tradeoffs than GC but does incur a performance penalty.
I’m no Rust expert, but in what I have done with it I’ve always found it reassuring to know the compiler has my back, and I haven’t found the rules too onerous. In some ways I prefer this to counting on some black-box garbage collector with unpredictable performance costs, and I certainly prefer catching as many errors as possible at compile time not runtime.
So that’s why I’ve been hearing non-stop crab rave music!
The interpreter or compiler could also introduce memory issues into the code. Much less likely to happen, but it is not unknown.
I’m going to probably be downvoted to Hell, but I disagree wholly that it’s the language’s fault that people can exploit their programs. I’d say it’s experience by the programmer that is at fault, and that’s due to this bootcamp nature of learning programming.
I’d also blame businesses that emphasize quantity over quality, which then gets reflected in academia because schools are teaching to what they believe business wants in a programmer. So they’re just churning out lazy programmers who don’t know any better.
There needs to be an earnest revival of good programming as a whole; regardless of language, but also specifically to language. We also need to stop trying to churn out programmers in the shortest time possible. That’s doing no one any good.
That’s my two cents.
Gently, I would ask you to think about yourself in a future role where you have too little time, and are under too much pressure, and you haven’t gotten enough sleep, and you’re distracted on this particular day, and you happen to make a mistake, leave out a line, forget to fix a section of code you were experimenting with…
And even if you, a paragon of programming power and virtue, would never find yourself able to be hurt by your tools, you must surely know that mortals have to work with them as well, right?
Id say it’s experience by the programmer that is at fault, and that’s due to this bootcamp nature of learning programming.
You are getting downvoted, because this is factually proven wrong by studies and internal analysis of several huge companies (e.g. google/android and microsoft). A huge number of exploitable bugs are preventable using memory safe languages, nowadays even without performance costs (Rust).
Apart from that your point is orthogonal to the point of the post. You can have better trained coders and have them use better, safer technologies.
We could also just train every driver more thoroughly including mental training and meditation to make sure they are more calm and focussed when driving and we maybe wouldn’t need seatbelts anymore. But:
- Is that a realistic scenario?
- Why not use seatbelts anyway, so there’s a higher chance of not dying if some driver didn’t sleep well that day?
Memory safety issues were a thing even before bootcamps and “bootcamp culture”.
Even if you fix expertise, intention, and mindset - the entire workfield environment and it’s people - mistakes still happen.
If you can categorically evade mistakes and security and safety issues, why would you not?
Even the best programmers are going to make mistakes at times. Saying the solution is to just be perfect all the time is impossible.
but I disagree wholly that it’s the language’s fault that people can exploit their programs. I’d say it’s experience by the programmer that is at fault, and that’s due to this bootcamp nature of learning programming.
Considering that even the best programmers in the world can’t write correct programs with C/C++, it’s wrong to absolve those languages of the massive level of memory safety bugs in them. The aforementioned best programmers don’t lack the knowledge needed to write correct programs. But programmers are just humans and they make or miss serious bugs that they never intended. Having the computing power to catch such bugs and then not using it is the real mistake here. In fact, I would go one step further and say that it isn’t the language’s fault either. Such computing power didn’t exist when these languages were conceived. Now that it does, the fault lies entirely with the crowd that still insist that there’s nothing wrong with these old languages and that these new languages are a fad.
Heartbleed, that famous cve written by a bootcamp grad
While I agree wholeheartedly with the idea that we need to emphasize quality over quantity, so long as software pays well there will be people who don’t care. In my university I’ve met a fair few people that complain about having to learn about compilers, assembly, and whatnot because “I’ll never need to know that in my actual job”. While to some extent in the United States you can blame the fact that classes just cost a ton, I think it’s a sad reality that, barring some key change in the way our whole education and economic systems work, there will be unimaginative apathetic people that will ruin things for the rest. Plus people are fallible or something I dunno. But yeah void pointers are my jam because I don’t have to wait precious clock cycles making new ones jk.
Absolutely. The problem is, most programmers are mediocre. So sadly the protection of stupid people tends to take cultural precedence.
Please show me a single “good” programmer who is working with C/C++ and hasn’t had a single memory bugs in a decade.
Check out Eskil Steenberg. He’s mostly a game dev, but he has some really good talks.
And you know with 100% certainty he hasn’t had a single memory bug in his last decade of developing?
He has written his own libraries and programs to ensure these things don’t happen.
What you people need to understand is that these problems have been solved before Rust. They just weren’t baked into the language. And so people made mistakes.
https://www.youtube.com/watch?v=pvkn9Xz-xks
I’m not saying Rust is not always the better choice. Of course not. I’m just oh-so-weary of this rewrite-the-world zealotry a lot of people have about it.
you people
You mean grown-ups?
No, children.
I’m going to advocate for C here: the sheer simplicity, fast compile times, and power it gives you means it’s not a bad language, even after all these years. Couple that with the fact that everything supports it.
Rust, while I don’t actually know how to write it, seems much more difficult to learn, slower to compile, and if you want to do anything with memory, you have to fight the compiler.
And memory bugs are only a subset of bugs that can be exploited in a program. Pretending Rust means no more exploitation is stupid.
You’re in the wrong place if you want to pitch C over Rust 😅
And memory bugs are only a subset of bugs that can be exploited in a program. Pretending Rust means no more exploitation is stupid.
This is facile.
According to Microsoft, about 70% of security bugs they see are memory safety issues.
Yes: if you introduce memory safety, there’s still those 30% of security bugs left. But, well, I’d rather worry about 30% of issues than 100%…
Similarly, I use libraries that eliminate SQL injections unless you really go out of your way.
Bait used to be believable 🚬
In cases where bugs have been counted they tended to make up the majority of vulnerabilities. Chrome, Firefox, and Windows reported that around 70% of security vulnerabilites were memory corruption. Yes a subset, but the majority of the worst subset.
I’ve also heard that unsafe Rust is even more dangerous than C. I guess that’s probably something to do with the fact that you’re always on your toes in C vs Rust? I don’t know. But if you need to do any sort of manual memory management you’re going to need unsafe Rust.
I’ve also heard that unsafe Rust is even more dangerous than C.
Utterly Untrue :
It’s important to understand that unsafe doesn’t turn off the borrow checker or disable any other of Rust’s safety checks: if you use a reference in unsafe code, it will still be checked.Way to necro a thread. This point was made months ago.
The thing is the whole c program is unsafe. In rust individual parts are marked unsafe. This means auditing should be easier. Also being always on your toes isn’t really viable. Breaking down the program into safe vs unsafe is probably an improvment
No, rust is stricter because you need to think a lot more about whether weird edge cases in your unsafe code can potentially cause UB. For ex. If your data structure relies on the
Ord
interface (which gives you comparison operators and total ordering), and someone implements Ord wrong, you aren’t allowed to commit UB still. In C++ land I’d venture to guess most any developer won’t care - that’s a bug with your code and not the data structure.It’s also more strict because rusts referencing rules are a lot harder then C’s, since they’re all effectively
restrict
by default, and just turning a pointer into a reference for a little bit to call a function means that you have to abide by those restrictions now without the help of the compiler.Unsafe code should be a very, very small part of any Rust codebase. Lots of major libraries have a policy against including any unsafe code at all, because 99.9% of the time you can do just as well with safe cost. The major exception is when you need to call C code.
I’ve written quite a bit of Rust and a lot of C and C++ code. I’ll take Rust over C or C++ for any task, including ones where memory safety isn’t a concern. Yes, there’s a learning curve, but overall it’s just more pleasant to use. Now that I’m used to it, writing C++ code feels just as much like fighting the compiler as Rust ever did.
Zig is a pretty interesting alternative to C
Pretending Rust means no more exploitation is stupid.
I guess? Are you alluding to someone or something in particular?
Mainly those who imply we should rewrite absolutely everything in Rust.
Except RIIR is a meme, not a real thing to be taken seriously.
Oh yes, improve security by mandating that everyone uses higher level languages that encourage importing libraries.
I hate to pull the AI card, but AI has a better chance of catching low level language type issues than forcing people to use tools they didn’t want to has of accomplishing anything positive.
Yeah let’s audit code using heuristic tools, after all safety is just about probabilities in the first place!