Live data from Hacker News

Is Rust Web Yet?

arewewebyet.org

111–120 of 183 posts

Re: Is Rust Web Yet?

#111

I spent about the past month learning rust - and decided it just wasn't a usable language for me. I think what it comes down to is that I'm just not that into bondage and discipline from a compiler. Yes, I know, it's trying to make my code 'safe', and I'm horribly cavalier and I should feel bad, but: 1. the borrow checker rejects valid programs, has a lot of corner cases it can't catch, and is in active development 2…

> I spent about the past month learning rust

This is a red flag for your complains: Is VERY likely you believe Rust is wrong, when the fact the problem is that your code is not good.

I know this, my first 3 months starting Rust were thinking between "I'm a failure as developer" and "Rust is wrong" or "What? Why can't do this?". For first time after learning more than 12 languages I was truly in shock. And even, for second time in 20 years, picking a book and PAYING attention to it.

THE major problem with Rust is not, not even close, the borrow checker or that is picky. Is that Rust idioms are not OO idioms, not C/C++ idioms, not PHP idioms, no Java idioms.

Is fairly a simple language, actually, and the productivity is very high (today I code in Rust faster than python, that is still my benchmark on productivity).

What is NOT simple, is that it require several things to "click" and align properly to make the journey smooth.

And that it reveals how much other langs hide for your.

P.D: The problem you say, sometimes are true, but only at first, when the people are not fluent on the lang, or later, when doing seriously advanced stuff.

Not think I bashing you. This experience is common for many in the community, and even very strong developer get the weird experience with Rust. But also is true that when Rust "click" is very, very good!

P.D.2: I bet Rust is much harder the more experience a developer is and the more ingrained some ways are. I teach Rust to some newbies, and the experience for them is far smother.

Re: Is Rust Web Yet?

#112
post #109
post #71

I've spent the last few months porting the guts of a 100 KLOC PHP command-line utility I wrote to Rust. Thanks to the wonderful Rust documentation it's been a mostly painless endeavour. What I've gained as a result: - execution speed (about 3x faster, single-threaded) - better-documented data structures Things I've lost: - ease of iteration - concise, readable code - really smart type inference - a bunch of time thin…

I disagree on the things you've lost. > - concise, readable code Rust code is significantly more readable. Use the type system to your advantage. > - - really smart type inference Rust has really smart type inference too and only rarely ask for an explicit type. I've found that I prefer annotating my types. It adds to documentation and readability. > - a bunch of time thinking about the borrow checker You can use Arc…

Rust has smart type checking. The really smart stuff is (IMO) the beauty of the borrow checker.

In PHP, modern typecheckers can verify that the first element always exists on an array after an emptiness check:

    if ($some_arr) {
        echo reset($arr);
    }
Whereas in Rust you have to explicitly unwrap:

    if !some_vec.empty() {
        print!("{}", some_vec.first().unwrap());
        // .. more code
    }
The Rust version requires you to use your intuition to figure out that `unwrap()` will never panic here.

In my Rust port I consistently rely on the PHP typechecker's knowledge of the equivalent code when using `unwrap()`, because it knows which array fetches are safe.

> At the cost of introducing a bug/technical debt.

At the cost of shipping a product!

-------

Edit: user ibraheemdev proposes this Rust equivalent which more closely matches the idealised pseudocode, and type-checks:

    if let [first, ..] = &some_vec {
        print!("{}", first);
        // .. more code
    }
It's preferable IMO to

    if let Some(first) = some_vec.first() {
because the latter relies on a property of a non-empty vec, and checks that property, rather than checking the non-emptiness of the collection.

Re: Is Rust Web Yet?

#113
post #71

I've spent the last few months porting the guts of a 100 KLOC PHP command-line utility I wrote to Rust. Thanks to the wonderful Rust documentation it's been a mostly painless endeavour. What I've gained as a result: - execution speed (about 3x faster, single-threaded) - better-documented data structures Things I've lost: - ease of iteration - concise, readable code - really smart type inference - a bunch of time thin…

> Things I've lost:

> - ease of iteration

> - concise, readable code

Ouch... then it's a big nope for me.

Re: Is Rust Web Yet?

#114
post #112
post #109

Earlier quoted context omitted.

I disagree on the things you've lost. > - concise, readable code Rust code is significantly more readable. Use the type system to your advantage. > - - really smart type inference Rust has really smart type inference too and only rarely ask for an explicit type. I've found that I prefer annotating my types. It adds to documentation and readability. > - a bunch of time thinking about the borrow checker You can use Arc…

Rust has smart type checking. The really smart stuff is (IMO) the beauty of the borrow checker. In PHP, modern typecheckers can verify that the first element always exists on an array after an emptiness check: if ($some_arr) { echo reset($arr); } Whereas in Rust you have to explicitly unwrap: if !some_vec.empty() { print!("{}", some_vec.first().unwrap()); // .. more code } The Rust version requires you to use your in…

[deleted]

Re: Is Rust Web Yet?

#115
post #112
post #109

Earlier quoted context omitted.

I disagree on the things you've lost. > - concise, readable code Rust code is significantly more readable. Use the type system to your advantage. > - - really smart type inference Rust has really smart type inference too and only rarely ask for an explicit type. I've found that I prefer annotating my types. It adds to documentation and readability. > - a bunch of time thinking about the borrow checker You can use Arc…

Rust has smart type checking. The really smart stuff is (IMO) the beauty of the borrow checker. In PHP, modern typecheckers can verify that the first element always exists on an array after an emptiness check: if ($some_arr) { echo reset($arr); } Whereas in Rust you have to explicitly unwrap: if !some_vec.empty() { print!("{}", some_vec.first().unwrap()); // .. more code } The Rust version requires you to use your in…

Rust noob here but couldn't you write

  if let Some(element) = some_vec.first() {
    println!("{}", element); 
    // .. more code
  }
and avoid the unwrap and the empty check?

Edit: Added a `let` I had forgotten.

Re: Is Rust Web Yet?

#116
post #112
post #109

Earlier quoted context omitted.

I disagree on the things you've lost. > - concise, readable code Rust code is significantly more readable. Use the type system to your advantage. > - - really smart type inference Rust has really smart type inference too and only rarely ask for an explicit type. I've found that I prefer annotating my types. It adds to documentation and readability. > - a bunch of time thinking about the borrow checker You can use Arc…

Rust has smart type checking. The really smart stuff is (IMO) the beauty of the borrow checker. In PHP, modern typecheckers can verify that the first element always exists on an array after an emptiness check: if ($some_arr) { echo reset($arr); } Whereas in Rust you have to explicitly unwrap: if !some_vec.empty() { print!("{}", some_vec.first().unwrap()); // .. more code } The Rust version requires you to use your in…

You can usually use pattern matching to get around a check followed by an unwrap. I would rewrite your example as:

    if let [first, ..] = &some_vec {
        print!("{}", first);
        // .. more code
    }

Re: Is Rust Web Yet?

#117
post #112
post #109

Earlier quoted context omitted.

I disagree on the things you've lost. > - concise, readable code Rust code is significantly more readable. Use the type system to your advantage. > - - really smart type inference Rust has really smart type inference too and only rarely ask for an explicit type. I've found that I prefer annotating my types. It adds to documentation and readability. > - a bunch of time thinking about the borrow checker You can use Arc…

Rust has smart type checking. The really smart stuff is (IMO) the beauty of the borrow checker. In PHP, modern typecheckers can verify that the first element always exists on an array after an emptiness check: if ($some_arr) { echo reset($arr); } Whereas in Rust you have to explicitly unwrap: if !some_vec.empty() { print!("{}", some_vec.first().unwrap()); // .. more code } The Rust version requires you to use your in…

[deleted]

Re: Is Rust Web Yet?

#118
post #112
post #109

Earlier quoted context omitted.

I disagree on the things you've lost. > - concise, readable code Rust code is significantly more readable. Use the type system to your advantage. > - - really smart type inference Rust has really smart type inference too and only rarely ask for an explicit type. I've found that I prefer annotating my types. It adds to documentation and readability. > - a bunch of time thinking about the borrow checker You can use Arc…

Rust has smart type checking. The really smart stuff is (IMO) the beauty of the borrow checker. In PHP, modern typecheckers can verify that the first element always exists on an array after an emptiness check: if ($some_arr) { echo reset($arr); } Whereas in Rust you have to explicitly unwrap: if !some_vec.empty() { print!("{}", some_vec.first().unwrap()); // .. more code } The Rust version requires you to use your in…

> The Rust version requires you to use your intuition to figure out that `unwrap()` will never panic here.

You should not use `unwrap` in a production product. It's there for prototyping and I think it's a mistake they have it (though the language already requires a good upfront time investment as it is). Use `?` and have your error propagate accordingly to the top of the chain. Have your own error types and convert from other error types.

    if !some_vec.empty() {
        print!("{}", some_vec.first().unwrap());
        // .. more code
    }
I don't know why you would check the first element of a vector. Use Rust type system to your advantage, and don't "convert" PHP code into Rust. Re-design your program. Also you don't need to check that the Vector is empty if you are using "first". "first" returns an Option with None if your vector is empty. My guess is that you have yet to exhaust the idioms Rust offers and approaching it in a PHP-like manner.

> > At the cost of introducing a bug/technical debt.

> At the cost of shipping a product!

Okay!

Re: Is Rust Web Yet?

#119
post #71

I've spent the last few months porting the guts of a 100 KLOC PHP command-line utility I wrote to Rust. Thanks to the wonderful Rust documentation it's been a mostly painless endeavour. What I've gained as a result: - execution speed (about 3x faster, single-threaded) - better-documented data structures Things I've lost: - ease of iteration - concise, readable code - really smart type inference - a bunch of time thin…

The 3x speed increase is interesting. Do you have any further details?

Re: Is Rust Web Yet?

#120
post #109
post #71

I've spent the last few months porting the guts of a 100 KLOC PHP command-line utility I wrote to Rust. Thanks to the wonderful Rust documentation it's been a mostly painless endeavour. What I've gained as a result: - execution speed (about 3x faster, single-threaded) - better-documented data structures Things I've lost: - ease of iteration - concise, readable code - really smart type inference - a bunch of time thin…

I disagree on the things you've lost. > - concise, readable code Rust code is significantly more readable. Use the type system to your advantage. > - - really smart type inference Rust has really smart type inference too and only rarely ask for an explicit type. I've found that I prefer annotating my types. It adds to documentation and readability. > - a bunch of time thinking about the borrow checker You can use Arc…

> Rust code is significantly more readable.

You should put down the Rust kool-aid. Rust is incredibly hard to read due to its sigil and abbreviation heaviness.

Post reply on HN