Live data from Hacker News

My favorite Rust function

blog.jabid.in

91–100 of 197 posts

Re: My favorite Rust function

#91
post #79

Earlier quoted context omitted.

Yes, to do anything interesting, you need to implement the Drop trait, which causes interesting behavior to happen here.

An example of the implementation is all that's missing from the blog post.

https://doc.rust-lang.org/stable/std/ops/trait.Drop.html

Re: My favorite Rust function

#92

Gotta admit, that really is a cute example. However, I was a bit surprised when the author described Go as "unacceptably crippled." What is he referring to?

Go is simple to the point where it annoys a lot of programmers, especially programmers who like to do fancy stuff with their programming language (the kind of person that's attracted to Rust, for instance).

Re: My favorite Rust function

#93
post #55

Earlier quoted context omitted.

Interesting how developer views can differ. Someone describes Go as "unacceptably crippled" while Uber engineering has 1500 microservices written in Go, making it their primary language. https://news.ycombinator.com/item?id=21226347

These are orthogonal points. Linux Kernel is all in C and possibly drives the world. Doesn't mean it's safe and amazing.

C was the only sensible choice back then.

Uber on the other hand has many languages available yet picked Go. So they certainly don't think it is "unacceptably crippled".

Re: My favorite Rust function

#94
post #51

Earlier quoted context omitted.

Sure, and my opinion is that this is a very shallow takeaway. My whole comment is just my opinion.

It is crippled admittedly by the authors themselves. The error checking pattern, no generics etc. are all to keep it "simple" yet are things most other programming languages have. Have you used Rust ? The borrow checker makes a lot of sense.

I feel like I shouldn’t have to answer this question, but Yes, of course I’ve used Rust. Why do you question this? I said nothing about Rust at all, other than that I like it, and whether Rust is good or not has little to do with Go being “crippled.”

But of course, Rust is not flawless. In fact up until recently it was kind of annoying, before non-lexical lifetimes became a part of the language. It’s also a very large and complex language compared to Go. This is not unilaterally a bad thing, but just as every line of code comes at a cost, so to does every language feature, and if enough language features fail to pay the rent your programming language will end up feeling bloated.

What Go lacks is exactly its strengths. If you criticize C for not having Java-style exceptions, people will look at you funny. There is some divide in the community over error handling but I defend that Go’s verbose and stupid error handling pattern is my favorite part of the language, and changed how I code inside and outside of Go. I also appreciate Go’s simple but effective patterns for composition-based object oriented programming, and for having a decent concurrency model (not that it is without flaws: the limitation of Go’s memory safety is definitely an issue here.)

Everything comes at a cost. The borrow checker brings immense promise for security, but that does not mean other approaches to memory safety or language design are suddenly obsolete. It’s more complicated than that, and I consider failure to understand this to be a sign that someone is not keeping an open mind.

Re: My favorite Rust function

#95

let x = String::from("abc"); std::mem::drop(&x); std::mem::drop(&x); std::mem::drop(&x); std::mem::drop(&x);

FWIW, that won't compile because std::mem::drop requires ownership of the object being passed; your code is trying to pass a reference instead.

Re: My favorite Rust function

#96
post #55

Earlier quoted context omitted.

Interesting how developer views can differ. Someone describes Go as "unacceptably crippled" while Uber engineering has 1500 microservices written in Go, making it their primary language. https://news.ycombinator.com/item?id=21226347

These are orthogonal points. Linux Kernel is all in C and possibly drives the world. Doesn't mean it's safe and amazing.

[deleted]

Re: My favorite Rust function

#97
post #22

> or making the language unacceptably crippled like Go Gotta say, I lost a lot of respect for the author at this point. It’s not like I don’t love Rust - quite the contrary - but if the only takeaway from Go for you is that it is “unacceptably crippled” then I feel you have missed a lot of insight. Go has been one of my languages of choice for over half a decade now, and for good reason.

I work with Rust only these days, it’s really an awesome language and I wish everyone working with system languages would switch to Rust. Yet, I find Golang to be a much clearer language to read (and I read a shit ton of code). I hope they don’t add generics, but I wish they would options, results, sum types in general, redeclaring variables, the ? Operator, etc.

Re: My favorite Rust function

#98

let x = String::from("abc"); std::mem::drop(&x); std::mem::drop(&x); std::mem::drop(&x); std::mem::drop(&x);

FWIW, that won't compile because std::mem::drop requires ownership of the object being passed; your code is trying to pass a reference instead.

This code compiles just fine. It doesn't do anything since immutable references are Copy, and so dropping them doesn't do anything.

https://play.rust-lang.org/?version=stable&mode=debug&editio...

Re: My favorite Rust function

#99

let x = String::from("abc"); std::mem::drop(&x); std::mem::drop(&x); std::mem::drop(&x); std::mem::drop(&x);

FWIW, that won't compile because std::mem::drop requires ownership of the object being passed; your code is trying to pass a reference instead.

This should compile, &T is Copy and so it will not really do anything, but it will still compile.

On my phone so I can’t triple check, but there’s no bound on T, you can pass in any type.

Post reply on HN