News for hackers. Stuff that matters.
Re:Go proposal: new package to provide generic slice functions by kubb on Wednesday May 05, 2021 @11:57AM (#27051577)
This is the decade-long argument of "let's sacrifice all our programmers to the devil so that we don't have work as hard on the compiler". I don't buy it, and it has never been demonstrated that the cumbersome style of writing go programs is helping compilation times, yet people keep saying it as if it's a fact.
Re:Go proposal: new package to provide generic slice functions by jolux on Wednesday May 05, 2021 @12:22PM (#27051933)
The cumbersome style seems to have become a strong part of the culture, almost a masochism about the limited features of the language. I find this ironic because I believe Go was intended to be highly pragmatic originally but it seems to have evolved an almost Scheme-like dogmatism about language complexity.
Re:Go proposal: new package to provide generic slice functions by skywhopper on Wednesday May 05, 2021 @02:13PM (#27053559)
Do you have specific examples you’re thinking of? Calling it masochism is weirdly insulting. Adding complexity is a one-way street. Languages live for decades. There’s no reason to rush adding features in a half-baked way, and the tradeoffs in terms of compiler complexity are very real.
Re:Go proposal: new package to provide generic slice functions by stouset on Wednesday May 05, 2021 @03:52PM (#27054827)
Virtually every large go program I've read has asymptotically reached 50%+ of its code being

    if res, err := fn(...); err != nil {
        fmt.Errorf("Look ma, I'm a human exception handler: ", err)
    }
This is held up as a positive thing, because handling errors is explicit and good. Somehow, the Rust equivalent of `?` is implicit and bad, despite desugaring to almost literally the exact same thing and being actually impossible to forget or overlook due to the return type of the function enforcing a Result.

In the same breath, devs will assert that the language is "low boilerplate" (despite 50%+ LOC being just one type of boilerplate) because Error Handling is Important. Which seemingly ignores that the important part of error handling is actually ensuring that errors are handled and not the mechanistic act of self-flagellation by wrapping every line of code in nearly-identical error handling ceremony. Which is unfortunate because golang doesn't do so great a job with the first part. It's surprisingly easy to actually forget to do something with the error while carrying on with a return value whose semantics are undefined (unlike Rust's Result, where you can have an error or a value and not both).

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Wednesday May 05, 2021 @06:33PM (#27056668)
I use Go a lot and I really like Rust, so maybe I can add some context. Error handling boilerplate isn’t a big deal. Lines of code aren’t a big deal. That’s not where your bugs are coming from and you aren’t bottlenecked on your typing speed. It’s not a real problem, but rather a dogmatic pursuit of terseness for its own sake. Rust is an expression-oriented language—it needs something like ? because without it we would have gratuitous nested braces marching ever-rightward and that actually is laborious to keep track of (deeply nested match expressions). Go could drop some error handling boilerplate with an ? operator, but it wouldn’t benefit as much from it as Rust did.
Re:Go proposal: new package to provide generic slice functions by kubb on Thursday May 06, 2021 @05:01AM (#27060714)
Consider these three points:

* it has been actually demonstrated that shorter programs contain less bugs,

* code is read much more frequently than it's written, and to the point code is easier to read than code full of boilerplate and meaninglessness syntactic elements,

* menial tasks and distractions introduce mental fatigue that consumes your limited brain resources that you need to think about the structure of your code that is actually dealing with the problem at hand.

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Thursday May 06, 2021 @01:49PM (#27066808)
I’m skeptical about the first bullet—is it the fewer characters or the reduced complexity which results in fewer bugs. If the latter, then it undermines your point; if the former the I’m very skeptical as it would suggest we should all be writing minified code.

With respect to the second bullet, I agree that code is read more frequently than it is written and that readability is paramount. I strongly disagree that minimizing the character count is the same as optimizing for readability. In particular, I find very syntactically terse languages like Haskell or Ocaml far harder to read—indeed ReasonML exists precisely because so many people find OCaml so difficult to read.

With respect to the third bullet, you should think about your error control flow. The structure of your code doesn’t change whether you’re using Go’s “if err != nil” or Rust’s ? operator. The difference is a dozen characters. I can’t believe that the real cognitive load is in the actual pressing of keys, but if that is your experience then text editors often have a “snippets” feature or extension that will let you map that boilerplate to a hot key.

Re:Go proposal: new package to provide generic slice functions by stouset on Thursday May 06, 2021 @01:31PM (#27066558)
Thanks for this, it's exactly what I had intended to reply with. Every single one of these points is spot-on.
Re:Go proposal: new package to provide generic slice functions by closeparen on Wednesday May 05, 2021 @07:54PM (#27057433)
Lines of code are a very big deal in an organizational context that cares about test coverage. Since all the error handling ceremony is written by hand, so too must a corresponding test case for each instance of the error-handling ceremony be written by hand. Typing out test suites for functions that compose several other error-returning functions is bureaucratic drudgery.
Re:Go proposal: new package to provide generic slice functions by lawl on Thursday May 06, 2021 @01:01AM (#27059322)
I'll bite. Why not ditch the "% test coverage" metric then, since as you just elaborated, it's not a good metric.

I would prefer my language wasn't designed around corporate bureaucracy personally.

Re:Go proposal: new package to provide generic slice functions by closeparen on Thursday May 06, 2021 @02:06AM (#27059701)
I don't think the coverage metric is necessarily wrong to highlight error return branches: they are program logic you typed, and might have mistyped. I certainly have mistyped them. Checked the wrong error value, or returned a different error from the one I checked. You get to skip tests for default exception handling behavior in e.g. Java because you know the language is going to do; there's no opportunity for human error.

It is possible to have company policies against abstraction and cleverness when working in more expressive languages, and this would achieve almost the same intent as Go, it's just that actually using Go is more convenient. The language is corporate bureaucracy. The whole point is what's not there. What can't go off in a weird directions on a per-project basis. What junior engineers in a high-turnover environment can't screw up. It's not by accident that the native toolchain will give you a test coverage report with untested error return branches in red. Google is just happy to pay people for that drudgery, I guess.

Re:Go proposal: new package to provide generic slice functions by lawl on Thursday May 06, 2021 @02:13AM (#27059752)
> You get to skip tests for default exception handling behavior in e.g. Java because you know the language is going to do; there's no opportunity for human error.

I fundamentally disagree with that. the only thing you know in java is that it throws an exception that's maybe caught somewhere. That's an untested branch aswell.

Re:Go proposal: new package to provide generic slice functions by closeparen on Thursday May 06, 2021 @02:35AM (#27059858)
You don't have to write a test for "if this underlying call throws an exception, that same exception is propagated up to me," which is about 80% of the test cases I write for Go.

You do have to test cases where exceptions are supposed to be caught and handled/eaten, which I agree is meaningful and relevant in all languages.

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Thursday May 06, 2021 @01:54PM (#27066884)
You “don’t have to write the test case” in the case of exceptions, but then you’re not getting the same coverage as with go. Just because a branch isn’t represented syntactically doesn’t mean it doesn’t exist. Note also that Rust’s ? operator isn’t going to be saving you from anything here since it just uses fewer characters to express the same branching logic, while languages with exceptions use none.

In general your org’s policies for what to test seems like a recipe for a low-value, high-effort test suite. Reminds me of the unit tests for getters and setters in Java.

Re:Go proposal: new package to provide generic slice functions by closeparen on Thursday May 06, 2021 @02:15PM (#27067170)
You get to take the language for granted; you don't get to take your own code for granted. "String reverse" is an easy function to write and the same instructions end up in my binary either way. But if you write your own, you'd better test it. If you import one from the standard library, no need, the stdlib has already done that. Functionality being in the language does not just save you typing; it also saves you testing. That's my point.

I agree, given that Go is what it is, it's a bad policy.

Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Thursday May 06, 2021 @03:00PM (#27067698)
You aren’t testing whether exceptions propagate correctly, you test that you catch or don’t catch them appropriately just like you test whether or not you return your error appropriately. That said, doing this for every function you write is probably not going to lead to a high value test suite.
Re:Go proposal: new package to provide generic slice functions by closeparen on Thursday May 06, 2021 @03:48PM (#27068259)
“Make sure it doesn’t catch the exception” is like “make sure it doesn’t do a tap dance” - there are quite a few things a function could do, we don’t generally ask unit testing to prove negatives.
Re:Go proposal: new package to provide generic slice functions by throwaway894345 on Friday May 07, 2021 @01:33PM (#27078521)
If you’re going to check that a function propagates an error in Go it equally makes sense to check that you check to make sure the equivalent Python/etc function propagates the exception. Of course I don’t think testing either of these is a good investment.
Re:Go proposal: new package to provide generic slice functions by eweise on Wednesday May 05, 2021 @05:59PM (#27056376)
I used to hardly think about exception handling on the jvm, mostly let them bubble up and be centrally handled except in special cases. Now I'm always worried that I'll forgot to manually handle the error in Go. Can't tell you how many times I've gotten panics as well, from nil objects.
Re:Go proposal: new package to provide generic slice functions by jolux on Thursday May 06, 2021 @12:16PM (#27065470)
I don’t think masochism is inherently negative and I did not mean to insult. For that I apologize. I was trying to characterize in a humorous fashion a difference between what I perceive to be the stated aims of the language and the experience of actually writing it.

It was also an oblique reference to this talk which is one of my favorites: https://youtu.be/mZyvIHYn2zk

Re:Go proposal: new package to provide generic slice functions by Serow225 on Wednesday May 05, 2021 @12:43PM (#27052252)
Thank you for naming this. I've always struggled with how to convey this to people.
Re:Go proposal: new package to provide generic slice functions by skywhopper on Wednesday May 05, 2021 @02:09PM (#27053494)
The Go compiler is much much faster than C++ and Rust. I don’t think that’s seriously disputed by anyone, is it?

There’s no universally correct answer to the right balance of “smart compiler” vs “simple language”. Having worked with Go on a daily basis for five years now, I really like the simplicity of the language. Compared to the cognitive load imposed by the language when using C++ and Rust, I much prefer the naive straightforwardness of Go. There’s no devilry about it.

Re:Go proposal: new package to provide generic slice functions by kubb on Wednesday May 05, 2021 @04:35PM (#27055402)
Go vs C++ is not a fair comparison, because C++ is a badly designed language from the 1980s. It also serves a different domain. Certain applications of C++ are not serviceable by Go.

Go vs Rust is not a fair comparison, because Rust's type system is much more powerful that Go's and enables applications that Go's doesn't (like embedded systems programming). Also some of the things I said about C++ apply here.

There are also features of Go absent from C++ and Rust (reflection, garbage collection). So it's really puzzling that you'd pick those two.

To have a fair comparison, you'd need to look at something like Kotlin sans the class system. There Kotlin is a clear winner, and with the same engineering resources put behind it, a cut-down version of Kotlin would easily be able to achieve build times in the ballpark of generic-enabled Go.

Despite its claimed simplicity, Go has inconsistent design and bug-prone unwieldy features (try to write code that merges streams of data from two channels without blocking unnecessarily). It also has unnecessary constructs that contradict its claim to include only what's necessary (interfaces are just structs of function pointers, type methods are just functions with a glorified first argument).

It may be enough to write one-off command line applications, but it doesn't give developers the tools to create complex distributed systems in a systematic, clean way, which was supposed to be its main area of application.

Re:Go proposal: new package to provide generic slice functions by geodel on Wednesday May 05, 2021 @06:10PM (#27056461)
> and with the same engineering resources put behind it, a cut-down version of Kotlin would easily be able to achieve build times in the ballpark of generic-enabled Go.

So basically no real example. It is only what would be possible if things were to happen certain way.

> It may be enough to write one-off command line applications, but it doesn't give developers the tools to create complex distributed systems in a systematic, clean way

This is just arrogant opinion. Distributed tools and applications like NATS, Kubernetes, Docker, CockroachDB and so many other exist and written in Go. Developers who can't write distributed systems themselves can ofcourse buy or license tools from vendors. And at that point, honestly, it could have been written in any language.

Re:Go proposal: new package to provide generic slice functions by erik_seaberg on Wednesday May 05, 2021 @06:43PM (#27056760)
If your team has to write and review boilerplate by hand, that’s millions of times slower than a computer generating it. The compiler only looks faster when we exclude all that wasted effort.