Live data from Hacker News

Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

opensource.googleblog.com

211–220 of 233 posts

Re: Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

#211
post #79
post #39

Earlier quoted context omitted.

Try Zig as a C replacement.

Does Zig run on everything C can, including weird devices?[0] If the answer is still No, then it can't replace C. 0: https://en.wikipedia.org/wiki/Small_Device_C_Compiler

Zig has been able for a while now to compile to C code, which is part of our bootstrap procedure now, so you can compile that output with an appropriate C compiler and target whatever you want.

We do have plans for adding backends for unconventional targets eventually.

Re: Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

#212
post #210

Earlier quoted context omitted.

By writing: first_name (name: &'a str) -> &'a str you promised the caller that the output is built directly from the input slice. That is your choice. I'll show you later that you didn't have to. Similarly by writing this in Go: func firstName(name string) string you promised the function accepts a string. Then you want to change the semantics (the contract) of the function, break your promise and you complain you ha…

As I said in the previous comment: >Please don't respond by saying "this API was badly designed in the first place!" Most languages don't give you the opportunity to design APIs badly in this particular way. If all APIs were perfectly designed on day one then of course we'd never have to worry about API changes. I did edit in that paragraph ~5 minutes after submitting the comment, so apologies if you missed that. >fn…

> Please don't respond by saying "this API was badly designed in the first place!" Most languages don't give you the opportunity to design APIs badly in this particular way. If all APIs were perfectly designed on day one then of course we'd never have to worry about API changes.

Ok, I agree. But this is just as well a problem for any language that specifies API in some way. So it is really a decades old debate about static typing disallowing to change things easily. I mean, there might always be certain case when the library author has to change the signature because they made it too restrictive. It just happens that Rust allows you to constrain things that might not be constrainable in other languages, so I guess the chances for that happening accidentally are somewhat higher. But generally I like going from more concrete / restricted to more generic when needed rather than the other way round.

> Off topic, but you could do this in both Java and Go via generics.

I don't think so you can achieve same level of flexibility and efficiency at the same time.

Go doesn't have function level generics, so you'd need interfaces and runtime polymorphism as usual (and runtime penalty).

And in Java you cannot add a new interface implementation to a builtin type like String, so the idea of switching from String to any other type won't work. There is much more upfront ceremony needed to add such flexibility (defining custom interface + implementations and using them from the beginning).

Re: Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

#213
post #210

Earlier quoted context omitted.

As I said in the previous comment: >Please don't respond by saying "this API was badly designed in the first place!" Most languages don't give you the opportunity to design APIs badly in this particular way. If all APIs were perfectly designed on day one then of course we'd never have to worry about API changes. I did edit in that paragraph ~5 minutes after submitting the comment, so apologies if you missed that. >fn…

> Please don't respond by saying "this API was badly designed in the first place!" Most languages don't give you the opportunity to design APIs badly in this particular way. If all APIs were perfectly designed on day one then of course we'd never have to worry about API changes. Ok, I agree. But this is just as well a problem for any language that specifies API in some way. So it is really a decades old debate about…

To my mind, the issue is that a substantial portion of lifetime constraints reflect implementation details and not actual domain-level constraints that the programmer specifically wished to enforce. The same thing can of course happen with static type constraints generally, but I think not usually to the same extent.

>Go doesn't have function level generics

Not sure what you mean by this. Go functions can take generic parameters that satisfy a given interface (at compile time). E.g.

    func firstName[T AsBytes](name T) T
(You'd have to define the AsBytes interface yourself.)

>in Java you cannot add a new interface implementation to a builtin type

Yes ok, fair point.

Re: Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

#214
post #194

Earlier quoted context omitted.

I am willing to bet that the type system and the opinionated way of doing things helps a lot here. Anecdata but I found myself very productive with Haskell when I was learning it for grad school, to the point where I knew that if it compiled, it was most likely right. I had similar experiences though not to that degree with Rust with very little time spent on it in comparison to Haskell. I feel a lot more comfortable…

> Anecdata but I found myself very productive with Haskell when I was learning it for grad school, to the point where I knew that if it compiled, it was most likely right. I recently told this to someone. The very next day my Elm code compiled just fine but it had three relatively tricky logical bugs which took me two hours to find and fix. This was a rare enough occurrence that I remember it. Higher cosmic powers to…

Those are always fun! I am a big fan of property based testing for this reason alone!

Re: Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

#215
post #213

Earlier quoted context omitted.

> Please don't respond by saying "this API was badly designed in the first place!" Most languages don't give you the opportunity to design APIs badly in this particular way. If all APIs were perfectly designed on day one then of course we'd never have to worry about API changes. Ok, I agree. But this is just as well a problem for any language that specifies API in some way. So it is really a decades old debate about…

To my mind, the issue is that a substantial portion of lifetime constraints reflect implementation details and not actual domain-level constraints that the programmer specifically wished to enforce. The same thing can of course happen with static type constraints generally, but I think not usually to the same extent. >Go doesn't have function level generics Not sure what you mean by this. Go functions can take generi…

         func firstName[T AsBytes](name T) T
Ok, I stand corrected. Can you define AsBytes for string then?

Re: Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

#216
post #208

Earlier quoted context omitted.

"Color" in this case just means signature. Of course you can't mix signatures - why would you want to? You might as well argue that Rust shouldn't have had any more than a single integer argument to every function. Async in rust essentially desugars to a return trait impl.

That isn't quite true. An async signature forces it's caller to be async as well. This is because of it's semantics. Most signatures don't infect their callers signatures like that. async is qualitatively different in this regard.

No it doesn't. Your can call an async function in rust from anywhere, you just can't await on it outside of an async function.

Re: Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

#217
post #213

Earlier quoted context omitted.

To my mind, the issue is that a substantial portion of lifetime constraints reflect implementation details and not actual domain-level constraints that the programmer specifically wished to enforce. The same thing can of course happen with static type constraints generally, but I think not usually to the same extent. >Go doesn't have function level generics Not sure what you mean by this. Go functions can take generi…

func firstName[T AsBytes](name T) T Ok, I stand corrected. Can you define AsBytes for string then?

> Can you define AsBytes for string then?

Yes. However, because strings in Go are immutable and byte arrays are necessarily mutable, you can’t safely convert strings to byte arrays (or vice versa) without copying, so it would not necessarily be a particularly useful interface.

By the way, this was an interesting discussion. I do see your overall point more than I did at the beginning of it, although I don’t think we completely see eye to eye on the costs/benefits of lifetimes.

Re: Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

#218
post #208

Earlier quoted context omitted.

That isn't quite true. An async signature forces it's caller to be async as well. This is because of it's semantics. Most signatures don't infect their callers signatures like that. async is qualitatively different in this regard.

No it doesn't. Your can call an async function in rust from anywhere, you just can't await on it outside of an async function.

The async function also can't await outside of an async runtime. Which means I cant just call it and expect it to work. I need to wrap the call in an executor of some sort. If the async function doesn't do any awaiting itself then it doesn't even need to be an async function.

So in practice my statement stands.

Re: Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

#219
I really like Rust and all its features, but I have a feeling that people really underestimate the importance of having a fast compiler. Being able to have a subpar compiler error sooner might still make you more productive than having good compiler errors but having to wait for the compiler all the time.

Re: Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022

#220
post #218

Earlier quoted context omitted.

No it doesn't. Your can call an async function in rust from anywhere, you just can't await on it outside of an async function.

The async function also can't await outside of an async runtime. Which means I cant just call it and expect it to work. I need to wrap the call in an executor of some sort. If the async function doesn't do any awaiting itself then it doesn't even need to be an async function. So in practice my statement stands.

But that's true of everything. You can't use a struct except through an "executor" of some sort. Once you've created it, it sits there and does nothing until you exercise it through its methods or other methods that take it. In that case, there's no ambiguity because the type is explicit. I guess the problem is that really `async fn` looks like a function, but isn't really a function, it's a future. The semantics of a future are quite different to the semantics of a function. That's only a problem if you think the semantics of `async fn` should closely reflect a function.

The thing is, once you grok async in rust, other things make sense, like being able to construct futures by implementing `Future` on a struct. You don't actually need `async fn` to do async rust. It's just syntactic sugar, just like await is.

Post reply on HN