You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Problem: I would like Golang to have a ternary (or conditional) operator. This would help so much in a lot of situations, especially error-handling.
I have a lot of:
AFAIK there would be no compatibility-issues or whatsoever, since it's just a new feature to the language. If you don't know or understand the operator, or simply don't want to use it, then don't. I'd like to have this feature in Go.
This would clean up my code (IMO), and would make it more readable (at least for me).
Let me know what you think. Thanks!
The text was updated successfully, but these errors were encountered:
@bontibon Okay thanks. I didn't find these when I first researched but I understand now that it is a design-decision to not support conditional operators, although I don't like it. Thanks again, issue closed.
I am kind of new to GitHub and not sure if this is the right place to post this, but here it goes:
What version of Go are you using (
go version
)?go version 1.10
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?(Ubuntu 18.04.1 LTS 64-bit)
GOARCH="amd64"
GOCACHE="/home/thommy/.cache/go-build"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/thommy/dev/go"
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
What did you do?
https://play.golang.org/p/gjlLvTJX1ev
What did you expect to see?
Just that what I saw.
What did you see instead?
That what I expected.
The Problem: I would like Golang to have a ternary (or conditional) operator. This would help so much in a lot of situations, especially error-handling.
I have a lot of:
in my code, when I could shorten it to:
!err ? err.Error() : doSomething()
AFAIK there would be no compatibility-issues or whatsoever, since it's just a new feature to the language. If you don't know or understand the operator, or simply don't want to use it, then don't. I'd like to have this feature in Go.
This would clean up my code (IMO), and would make it more readable (at least for me).
Let me know what you think. Thanks!
The text was updated successfully, but these errors were encountered: