4 ms·
TLDR: if you’re a new programmer, don’t take this seriously. This person clearly doesn’t understand programming languages so well. Sorry to make this response
by santiagobasulto 7y ago
TLDR: if you’re a new programmer, don’t take this seriously.
This person clearly doesn’t understand programming languages so well. Sorry to make this response an “ad hominem” one, I should revoke the claims. But it’s impossible if they don’t understand basic concepts of programming languages.
For example, complaining that a dictionary key must be place in quotes. It’s not that “the key needs quotes”, but that you’re using “a string” as a key. In fact in Python, you can use any immutable object as a key (tuples, for example). They clearly come from Javascript, Python works differently (and arguably better), and they’re complaining that it doesn’t work the way they’d like it to work.
Then complaining about list comprehensions as a “weirdo” thing. Clearly not understanding the functional paradigm and the beauty of expressions (see Smalltalk for the ultimate example of beauty and expressiveness).
- verttii 7y agoActually nowadays it's discouraged to use list comprehensions in Haskell. Even though he didn't complain about it, Python has very poor facilities for functional programming overall.
- mplanchard 7y ago> any immutable object as a key Any hashable object, technically. Especially with custom objects, the two (immutability and hashability) don’t necessarily have to overlap, although it’s often a bad idea to have hashable, mutable objects
- abhishekjha 7y agoMutable objects can't be hashed right?
- detaro 7y agoAs the comment you responded to says: An object can be mutable and hashable. E.g. any custom class by default has mutable and hashable instances.
- abhishekjha 7y agoHow can you get both mutable and hashable instances at the same time?
- detaro 7y agothe only requirement on a hashable instance is that it implements a proper __hash__ function. The default implementation in CPython returns the address of the memory the object is stored at, so all instances are considered unique, values play no role at all.
- progval 7y ago> For example, complaining that a dictionary key must be place in quotes. It’s not that “the key needs quotes”, but that you’re using “a string” as a key. In fact in Python, you can use any immutable object as a key (tuples, for example). They clearly come from Javascript, Python works differently (and arguably better), and they’re complaining that it doesn’t work the way they’d like it to work. Agreed. However, there's a trick to use strings without quotes: dict(foo=1, bar=2) == {'foo': 1, 'bar': 2}
- mlevental 7y agohow is that a trick? you still can't access without quotes? the real trick is a Dict class that in the __init__ sets self.__dict__. but why would you do that just to save trying quotes
- etbebl 7y agoTo be fair it is pretty confusing how Python and JS have two features that look very similar on the surface (dictionaries and objects) but actually work very differently. As someone who uses both languages infrequently, it trips me up.