News for hackers. Stuff that matters.
Re:Faster Sorting with Go Generics by dilap on Saturday April 02, 2022 @02:38PM (#30890562)
Yeah Go is all about "simple, fast enough, compiles fast"

So I'd say knobs to control this, which, if you get them wrong, lead to slow compiles, would defnly be contra the spirit of Go.

And in cases where absolute max performance really matters, nothing is stopping you from monomorphizin by hand. (But if absolute max perf really matters, you probably picked the wrong language.)

Re:Faster Sorting with Go Generics by rventure on Saturday April 02, 2022 @02:45PM (#30890624)
There is no language that writes code as beautiful code as go, at a lower level. C comes close, but C++/Rust are plain ugly, while C is older than some HN users and requires a lot of third-party dependencies for basic operations (e.g http requests).
Re:Faster Sorting with Go Generics by mirceal on Saturday April 02, 2022 @04:19PM (#30891338)
if err != nil { return nil, err }

code poetry right there. it's so good that you have to repeat this over and over again!

Re:Faster Sorting with Go Generics by socialdemocrat on Saturday April 02, 2022 @08:15PM (#30892889)
It sucks a bit, but I find the tradeoff quite good. The Go folks have managed to make a language which is quite low level and with a small fairly transparent feature set which still manages to produce code which is not too verbose.

Java and C# for instance despite being much higher level languages tend to require far more verbose code.

I have played with some crypto code and concurrency in all languages to compare and was pleasantly surprised by how much more compact Go code ended up being while also being easy to read and using fairly simple constructs.

You can often get smaller Java and C# code but at the expense of using far more complex and abstract concepts.

There is a sense of good balanced taste in how Go featured and libraries are made which often lacks in many other languages.

Re:Faster Sorting with Go Generics by mirceal on Sunday April 03, 2022 @12:44AM (#30894529)
i think go (as any other language) shines in some use cases, is meh in some use cases and straight-up sucks in others. the problem i'm seeing is the cargo cult where basically go is the ultimate answer and everything has to be rewritten in it.
Re:Faster Sorting with Go Generics by doctor_eval on Saturday April 02, 2022 @09:47PM (#30893474)
Yeah, the fact that I can write a production capable JSON API server in about 5 lines of code with no external dependencies is golden. Compile and start times are tiny. Native executables are brilliant. The ergonomics of Go go well beyond just LOC.
Re:Faster Sorting with Go Generics by esprehn on Saturday April 02, 2022 @07:46PM (#30892715)
To be fair in rust you get to write .into() or Ok a lot.

I do find Go's error handling annoying but rust seems similar for line noise. It's more compact noise, but it's all there.

Re:Faster Sorting with Go Generics by maleldil on Saturday April 02, 2022 @09:42PM (#30893422)
Those are for the cases where you're creating or transforming an error. In those scenarios, Go's handling isn't that bad.

The issue is having to write `if err != nil { return nil, err }` versus `func()?`. The former gets old really fast.

Not to mention the other benefits of monadic error handling when compared to glorified error codes.

Re:Faster Sorting with Go Generics by mcronce on Sunday April 03, 2022 @01:24AM (#30894689)
Even transforming an error is taken care of by ?

func()? desugars to (more or less)

    match func() {
        Ok(v) => v,
        Err(e) => return Err(e.into())
    }
I'm also not really sure what the complaint is. Go doesn't do any more implicit type conversion than Rust does. There are numerous solid arguments for Go over Rust, but error handling and automatic type punning aren't on the list.
Re:Faster Sorting with Go Generics by avgcorrection on Saturday April 02, 2022 @08:48PM (#30893117)
> To be fair in rust you get to write .into() or Ok a lot.

Sure. If “fair” means “not comparable at all”.

if-condition-return using two variables is not comparable to one function/macro call.

Re:Faster Sorting with Go Generics by burnished on Saturday April 02, 2022 @10:06PM (#30893633)
yeah errors appear to be a wart
Re:Faster Sorting with Go Generics by tialaramex on Saturday April 02, 2022 @07:16PM (#30892539)
Beauty is of course necessarily in the eye of the beholder, but Rust doesn't look ugly to me. One of the first things that jumps out is how little boiler plate Rust's canonical Hello World program has, Go doesn't do badly here either (certainly compared to C, C++ or Java), but it does introduce a bunch of ancillary stuff like packages and importing that are peripheral to our purpose in writing Hello, World!
Re:Faster Sorting with Go Generics by mustache_kimono on Saturday April 02, 2022 @10:53PM (#30893931)
> Beauty is of course necessarily in the eye of the beholder

This is so true. Not is disparage other languages, but golang isn't beautiful to me at all, and neither is python. Yet Rust is nearly perfect. I'm strange. I get it!

Re:Faster Sorting with Go Generics by esprehn on Saturday April 02, 2022 @07:50PM (#30892732)
Spin showed up on HN recently as an interesting example of Go vs Rust hello world:

(Rust) https://spin.fermyon.dev/ Vs (Go) https://spin.fermyon.dev/go-components/

The Go example seems a lot simpler without the Ok/Some/.into()/? That are unrelated to sending hello world. There's also no macro magic to understand.

In general my observation is the ancillary stuff (and in general number of things you need to understand) is greater in rust. That's paired of course with greater expressivity.

Re:Faster Sorting with Go Generics by mustache_kimono on Saturday April 02, 2022 @09:06PM (#30893237)
I've never really understood why the lack of Result/Option types are somehow spun as a good thing. Other things about Rust can be complex and can require some diligence to learn, but Result/Option types over golang's way of handling the same thing? Seriously? That's the argument for golang?
Re:Faster Sorting with Go Generics by doctor_eval on Saturday April 02, 2022 @09:51PM (#30893513)
I don’t think that’s the argument for Go. It’s a decision that Go developers accept as a trade off for other things that are nice about Go.

I haven’t learned Rust yet, maybe one day I will, but it looks a lot more complex to me, and it’s hard to see how the extra complexity will help me write better web servers.

It’s OK for Rust and Go to solve different problems with different trade offs.

Re:Faster Sorting with Go Generics by mustache_kimono on Saturday April 02, 2022 @10:28PM (#30893781)
Totally agree with you. And I totally get why some people would prefer golang.

Don't like how some constantly feel the need to compare golang and Rust (two very different languages), and how some feel like the comparison is always favorable to golang. Like you said -- there are tradeoffs. golang folks seems to have a problem acknowledging that Rust made a few good decisions too, like Result and Option types, mostly because they haven't ever used them.

It's hard for me to imagine someone using them (golang has generics now, so get ready!) and not liking them. Especially golang. It's just so weird to hear that someone describe one of the warts of golang as actually beautiful, instead of, as you say, a tradeoff.

Rust has a certain amount of friction. It takes some work to learn well enough to feel productive. I don't know if it's all that bad. But, yes, it is a clear tradeoff for people who mostly work in domains in which golang works well enough to really pretty great, like writing web servers.

Re:Faster Sorting with Go Generics by doctor_eval on Saturday April 02, 2022 @10:51PM (#30893924)
Ok. Ironically, your comment came across to me as a comparison, but I guess we were both reacting to the same sense, that it’s not a race.

In fact, I’d really love to learn Rust - GC always feels like a nasty hack to me - but my current use case and time constraints mean that I won’t get to use what I learn, and will quickly forget, so it’s just a waste of time for me at the moment.

Re:Faster Sorting with Go Generics by tialaramex on Saturday April 02, 2022 @09:08PM (#30893250)
Hmm. I think you intended to link: https://spin.fermyon.dev/rust-components/

What's nice about "Hello, World!" is that it's a canonical example where we know exactly what it's supposed to do, in contrast these pages are showing off features of writing Spin components in different languages so that makes it much harder to compare.

In each case they're using a popular existing HTTP library for its familiar APIs, but the chosen APIs are of course not the same in Go and Rust.

The Go API (from net/http) follows typical Go style, it assumes success, and doesn't worry too much about errors. If you write any data to the ResponseWriter (which this example does), you get a 200 OK response anyway. You don't need to set types, it'll guess, likewise you don't need to care about binary data, it'll guess. This is cheerful and will mostly work, if it doesn't work you can probably learn what you did wrong and try again.

The Rust API (from the http crate) follows more typical Rust style. You must say whether you succeeded with Ok, so that failures can be handled appropriately. You can choose whether your response has a body we do have a body here so hence we need to write Some. Finally HTTP bodies are binary data, and we'd like to return a string, so we use the Into trait to get the UTF-8 encoded text out of the string as bytes, this is how Rust stores strings anyway so it will be trivial.

The Rust code sets header "foo" to "bar" for some reason, and also prints (to console) all the information about the request, presumably because that's trivial to do in Rust, the Go code doesn't do either of these things.

I agree that there certainly is a lot more Rust, it's just that I'd say it's beautiful rather than ugly, a matter of opinion.

Re:Faster Sorting with Go Generics by esprehn on Saturday April 02, 2022 @10:11PM (#30893679)
The link was the correct one, scroll down and you'll see a simple hello world example that matches what the golang one does.
Re:Faster Sorting with Go Generics by tialaramex on Sunday April 03, 2022 @11:54AM (#30897848)
On second glance I think that Rust example is needlessly verbose, which is fine if that's what you meant, but the Go doesn't do that.
Re:Faster Sorting with Go Generics by tehnub on Saturday April 02, 2022 @09:32PM (#30893370)
Zig
Re:Faster Sorting with Go Generics by pjmlp on Saturday April 02, 2022 @03:11PM (#30890860)
Object Pascal, Modula-2, Active Oberon.

Just for starters.