Live data from Hacker News

Welcome to Comprehensive Rust

google.github.io

111–120 of 204 posts

Re: Welcome to Comprehensive Rust

#111

Earlier quoted context omitted.

It does not guarantee, but it is actually quite hard to cause a memory leak by accident, because at the same time Rust makes creating cycles hard.

I actually haven't tried this... do you know off the top of your head what it takes to make a cycle with Rc? It should not be possible with normal borrows (and safe Rust) since they're statically checked to be acyclic.

And when using C libraries / FFI, there are a lot of tricky things going in, it is much easier to leak in unsafe land.

Re: Welcome to Comprehensive Rust

#112
post #109

Unrelated: but why does Google use Kotlin(for developing Android apps) and Rust when they have a nice little language in Go. Genuinely curious: Is Go not a good fit for developing Android apps(Is targeting JVM the concern?) or system programming(using Rust in Android systems), what does it lack?

Most system APIs are only exposed in the JVM environment without native equivalents. You do need a JVM language to do anything meaningful. Either that, or you'll have to use JNI.

Re: Welcome to Comprehensive Rust

#113
post #39

It's kind of surprising to see that Rust is so rapidly accepted by wide range of developers. Unfortunately I'm from DataScience field, so I cannot see much motivation to learn Rust, but I am considering learning it, because language itself seems exciting! Is there anyone on HN who is from DataScience field like me and has learned Rust? It would be much appreciated if you could share the experience.

I've had some success with polars.

But: I'm not well versed in Python Pandas either, and my rust is better than my python (though Ruby is my daily language, so I'm very used to dynamic languages). The thing I miss most is the rapid REPL workflow in Python, where I work out the pipelines, filters, map-reduce and so forth, on the interactive REPL and then extract that into python scripts.

The polars scripts that I worked with, were small enough and the builds are incremental, therefore fast: milliseconds. But the build-step inbetween is somewhat clumsy when exploring data.

But the end-results are just so extremely cleaner, saner and especially faster that it certainly is worth it. I worked on a dataset where crunching it in python took upwards of 14 hours, and the polars under an hour. That feedback loop alone is worth days of fighting the borrow-checker. And that immediate feedback by the compiler/checker "this column isn't guaranteed a String, it could be missing, could be unparsable; deal with this now" is priceless. Too often did I have some ETL run for 8 hours, and then choke on some column that I swore should've been UTF8. Fix it, and re-run. Wasting 8 hours. A type-checker in ETL/data flows is priceless.

Edit: to be clear: I am developer. Not datascience. But I do need to understand my users, my business, my market. Developer/devops today do need to crunch large datasets: at least I do.

[1] https://www.pola.rs/

Re: Welcome to Comprehensive Rust

#114
post #56

Earlier quoted context omitted.

Rust is a safer C/C++. If you'd never consider writing anything in C/C++ (i.e. low-level code where performance is essential), you'll never use Rust.

That’s underselling it quite a lot. Rust has a number of features (ergonomic and technical) and some really nice language design that permits writing quite “high-level” code. Personally, having a compiler and type system as powerful as Rusts makes it worthwhile alone.

This. Rust is quite pleasant to use and once some barriers are overcome quite productive. Not Python fast dev speed, but easily Go levels of productive for me. I rarely fight the borrow checker unless building tricky data structures. It will still stump me once in a while with lifetimes, but the trade off is so worth it to have memory safety guarantees and know there are no foot guns like C code would have. And if you are just cranking something out you can write code a little less idiomatically and of efficiently for quick scripts or smaller throwaway CLI tools. Rust prefers a more functional style but you can just as easily make it not so.

Re: Welcome to Comprehensive Rust

#115
post #96
post #92

Earlier quoted context omitted.

Cryptonite? I am... not sure it means what you think it means.

I only know this word from context. And it is actually written with "k". So what does it mean? (Context/my reasoning: If you have to prove that you are a smart programmer you can't stay away from learning Rust. Hence it is kryptonite.)

You're looking for something like honey that no one can resist - kryptonite is Superman's weakness; he avoids it at all costs.

Re: Welcome to Comprehensive Rust

#116
post #109

Unrelated: but why does Google use Kotlin(for developing Android apps) and Rust when they have a nice little language in Go. Genuinely curious: Is Go not a good fit for developing Android apps(Is targeting JVM the concern?) or system programming(using Rust in Android systems), what does it lack?

[deleted]

Re: Welcome to Comprehensive Rust

#117
post #73
post #63

Earlier quoted context omitted.

Is that really due to the language or that we collectively have become better in structuring software projects?

You can trust the compiler to yell at you when you break many invariants that would be tacit and implicit in C and even in C++ (even with best practices followed) which can make you much more productive when you’re just familiarizing yourself with a codebase. Also, the two aren’t necessarily mutually exclusive. Many people learning the language have reported being surprised by the way Rust seems to make "doing things…

I’ve had that experience. I had to write code for a complicated reference counted datastructure. The code was a mess at first because I was approaching it the wrong way, but once I understood it well enough to write it correctly all the pieces fell into place. Extraneous complexity was eliminated, and all the possible mistakes turned out to be impossible. The resulting code is so simple and straight forward that anyone can read it and see that it is correct. And as is traditional, the first time it compiled it was correct in all respects.

Re: Welcome to Comprehensive Rust

#118
post #87
post #71

Earlier quoted context omitted.

I'm well aware of that attack, it's quite cute, but if you don't trust the host not to serve you a backdoored binary then you've already lost.

And where is this trust supposed to come from? I downloaded the thing manually, looked at the scripts, ran the binary in a sandbox, it seemed to be OK. Right, I'll recommend that everyone just curl | bash's it ... I think the worst thing about this is that Rust is fashionable, so encouraging inexperienced devs think that these dangerous practices are just fine. Look around at how many n00b projects now suggest doing…

The bash timing exploit makes everyone focus just on how cleverly evil it can be, and forget the big picture that it's about trusting the Rust org not to screw you.

(BTW, you can run `curl | sh` in a VM or with a modified bash to intercept the code and catch the bash script in the act, so it's not actually as sneaky as people believe).

If you think the Rust org is going to pwn you in a clever sneaky way, then you can't use Rust or any Rust-containing products.

In the end, you're pulling hundreds of MBs of binaries that you won't review, they're compiled from over 15 million lines of code that I don't believe you'd ever review either. Reviewing just the first 10 lines of code gives you nothing. A smoke test in a sandbox is also worthless, since a binary could detect being run that way, or delay the attack, or attack by specifically miscompiling your code (see Reflections on Trusting Trust).

In the end, you have to trust the Rust org, all of it.

Re: Welcome to Comprehensive Rust

#119
post #86

I still play with Rust (and Zig), but I have decided to put my work efforts into SPARK[1], the subset of Ada, for high-integrity software and formal verification. I know AdaCore and Ferrous Systems are collaborating in trying to bring a lot of Ada/Spark's capabilities to Rust, but this is still going to be some time. Ada has a longer legacy in this game. I am working on safety critical control systems and there is a…

what resources can you suggest to learn formal verification and implement it to make high integrity fault tolerant services? I am quite intrigued by AdaCore. Want to try it out. I dont know much about Formal Verification.

Re: Welcome to Comprehensive Rust

#120
post #109

Unrelated: but why does Google use Kotlin(for developing Android apps) and Rust when they have a nice little language in Go. Genuinely curious: Is Go not a good fit for developing Android apps(Is targeting JVM the concern?) or system programming(using Rust in Android systems), what does it lack?

I dont have first hand knowledge, but I've been in the space for 10 years and wrote Go, Java, Kotlin, so here is my take.

Kotlin made a huge effort to stay compatible with Java. You can call Kotlin code from Java and Java code from Kotlin, so orgs could migrate their apps piece by piece. The only real incompatibilities that I've experienced were when going from C code via JNI into Kotlin. All sorts of really weird issues creep up.

There was no boiling the ocean in any of the large apps I worked on at Amazon and Meta - just add Kotlin and see how it goes, it's a really easy sell to tech VPs. First we added Kotlin just for the unit tests, then for small features and eventually with Google releasing Jetpack with Kotlin extensions, for all new apps and features.

Kotlin also improved upon existing painpoints in Java and provided a ton of syntactic sugar for things that were tedious in Java. For example, proper get/set syntax for fields, data classes with autogenerated equals/hashcode, explicit nullability for types, val with 'final' semantics to get rid of all the final variables, fields in interfaces, top level functions, etc. All the functional stuff in it is nice too.

Go is much leaner than Kotlin. The VM or performance is not an issue - Kotlin generates entire classes for simple syntax, to make things convenient and compatible, but the bytecode is pretty bloated.

I imagine that Google had sufficient resources to make a GoJava translation layer (though Go would have needed generics) but transitioning a huge API like Android is already a large effort, and if the language isn't fully compatible with the existing code, it would have added an order of magnitude of complexity, so Kotlin was a much easier sell.

In my opinion, migrating to Dart would have been more practical than Go (as evidenced by Flutter), so thats the real head-scratcher. It would have been easy for Java devs to learn Dart because the OOP concepts translate directly.

Other factors:

Google already had a relationship with JetBrains because of Android Studio.

The Oracle Google lawsuit was happening at the time and I speculate that Google needed to show to Oracle they can move off of Java. Kotlin happened to be available.

Post reply on HN