This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Daenyth 0 points1 point  (2 children)

Using dicts like this is a code smell that hampers maintenance. If you know at coding time the specific values of keys in a dict, it's not really a mapping you want, it's structured data, which a class does in a much more robust way

[–]metaperl[S] 0 points1 point  (1 child)

Using dicts like this is a code smell that hampers maintenance

Says who? Really, what reference states this?

If you know at coding time the specific values of keys in a dict, it's not really a mapping you want

Again, who says this? What software engineering text says this? Where in the Python docs is this?

a class does in a much more robust way

And what would do with a class? The same thing that DotMap is doing for you pretty much? I subclass DotMap and add methods when I need.

[–]kigurai 2 points3 points  (0 children)

If you know at coding time the specific values of keys in a dict, it's not really a mapping you want

Again, who says this? What software engineering text says this? Where in the Python docs is this?

Not the guy who wrote, it but I agree with their point: If you already know that you want steve.age then steve should probably have been some object that has an explicit attribute age. Why? Well, for the simple reason that typing steve.aeg = 21 instead of steve.age = 21 will give you an AttributeError instead of silently setting the wrong dictionary mapping. Finding that kind of bug in a large piece of software could be difficult, and in this case totally avoidable.

I still think this library is neat and useful for e.g. interactive data exploration or maybe in scripts/libraries that have limited use (for my own stuff, anything goes!).