Live data from Hacker News

My Struggles with Rust

compileandrun.com

241–250 of 329 posts

Re: My Struggles with Rust

#241
post #123

Earlier quoted context omitted.

As someone who's been doing C++ for a close to few decades I's challenge you on that. In C++ you need to understand: Exceptions(and the runtime/memory costs they incur by pulling in RTTI) ERRNO(on relevant *nix platforms) Lifetimes tied to objects when things fail(this is a big one) Plus any library-specific hackery(I've seen raw strings as errors before) In contrast I've been writing Rust for ~1.5 years now and each…

Exceptions don't need RTTI and have only runtime cost when thrown.

> Exceptions don't need RTTI and have only runtime cost when thrown.

No, they add extra control flow edges, which inhibit optimizations, affecting runtime performance. This is a lot of the reason why unwinding is optional in Rust.

Re: My Struggles with Rust

#242
post #4

My main gripe with Rust so far has been the unnecessary profusion of Result types, making it hard to process and forward errors. Case in point: the example in the article from the rust documentation that converts errors to strings just to forward them: https://doc.rust-lang.org/book/error-handling.html#the-limit... In practice, I find a type like Google's util::StatusOr ( https://github.com/google/lmctfy/blob/master/…

I think having Result alone does not make error handling complicated, but having different error types for each operation (and concrete result) instead of using one generic error type for all of them does by pushing the job of unifying erros towards the user. Go works around the problem by Error being an interface, which means any function can return any kind of error without needing to transform it to another form.…

> However Go benefits from the Garbage Collector here - I totally understand why Rust libraries don't want to return heap allocated errors.

This doesn't have to do with the GC or lack thereof. Instead it's part of the philosophy of zero-cost abstractions: idiomatic C libraries don't require heap allocations to return errors, so neither does Rust.

Re: My Struggles with Rust

#243

One thing I've found with rust is that you struggle struggle struggle trying to do a simple task, and then finally someone says "Oh, all you need to do is this". Rust has already reached the point where it leaves the world behind. Only the people who have been there since the early days really understand it, and getting into rust gets harder and harder as time goes on. Yes, there's some awesome documentation, and the…

These are the exact same complaints of students learning to program for the first time.

Have you tried functional programmng? Lisp? Ocaml? The complaints of newbie functional programmers are also nearly the same.

The "struggle" is necessary. If there is no struggle, there is no learning of fundamentally new approaches you are not yet comfortable with.

See it as part of the training regimen that lets people emerge as stronger programmers on the other side.

Re: My Struggles with Rust

#244

Rust's aversion to exceptions is exactly like Go's aversion to generics - a strongly held position that doesn't actually make anyone's life easier.

We nearly had a hostile language fork over mandatory unwinding. It is not something that the language team decided and refuses to acknowledge. Rather, we had to respond to the demands of our embedded users.

Re: My Struggles with Rust

#245
post #225

Earlier quoted context omitted.

As someone whose first introduction to C was through K&R, and still has that torn and tattered copy on his bookshelf, the idea that we're still recommending K&R as "one of the best books about C" only validates arcticbull's (sadly-downvoted) point.

K&R is so clearly written that I was able to understand it as a sixth grader. (At least, I felt like I did; subsequent events later proved that I did not understand pointers, but I don't think it was K&R's fault that a sixth grader didn't understand.) That's why it's still being recommended and the much thicker tomes also purporting to teach the C language have been forgotten. It's probably the same reason that your…

> It's probably the same reason that your copy is torn and tattered.

Er, well I was also using it as a mousepad for about three years...

Re: My Struggles with Rust

#246
> Only if the programmer chooses to not handle exceptions, which is bad practice.

So basically you're telling me that the example Python script is actually considered bad practice. I didn't saw that coming, I thought it was just grrrreat without any checking. Keep the wisdom coming!

> In Python you can catch an exception and continue the operation in a different manner.

But he doesn't do that.

> Well, you seem to not know a lot about exception handling in Python, so I hope I was at least a little helpful.

snickers

Come on you can't be saying this seriously?

Re: My Struggles with Rust

#247

Earlier quoted context omitted.

Sounds like an aversion to me. By the time Go was developed, there was no doubt in my mind that generics (or some kind of polymorphism along those lines) were an essential feature for any new statically typed programming language. The fact that Go's developers "don't feel an urgency for them" to me makes it sound like they are living in the 1980s.

> were an essential feature Do you mean, "this feature is required for me to write code in that language"? Or do you mean, "this feature is required for any project in the language to flourish"? If the former, why do you think your preferences generalize? If the latter, how do you explain the large number of successful Go projects? Are we all stuck in the 1980s? And if so, what does that even mean?

>And if so, what does that even mean?

The lack of generics in Go simply means that you will for common algorithms and functions end up with either of these scenario's:

1. You were forced to duplicate code under a different name with a different type signature (even though the body would be identical)

2. You are forced to use the 'empty interface' which negates the advantages of static type-checking (and seriously: why isn't it the default when you open an accolade?)

Not having generics in a statically typed language means you combine the disadvantage of static typing ('having to specify types and doubling the cognitive complexity of the language with a special type syntax') with ('not having the compiler be able to check the validity and risk run-time type errors, ie. things like cast exceptions').

>If the former, why do you think your preferences generalize?

Generics is not a platonic ideal such as 'object oriented programming'. Type systems are as solid as math itself. And just like Math there are multiple systems with different trade-offs in how expressive they are. This expressivity is not subjective! One type system can be strictly more expressive than another type system. Consider this pseudo-code without any type annotations:

    def example(a,n)
        return a.something(n)
In a dynamically typed language such as Ruby, Erlang, Python or JS there are programs that would call this method that would make it throw an exception during run-time. For example because it doesn't know how to do '.something' on the provided argument.

The challenge: It barfs during run-time and we want it to barf during compile-time.

Now imagine all the possible usages of this method in a dynamically typed language that would be provable correct. All the potential combinations of a's and n's that would not make it barf. How many of them are legal Java, Haskell, C# or Go programs? (some, most, some, few)? The goal of a static system is to barf during compile-time. Not to exclude valid, legal programs just because the language author thinks type systems are hard to implement.

Whenever you can write provable correct code, that a type-system is complaining about: how is that not a bug?

>If the latter, how do you explain the large number of successful Go projects?

1. The projects are successful because of the people who make them

Well for starters by not assuming that people who program in Go are completely incompetent drooling idiots who are only able to deliver working code because Go is so great. As if the same developers wouldn't have successful projects right now, if Go didn't exist.

2. Any language released by a famous language author at Google will get a large minimum cult following by default

Much like with Angular who releases something has a strong impact on the adoption, regardless of the actual quality of the product, language design or implementation. I'm convinced the same set of programmers would be more productive in other languages. I'm also not surprised they themselves aren't aware of it.

3. Go has nice competitive features, the type system just isn't one of them.

Finally, Go isn't all shitty, for example, it has a very nice IO and concurrency model and ever since it finally got a precise garbage collector, one could finally use it long-running processes.

4. Your logic has clear type errors that a strong type system would help you catch

The existence of successful Go projects isn't an indication of _anything_. With the same logic you could argue VHS is superior to Betamax or that that Kanye is a talented musician. It's like the Silicon Valley variant of religious logic of 'moral people don't get sick'. Sometimes people, projects or products are not successful because they did everything the right way! Sometimes they just get lucky. Sometimes they just plain conspire against civilisation and cheat. Sometimes the things they did correctly ended up being more important the the things they did wrong. Sometimes they just get to announce on a bigger stage than somebody else.

> Are we all stuck in the 1980s? And if so, what does that even mean?

It means that there has been a large research initiative since the 1980's in software verification but because science is hard and thinking is hard and we are all getting paid anyway, we rather prefer to cargo-cult, bike-shed and gloat about our own ignorance. Because what you haven't learned yet is hard and what you already know is easy, even if it's all wrong.

It doesn't help that most of the academic researchers don't care enough about engineering to turn their research into actual production tools (with a few exceptions).

But i'm starting to warm up to the common notion that all progress in programming language design comes not from people learning, but from generations of developers eventually dying of old age. There is just too much money to go around for developers to not act like spoiled ignorant little children, and as a result most technology is just fundamentally broken and for no good reason.

Re: My Struggles with Rust

#248
post #164

Earlier quoted context omitted.

Exceptions actually can need RTTI, though not necessarily all of the RTTI that things like provide. For some details, see the -fno-rtti flag for GCC, for which the documentation says[1]: Disable generation of information about every class with virtual functions for use by the C++ runtime type identification features (`dynamic_cast' and `typeid'). [...] Note that exception handling uses the same information, but it wi…

That is a compiler specific implementation, the ANSI C++ standard doesn't require it.

The ANSI C++ standard requires exceptions in the first place. The moment we start talking about disabling them, we're not talking about standard C++ anymore.

Re: My Struggles with Rust

#249
post #97

Earlier quoted context omitted.

I'd expect 'on_error' to take a function as a callback, not a string. But yes, a better named function could be added

Perhaps or_die, similar to Perl?

Yep, this is what I always wanted it to be! But maybe or_panic would be better. Naming things is hard.

Re: My Struggles with Rust

#250
post #247

Earlier quoted context omitted.

> were an essential feature Do you mean, "this feature is required for me to write code in that language"? Or do you mean, "this feature is required for any project in the language to flourish"? If the former, why do you think your preferences generalize? If the latter, how do you explain the large number of successful Go projects? Are we all stuck in the 1980s? And if so, what does that even mean?

>And if so, what does that even mean? The lack of generics in Go simply means that you will for common algorithms and functions end up with either of these scenario's: 1. You were forced to duplicate code under a different name with a different type signature (even though the body would be identical) 2. You are forced to use the 'empty interface' which negates the advantages of static type-checking (and seriously: wh…

I think you kind of missed my point, and crucially, missed that I was specifically questioning usage of the word "essential." You very clearly read far more from my comment than was said or implied. See: https://news.ycombinator.com/item?id=14286020

Personally, I think a lot of the language you chose to use in that giant wall of text was quite unfortunate. I'm not interested in being a party to your ax grinding.

Post reply on HN