On Apr 24, 2019, at 12:34 PM, Marcus Low <marcus...@gmail.com> wrote:
> 
> On Wednesday, April 24, 2019 at 10:08:53 PM UTC+8, Mark Volkmann wrote:
>> Are there really developers that find this unreadable? 
>> 
>> color := temperature > 80 ? “red” : “green” 
>> 
>> I know what you are going to say. People will nest them. But even nested 
>> usage can be readable when formatted nicely with one condition per line. 
>> Another alternative is to allow only unnested ternaries. 
>> 

> color := map[bool]string{true:"red",false:"green"}[temperature>80]
> Here you go.

Pardon my bluntness, but it is silly to assert that this is anywhere near the 
readability of the ternary statement.  The entire point of the ternary 
statement is that it is concise and spartan; this is cluttered and overwrought.

Yes, people can (and will) abuse it.  That doesn't seem to have stopped us from 
having a reflection library, which is arguably much worse for readability and 
more pernicious compared to ternary statement abuse.

There are very few cases where you can force good coding hygiene by removing 
language features.  This isn't one of them.  If you wanted to force good coding 
style, put a check for nested ternaries in go vet along with other readability 
issues.


- Dave

-- 
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.

Reply via email to