I'm at a loss as to how that could be considered more readable that a single ternary. You've successfully changed five lines to four lines, but that's still a long way from one line.
On Wed, Apr 24, 2019 at 12:15 PM Marcus Low <marcus...@gmail.com> wrote: > Yeah of course I was joking... the solution I provided does work for the > "I need a one-liner" mentality, though. > > I believe this following solution fits your use case, and is simpler to > read too: > > datalen := removedKeyken // removedKeyken must have been int32 in your > example. > if value != nil { > datalen = len(value) > } > > > > On Thu, Apr 25, 2019 at 1:05 AM Robert Engels <reng...@ix.netcom.com> > wrote: > >> I’m pretty sure you’re joking... but I think most are referring to simple >> usages, like this (from my own code). Clearly, there are others was of >> designing it to avoid the usage, but sometimes what is simple really is >> simpler. >> >> var datalen int32 >> if value == nil { >> datalen = removedKeyken >> } else { >> datalen = len(value) >> } >> >> >> >> On Apr 24, 2019, at 11:31 AM, Marcus Low <marcus...@gmail.com> wrote: >> >> I personally do not find ternary operators to be readable in any form. >> For those who are truly desperate for that cosmetic one-line kick, >> though, here's an example you can use (which looks just about as unreadable >> as any ternary operator out there): >> >> // ternary returns 12345 if x is positive (x > 0). >> // It returns -1 otherwise. >> func ternary(x int) int { >> return map[bool]int{true:12345,false:-1}[x>0] >> } >> >> >> >> On Thursday, April 25, 2019 at 12:20:35 AM UTC+8, Robert Engels wrote: >>> >>> Yes, but the FAQ has similar concerns about readability and >>> maintainability as reasons for not having generics, but adds the language >>> “may change”... not sure that is consistent with the views on the tenant >>> operator. >>> >>> > On Apr 24, 2019, at 9:52 AM, Ian Lance Taylor <ia...@golang.org> >>> wrote: >>> > >>> > The lack of the ?: operator in Go is a FAQ: >>> > https://golang.org/doc/faq#Does_Go_have_a_ternary_form . >>> > >>> > Ian >>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- R. Mark Volkmann Object Computing, Inc. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.