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.
[ Parent
| on HN ]
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
since when is if-programming a bad thing
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.
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.
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.
'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.
> 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.
vs exception based control flow which is way worse.
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.