starlight-go / starlight

a go wrapper for google's starlark embedded python language
MIT License
300 stars 29 forks source link

For conversion from starlight Set to native Go map use map[interface{}]struct{} #6

Open deckarep opened 5 years ago

deckarep commented 5 years ago

Since the empty struct is more compact.

natefinch commented 5 years ago

Yeah, I've gone back and forth... in real use, I don't think size really matters unless you're making a gigantic set... my main concern is usability, and plain bools are easier to work with than struct{}.

// this is easier and nicer
set["foo"] = true
exists := set["foo"] 
// this is more compact, but ugly
set["foo"] = struct{}{}
_, exists = set["foo"]

I'll keep this open for now to have other people weigh in on it, but I don't think it really matters either way.... and bool is slightly easier to read IMO.