News for hackers. Stuff that matters.
Re:Rust Is Hard, Or: The Misery of Mainstream Programming by blub on Friday June 03, 2022 @06:13AM (#31606407)
How you feel relates to you and your preferences and doesn't really say anything about Rust versus let's say Go.

Is your software more performant and does this translate to additional customers or reduced costs? Is your software more stable and does this result in reduced support costs or happier customers?

Testing effort is likewise not a decisive matter. In fact it's quite likely that what one wins time-wise on the testing side is lost on the development side.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by skohan on Friday June 03, 2022 @06:59AM (#31606719)
Not the person you're responding to, but imo the main thing missing from Go is ADT's. After using these in Rust and Swift, a programming language doesn't really feel complete without them.

That said, I think Go's simplicity has a lot of advantages over Rust for a great many use-cases. Imo Rust almost feels like a prototype for a great language which will finally get ownership-based memory management right. The goals of the language are admirable, and the tooling is great, but it's such a complex language once you start getting into topics like lifetimes and async.

I think it shines for certain use-cases where the tradeoffs it makes genuinely add value, but in a lot of ways I think it's more of a niche language for people who love esoteric programming topics rather than something with the potential to go truly main-stream.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by CraigJPerry on Friday June 03, 2022 @12:08PM (#31610253)
>> the main thing missing from Go is ADT's. After using these in Rust and Swift, a programming language doesn't really feel complete without them

What are the differences between an ADT (plus pattern matching i’d reckon?) in Rust/Swift vs the equiv in Go (tagged interfaces + switch statement)?

One has exhaustive matching at compile time, the other has a default clause (non exhaustive matching), although there’s an important nub here with respect to developer experience; it would be idiomatic in Go to use static analysis tooling (e.g. Rob Pike is on record saying that various checks - inc this one - don’t belong in the compiler and should live in go vet). I’ve been playing with Go in a side project and using golint-ci which invokes https://github.com/nishanths/exhaustive - net result, in both go and rust, i get a red line of text annotated at the switch in vscode if i miss a case.

Taking a step back, there isn’t a problem you can solve with one that you can’t solve with the other, or is there?

To take a step further back, why incomplete?

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by skohan on Friday June 03, 2022 @12:38PM (#31610602)
I'm not a go expert, but imo the main difference is ergonomics and clarity. Rust/Swift style ADT's plus pattern matching gives you a very concise and readable way to declare and use sum-types, and the Go way seems to have more boilerplate.

Also with Rust for instance you have more robust pattern matching. So you don't have to match only on type, you can match on complex criteria (i.e. foo is a Circle, with foo.radius < 10).

I find this type of programming very expressive and easy to reason about.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by CraigJPerry on Friday June 03, 2022 @04:45PM (#31613394)
>> I'm not a go expert

Yeah me neither, i’ve just been dabbling for fun recently. I’ve been dabbling with rust for longer

>> the Go way seems to have more boilerplate

    …
    switch t := s.(type) {
    case Circle:
      if t.radius < 10 {
        fmt.Println("the rust syntax for this is sweeter")
      }
    …
https://go.dev/play/p/s4TTZeo7Gse

Definitely less boilerplate in the rust version, but i don’t think i go along with it being incomplete or less clear.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by skohan on Friday June 03, 2022 @09:08PM (#31615788)
I think this is less clear than. The rust/ swift version.
Re:Rust Is Hard, Or: The Misery of Mainstream Programming by CraigJPerry on Saturday June 04, 2022 @03:38AM (#31617973)
That’s fascinating, what would you say obscures clarity?

Go: https://go.dev/play/p/s4TTZeo7Gse

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

For me, i reckon the Go type machinery is more verbose in this case, e.g. the isShape method to tag Circle as a shape - that just feels awkward to me.

The cyclomatic complexity is identical for both though.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by skohan on Saturday June 04, 2022 @08:36AM (#31619594)
Yeah exactly, imo the way the Go version requires you to declare an interface, in this case with a no-op method essentially acting as a tag, and declare conformance on your types is quite noisy and feels like a hack.

Also I prefer with Rust-style sum types that the declaration happens in one place. In the Go version your Shape types could be scattered around all over the place, which makes it harder to parse and understand if you're reading unfamiliar code.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by preseinger on Sunday June 05, 2022 @02:45PM (#31633731)
This Go code is wildly non-idiomatic. Type assertions via `.(type)` are a tool of last resort, not something that an application developer should turn to as a solution to a problem, and certainly not post-1.18, which permits generics.

edit: e.g. https://go.dev/play/p/wDO5J8CElSC

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by CraigJPerry on Monday June 06, 2022 @12:43PM (#31642730)
Hey thanks for sharing this, I think this has lost track of the problem though, remember we're looking for the alternative to rust's:

    enum Shape {
        None,
        Circle(radius: usize),
    }
In your version we've lost the Shape concept, to make it more explicit, what's the idiomatic go version of:

    enum Shape {
        Circle(usize),
        Rectangle{length: usize, breadth: usize},
    }
https://play.rust-lang.org/?version=stable&mode=debug&editio...
Re:Rust Is Hard, Or: The Misery of Mainstream Programming by preseinger on Thursday June 09, 2022 @12:02AM (#31677432)
There is no way to express an enum whose possible values are of different types.

In Go code will typically "offer" concrete types, and "accept" abstract interfaces. Abstractions over concrete types are expressed by consumers who want to operate on those types, rather than producers who provide implementations of them. So your Shape would probably end up an interface defined by whatever consuming code wanted to treat Circles and Rectangles equivalently.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by garethrowlands on Friday June 03, 2022 @09:27AM (#31607918)
Rust and Go are surely different classes of programming language. Rust is a systems language and Go is garbage collected. That is, Go is in the camp with Ruby, Python and Javascript, whereas Rust is in the camp with C and C++. Garbage collected languages are easier to use than non-garbage collected languages, so if you can use them, you should.
Re:Rust Is Hard, Or: The Misery of Mainstream Programming by blub on Friday June 03, 2022 @12:22PM (#31610438)
Why is a systems language used for web applications, servers, command-line utilities and all sorts of libraries?

The article is about a “messenger bot” for example and nobody’s complaining that it’s wrong to write such a thing in Rust.

The reality is that Rust is competing with Java and Go and Python for many things and its poor ergonomics are hobbling it.

Re:Rust Is Hard, Or: The Misery of Mainstream Programming by CraigJPerry on Friday June 03, 2022 @12:17PM (#31610381)
Probably comes down to your definition of a systems language.

E.g. if that means implementing low level things like cryptography APIs, or being able to define the exact memory layout of objects in memory or access raw pointers or write ASM inline then obviously that disqualifies ruby, python and js but it would mean Go qualifies.