News for hackers. Stuff that matters.
Re:Twelve Years of Go by mountainriver on Wednesday November 10, 2021 @01:26PM (#29178323)
It’s never actually been a problem for me, I prefer Go errors over most languages
Re:Twelve Years of Go by jrockway on Wednesday November 10, 2021 @01:47PM (#29178657)
I agree with this. What I like about the Go method is that all errors are equal -- they look the same if it's a stack of microservices running at different companies, a bunch of goroutines communicating state with each other, or if you're just calling a local function that fails. It's the same every time, and the programmer can cut through the noise and make a complicated error from a complicated system simple, concise, and easy to understand.

People seem mad that they have to plumb around `err`, and that they have to provide useful context with fmt.Errorf. I see that as letting good programmers make good systems. The default in other languages is useless -- line numbers and arguments is all you are allowed to have, and when something goes wrong it takes up your entire screen with noise. Not as good as everyone thinks it is.

Re:Twelve Years of Go by AtNightWeCode on Wednesday November 10, 2021 @01:32PM (#29178408)
I can live with the error handling. But as I wrote. The problem is that it encourages if-programming. Something that is a problem in the Go community.
Re:Twelve Years of Go by handrous on Wednesday November 10, 2021 @01:36PM (#29178487)
If it's helping keep the "'if' considered harmful" crowd away, I say keep it. There are plenty of other languages.
Re:Twelve Years of Go by mountainriver on Wednesday November 10, 2021 @03:26PM (#29180218)
Yeah exactly, conditionals around errors are fine. Nothing like being pedantic for no reason
Re:Twelve Years of Go by mseepgood on Wednesday November 10, 2021 @01:37PM (#29178493)
since when is if-programming a bad thing
Re:Twelve Years of Go by skybrian on Wednesday November 10, 2021 @01:46PM (#29178642)
It depends on what kind. I didn’t find maintaining codebases littered with platform-specific ifdefs all that fun.

If statements used for error checking are a bit verbose but basically fine.

Re:Twelve Years of Go by mseepgood on Wednesday November 10, 2021 @01:56PM (#29178815)
Go doesn't have platform-specific ifdefs sprinkled throughout the source. Platform-specific code is separated into files guarded by build tags as recommended in 'The Practice of Programming'. Compile-time control flow is not mixed with runtime control-flow.
Re:Twelve Years of Go by skybrian on Wednesday November 10, 2021 @04:14PM (#29180905)
Sure, that was in C. Go is an improvement.
Re:Twelve Years of Go by AtNightWeCode on Wednesday November 10, 2021 @01:55PM (#29178797)
What you learn at school when it comes to programming is to avoid if-statements for control flow. It is error prone. If-statements are mainly used for various types of guards.
Re:Twelve Years of Go by AnimalMuppet on Wednesday November 10, 2021 @03:46PM (#29180517)
And what you learn after a few years in the real world is that, when school tells you "this is the right way", they're almost always wrong. Or, there at least almost always wrong in many circumstances. The real world is a lot more complicated than they teach you in school, and the correct answer is almost always "it depends".

Should you avoid if-statements? It depends. What are you going to have to do instead? You're going to have to do something. Is that something going to be more understandable for your co-workers for the lifetime of the code? Maybe, depending on your co-workers. Maintainability over the lifetime of the code far outweighs and "should" that they tell you at school.

Re:Twelve Years of Go by mseepgood on Wednesday November 10, 2021 @02:17PM (#29179173)
'if' is the epitome of control flow (next to looping). It's fundamental to computer programming. It's honest. Don't be ashamed of control flow, don't hide your control flow as if it didn't exist.
Re:Twelve Years of Go by morelisp on Wednesday November 10, 2021 @02:37PM (#29179479)
> It's fundamental to computer programming.

I'm weakly pro-if, but no, it's not. We went a lot of years without it, and some rending and gnashing accompanied its introduction.

Re:Twelve Years of Go by Thaxll on Wednesday November 10, 2021 @02:02PM (#29178935)
vs exception based control flow which is way worse.
Re:Twelve Years of Go by xh-dude on Wednesday November 10, 2021 @04:03PM (#29180743)
I really think Go’s opinion here arises from a sense that some abstractions of control flow just should be verboten for concurrency. For example exceptions dumping a stack trace in a concurrent program is often OK and occasionally extremely cursed.
Re:Twelve Years of Go by nobleach on Wednesday November 10, 2021 @06:07PM (#29182211)
Spectre I think? The mitigation patches make branch-heavy code slower.