Live data from Hacker News

What it feels like when Rust saves your bacon

smallcultfollowing.com

141–150 of 192 posts

Re: What it feels like when Rust saves your bacon

#141
post #8

This article is super overcomplicated. All it had to say was that rust tells you when you keep reference to on stack variable after it goes out of scope. Context provided adds nothing. I must say - as someone who doesn't use rust - I haven't had this type of issue in years, and when I did it wasn't hard to debug. You get corrupted data, set data breakpoint and in the provided example you will see it being modified by…

Yeah no. In my experience, when several people commit to a common C/C++ codebase this kind of issue become really exhausting when it happens more than once, and the symptoms may be so subtle it's a bitch to debug. Rust lowers your mental load. You spend more time being creative and way less time debugging "obvious" (or not) mechanical problems (reference not-on-stack-anymore variables, use-after-free, concurrent writ…

> less time debugging

I would say it isn't even the debugging. As many of the C++ programmers here have said as you get good at C++ this becomes something that you are vigilant for and it rarely actually gets written. But just the lack of even needing to think about it is a huge load off my mind. When I used to write C++ I never really realized how vigilant I was. Every time I added code into the middle of a function I had to double check all of the lifetimes, every time I shorted the lifetime of a variable I had to search for it to the end of the function. Just not having to worry about this much really frees your mind for thinking about other things.

Re: What it feels like when Rust saves your bacon

#142

Earlier quoted context omitted.

Can you name what new syntax you abhor? I mean, other than [] (){}() being a valid C++ expression [0], C++ hasn't even made any notable sygil-related syntax changes recently. Sure, some keywords were added (auto, constexpr, co_yield...) but I don't see how that leads to "ugly" syntax. [0]: That's a lambda capturing no state, having no template parameters, taking no arguments, with an empty body, finally being called…

Anything with templates, type traits, especially when nested. (The kind of spew you get on an compilation error). Even template struct foo () )>> : std::true_type { }; looks terrible and that's just basic.

You will notice that this is almost valid Rust. (Rust is a very small bit better, not enough to matter.)

In fact, a lot of what the Rust syntax ugly was taken from C++, and it took most of what makes C++ ugly. So the entire discussion is just amusing.

Re: What it feels like when Rust saves your bacon

#143
post #8

This article is super overcomplicated. All it had to say was that rust tells you when you keep reference to on stack variable after it goes out of scope. Context provided adds nothing. I must say - as someone who doesn't use rust - I haven't had this type of issue in years, and when I did it wasn't hard to debug. You get corrupted data, set data breakpoint and in the provided example you will see it being modified by…

Yeah no. In my experience, when several people commit to a common C/C++ codebase this kind of issue become really exhausting when it happens more than once, and the symptoms may be so subtle it's a bitch to debug. Rust lowers your mental load. You spend more time being creative and way less time debugging "obvious" (or not) mechanical problems (reference not-on-stack-anymore variables, use-after-free, concurrent writ…

I find neither C++ nor Rust to be particularly “creative” programming languages because one has to think all the time about two things which are irrelevant for the features of the program - resource management and complicated types.

Rust is even worse than C++ because it highly encourages encoding logic in types and the community loves doing that.

You seem to have almost come to the same conclusion yourself, but then mistakenly assume that the same kind of productivity of a GC language is available in a system language. Nope. Although at least in C++ one can just say “fuck it” during the “creative” prototyping phase, copy most things and still have decent syntax and performance. In Rust you’d have to pepper everything with clone, boxes and (a)rc, so you'd have another mess.

Re: What it feels like when Rust saves your bacon

#144
When I was first learning Rust, it was exactly this sort of lifetime issue that tripped me up and frustrated me, until I finally saw the light and understood how things work.

Yes, the article is overly technical and detailed, but it captures very well the eureka moment of understanding Rust’s memory management. Some aspects are subtle yet profound.

I am always happy to take a little more pain at code-writing and compile-time in exchange for more safety guarantees at run time; Rust is great in this regard.

Re: What it feels like when Rust saves your bacon

#145

Earlier quoted context omitted.

Yeah no. In my experience, when several people commit to a common C/C++ codebase this kind of issue become really exhausting when it happens more than once, and the symptoms may be so subtle it's a bitch to debug. Rust lowers your mental load. You spend more time being creative and way less time debugging "obvious" (or not) mechanical problems (reference not-on-stack-anymore variables, use-after-free, concurrent writ…

> less time debugging I would say it isn't even the debugging. As many of the C++ programmers here have said as you get good at C++ this becomes something that you are vigilant for and it rarely actually gets written. But just the lack of even needing to think about it is a huge load off my mind. When I used to write C++ I never really realized how vigilant I was. Every time I added code into the middle of a function…

And what are you thinking about now?

For me it was what lifetimes and types to use to make my program work. Just as it was in C++, but with a static verification step at the end which most of the time got in my way.

Rust makes lots of sense in high-churn projects or projects which have very high security requirements (like browsers). Otherwise I’d think carefully about using it.

Re: What it feels like when Rust saves your bacon

#146
post #119

Earlier quoted context omitted.

> High quality teams like the Linux kernel team and PostgreSQL, do periodically have serious security bugs that are things Rust would have caught. Safe rust would have caught. If you had to drop into unsafe to do what they did, the serious security bugs would still have happened.

A fair point, though the few security issues in recent years I've looked at were not the kind of thing you would turn to unsafe rust for. But I've certainly not done a broad enough sampling to say what % of cases are like that.

To be fair, I am sure Rust catches a fair amount (compared to C++ which would catch 0). I just think that phrasing rust has having 0 memory errors can be a tad inaccurate.

Re: What it feels like when Rust saves your bacon

#147
post #112
post #61

Earlier quoted context omitted.

Ohh, I got one. Rust is less secure than C++ because it causes people to be overconfident in its security properties. The sharp edges of C++ are a feature that cause people to focus on correctness, not just get it for free.

You jest, but that used to be an argument against making seatbelts mandatory in cars. I suppose people would drive even more safely if there was a sharp metal spike sticking out of the center of the steering wheel.

The great (unintentional?) irony of that argument is that before seatbelts, that was arguably how cars used to be manufactured. Back then, drivers were often killed in car crashes by being impaled on the steering wheel. Those in the passenger seat would die from being hurled through the window. Despite the elevated risk in those older cars, drivers weren't safer --- they were unsafe to such a degree that it formed the argument for mandating seat belts in the first place.

Re: What it feels like when Rust saves your bacon

#148
post #130
post #112

Earlier quoted context omitted.

You jest, but that used to be an argument against making seatbelts mandatory in cars. I suppose people would drive even more safely if there was a sharp metal spike sticking out of the center of the steering wheel.

Hell, this is a current argument some people have against wearing bicycle and motorcycle helmets.

Is it? For bicycle helmets I just know these variants:

1. Wearing a bicycle helmet is unpleasant, so people will cycle less and possibly use other modes of transportation such as cars. The risk of a traumatic head injury may decrease but this is offset either partially or fully by other health risks such as obesity.

2. Other road users in heavier vehicles (e.g. cars) perceive riders wearing bicycle helmets as less vulnerable, and so keep less distance when overtaking them, thus wearing a helmet increases the risk of collision.

I don't think I've ever heard someone say they won't wear a bicycle helmet because it would make them personally drive more dangerously.

I personally strongly oppose mandatory bike helmets. I think one of the reasons so many people own and ride bikes in my country (The Netherlands) is that we don't have mandatory helmets. Making helmets mandatory for people inside cars would also prevent or reduce head injuries (and indeed that is why they are worn by race car drivers) so if we ever introduce mandatory bicycle helmets here perhaps we can introduce mandatory car helmets at the same time, to ensure that people won't just take a car instead.

Re: What it feels like when Rust saves your bacon

#149
post #59

Earlier quoted context omitted.

You often encounter this entire thread of rhetoric when someone wants to put a diversion into the central argument, yeah but it doesn't ____. But Rust does do that, match exhaustiveness, forcing the handling of errors and the type system enables things like CreuSAT [1] using creusot [2] [1] https://news.ycombinator.com/item?id=31780128 [2] https://github.com/xldenis/creusot > Creusot works by translating Rust code to…

You mean like Boost.Units?

Great example of the kind of cherry picking in these conversations. It is insincere and uncharitable, all you did was show your colors. Didn't say everything was exclusive to Rust, while you make no mention on the ground breaking work in CreuSAT. Given as an example of the kinds of things besides memory lifetime tracking that can make Rust code more robust against logical errors.

Re: What it feels like when Rust saves your bacon

#150
post #95

Earlier quoted context omitted.

I see many C++ programmers say stuff like this, and maybe it is the case that studios exist which can do C++ without mistakes related to memory management or sigils and so on, but I also observe that: 1. High quality teams like the Linux kernel team and PostgreSQL, do periodically have serious security bugs that are things Rust would have caught. 2. I see sometimes C++ instructors making the same claims you do and th…

I'd venture that the development slowdown from using rust is closer to 50% than 5%. Even just compile times probably slow down that much, not to mention you have to write (sometimes) as much as 10x code to express yourself. The specific exercise I have in mind is a lockless thread queue. < 20 lines in C .. ~200 lines in Rust.

> The specific exercise I have in mind is a lockless thread queue. Why is this your exercise you have in mind though? This is such a bad argument. Like, yes, if you work at doublylinkedlist.com where your entire job is writing a new linked list implementation every day of the week, Rust might be a bad choice. But that's not what any kind of commercial enterprise actually looks like. If I saw you writing a lockless thread queue at work, I'd tell you to stop wasting time.
Post reply on HN