5 ms·
Interestingly enough, my advice to not use `Map.get` is the most contentious point in the entire post. I didn't suspect that would be the case. I'm certainly n
by keathley 5y ago
Interestingly enough, my advice to not use `Map.get` is the most contentious point in the entire post. I didn't suspect that would be the case.
I'm certainly not against using those functions and the additional checking can be of use in certain circumstances. The use case I had in mind was specifically how people will use `Keyword.get` to grab configuration values or options. This means that if you load configuration from a json file or external service, and it comes back as a map, you now need to convert to a keyword list just to initialize a library. Its a small thing, but in those situations I would rather allow for more flexibility in the interface.
That said, I think this advice is particularly useful for people building libraries more so then people working on applications. I may try to add more nuance to this point in the post.
- jolux 5y ago> The use case I had in mind was specifically how people will use `Keyword.get` to grab configuration values or options. It seems like this advice is very dependent. I think you should decide whether a function accepts maps or keyword lists or both, but I do not think that all functions which operate on key-value structures should default to accepting both. They have very different performance characteristics, and keys are not unique in keyword lists.
- keathley 5y agoI agree on the performance characteristics. But if your using `get` then it doesn't matter that keyword lists have non-unique keys. You just get the first one.
- jolux 5y agoMaybe it does, maybe it doesn’t. Maybe somebody gave you a keyword list that they thought had unique keys and it didn’t. The point is, the two structures are not semantically equivalent, and I think it’s a mistake to conflate them in general. Just because you can use access syntax on both doesn’t mean you should write a polymorphic function that does so. Sometimes you should! But not most of the time.
- keathley 5y agoNo, it literally returns you the first one. If you have a keyword list and use get your not going to be getting the benefit of duplicate keys.
- deleted 5y ago[deleted]
- jolux 5y agoNo, you asserted it doesn't matter because it still works and returns the first value. I was saying it might. The point stands. Different data structures, different modules, different semantics. Can and should is an important distinction here.
- sb8244 5y ago> That said, I think this advice is particularly useful for people building libraries more so then people working on applications This is a good point that I hadn't really thought about previously. I agree with your thoughts much more when I consider the different needs between libraries and applications.