Hacker News new | ask | show | jobs
by valbaca 1455 days ago
Interesting how Clojure takes the complete opposite approach by simply making dicts immutable.

https://chasemerick.files.wordpress.com/2011/07/choosingtype...

4 comments

Yeah, as a clojurist this made me laugh: just like people will naturally feel an urge to fill up conversational silence with words, people can’t seem to be able to go without their classes for more than 5 minutes.

I don’t have anything against classes in theory, but I’m of the opinion that 99.9% of classes out there just shouldn’t exist.

Clojure has established the gold standard for beautiful abstractions that unify broad categories of data types. It's seq interface is elegant and powerful. Python's efforts towards option data typing or strict data typing looks especially clunky, awkward, forced, and painful when compared to Clojure.
Clojure also makes working with hashes a whole lot more ergonomic with destructuring and symbol keys.
Could you clarify a bit here? Python also has destructuring for its dicts and I'm not entirely sure what you mean by symbol keys.
Python has tuple destructuring, which can be used with dict.items(). I'm talking about being able to destructure by name not position:

    name, address = some_dict
You could fake it if you could ask for a tuple of specific entries:

    name, address = some_dict.pluck("name", "address")
Symbol keys are string keys for the more sophisticated among us. See :some-name vs "some_name". ;)
they're closer to a (namespace) global enum imo
You still need to know what keys to expect. The Clojure map that get replaced with a new map have the same problem as a mutable dict.