2016-07-26 18:27 GMT+02:00 Tyler Compton <xavi...@gmail.com>:
> if _, ok = m[key]; ok {
> }
>
> Is something Go programmers are used to.
>
> if m[ok] {
> }
>
> Requires that the programmer take a look at the map and its documentation to
> see what's going on unless they're already used to that pattern in the code
> base.

If this map is part of some sort of external API I'm inclined to
agree. (Except that a map[something]struct{} is a crappy external API
sort of type and should probably be a StringSet or whatever with
relevant methods on it.)

However, in my code these sort of maps usually pop up in deduplication
loops and similar:

    seen := make(map[string]bool)
    for _, v := range whatever {
       seen[v] = true
    }
    // ...
    for _, v := range somethingelse {
        if seen[v] {
           // ...
       }
   }

and there I think the bool value makes the code read much nicer
without any risk for confusion.

//jb

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