News for hackers. Stuff that matters.
Re:Microsoft seeks Rust developers to rewrite core C# code by unclad5968 on Saturday February 03, 2024 @02:35PM (#39243920)
I don't care that it's hard to learn. What turns me off rust is that if I ever make a change that requires a lifetime annotation, I now have to go back through all my code potentially adding lifetime annotations to everything it touches.

I was making a little toy compiler in rust and basically gave up when I wanted to make a change that would have amount to string -> string_view in c++ because in rust I now need to tell the compiler that the String to my &String is going to outlive the struct. Now I understand why it's good but Id rather just let c++ blow my feet off. Maybe once I nail down all the data structures I'll rewrite it in rust.

Re:Microsoft seeks Rust developers to rewrite core C# code by miniupuchaty on Saturday February 03, 2024 @04:06PM (#39244745)
If you're fine with dropping safety you can just make a wrapper around a raw pointer. I wouldn't do it in public library but if it's fine for your cpp code then it's fine for your rust code. You can always drop to the "blow my feet off" level.
Re:Microsoft seeks Rust developers to rewrite core C# code by zozbot234 on Saturday February 03, 2024 @02:38PM (#39243957)
Isn't that why Rc<> and Arc<> exist in Rust? So that you can deal with situations where you don't know the object lifecycle at compile time?
Re:Microsoft seeks Rust developers to rewrite core C# code by merb on Saturday February 03, 2024 @04:36PM (#39244981)
The last few versions made a lot of the lifetimes elided so you can drop them.
Re:Microsoft seeks Rust developers to rewrite core C# code by pdimitar on Saturday February 03, 2024 @08:04PM (#39246458)
Do you have a direct link? I'd love to read more.
Re:Microsoft seeks Rust developers to rewrite core C# code by merb on Sunday February 04, 2024 @06:18AM (#39249371)
Sadly not. But between 1.5x and 1.7x a lit of things changed, especially around traits and there is clippy which actually helps. So our functions barely need lifetimes anymore.
Re:Microsoft seeks Rust developers to rewrite core C# code by winrid on Sunday February 04, 2024 @04:17AM (#39248781)
I feel like this has been this way for at least two years, too?
Re:Microsoft seeks Rust developers to rewrite core C# code by merb on Sunday February 04, 2024 @06:15AM (#39249353)
Well maybe we started with 1.5x or so and especially impl trait‘s made a lot of things easier. We barely have lifetimes in our rust code.
Re:Microsoft seeks Rust developers to rewrite core C# code by pornel on Saturday February 03, 2024 @04:40PM (#39245017)
This effect of <'a> spreading everywhere is very frequently a novice mistake of putting temporary scope-bound loans (AKA references) in structs that aren't temporary views themselves.

People used to C or C++ perspective tend to reflexively (over)use references to avoid copying, but references in Rust are to avoid owning, and not-copying is handled in different ways.

BTW, apart from edgiest of edge cases, &String is a useless type in Rust, because String already stores data "by reference" and is never implicitly copied. For loans it's generally better to deref to &str.

Re:Microsoft seeks Rust developers to rewrite core C# code by imetatroll on Saturday February 03, 2024 @08:03PM (#39246457)
I am a novice when it comes to rust but as I recall the instant you put anything that isn't a scalar type you need lifetimes. Is that what the person you are replying to frustrated with?

How would not copying be handled?

Sorry for the basic questions. Your comment tickles something in my brain that suggests I need to know.

Re:Microsoft seeks Rust developers to rewrite core C# code by telios on Sunday February 04, 2024 @05:48AM (#39249187)
Very rarely do you need to pass around a lifetime-bound struct or enum that isn't _also_ meant to be temporary. (One database pool has database connections lifetime bound, for example, but the pool still owns the connection.) When I do, I generally eat the cost and put it behind a Rc/Arc, where cloning is cheap.

It is 'borrowing' because you don't own it, not because you don't want to clone/copy it. Sometimes it is cheaper to borrow than it is to clone/copy; sometimes it is not.

Re:Microsoft seeks Rust developers to rewrite core C# code by pdimitar on Saturday February 03, 2024 @08:03PM (#39246447)
> and not-copying is handled in different ways

Can you give a few examples?

Re:Microsoft seeks Rust developers to rewrite core C# code by frfl on Saturday February 03, 2024 @09:38PM (#39247015)
I feel like this could be a great in depth blog post...unless such a blog post already exists? It would greatly benefit novices and those who haven't gotten to that stage where this mentality kicks in.
Re:Microsoft seeks Rust developers to rewrite core C# code by tracker1 on Sunday February 04, 2024 @12:58AM (#39247984)
There's a pretty good YouTube video I saw pulling all the types of strings in rust.

I find it confusing still... Been wanting to do a few things that would mean dealing with it streams that could be cp437 or utt8, generally and haven't been quite sure how I want to deal with it.

Re:Microsoft seeks Rust developers to rewrite core C# code by iknowstuff on Sunday February 04, 2024 @07:17AM (#39249659)
Re:Microsoft seeks Rust developers to rewrite core C# code by tracker1 on Sunday February 04, 2024 @03:10PM (#39253878)
I'm thinking I want to convert to/from utf8 at the edges even for the encoding... Namely web/terminal, then the internal interfaces and relay in utf8, then back to co437 for door game interaction.

Basically a BBS door running service, with some extra niceties internally.

Re:Microsoft seeks Rust developers to rewrite core C# code by rightbyte on Sunday February 04, 2024 @05:55AM (#39249228)
This is more or less the reason I don't like adding "const" to member functions in C++, or setting any method or field to anything but public.

Working with the code base gets so annoying if you suddenly want to change something you didn't plan for.

Such changes can have a domino effect through the code.