8 ms·
This is why adding language features needs to be carefully thought out and explored to great lengths. Sadly C++ never got that memo. Here's hoping Python remain
by wheaties 4y ago
This is why adding language features needs to be carefully thought out and explored to great lengths. Sadly C++ never got that memo. Here's hoping Python remains "simple."
- pizza 4y agoIs it better for Python to be simple than for Python to be simple for simple problems?
- Waterluvian 4y agoI’m not sure I understand the “this is why” part. Python wants to let you override almost everything. It’s a feature and a powerful and occasionally helpful one. It’s also a feature you never ever have to know about or touch.
- Blackthorn 4y agoIt's like python's metaclasses. You rarely need them but sometimes they really are just the best solution to the problem. Those times, you're really glad they're available.
- jesushax 4y agoThis debate could be summed up as: There's more than one way to do it *vs* there should be one, and preferably only one, obvious way to do it
- DangitBobby 4y ago> there should be one, and preferably only one, obvious way to do it Loops, list/dict comprehensions, if statements, and ternary expressions would all like a word
- jesushax 4y agoThe same debate applies to all of those things, so this is just another instance of Python battling with a philosophical principle underlying the language, which naturally arises anytime a redundant (but good) feature like this is added to the language
- jamesfinlayson 4y agoAgreed - I mostly use Python for small scripts and it makes that use case very easy. I know it has a bunch more features for more niche stuff as well but my throwaway script to download images from a webpage doesn't need pattern matching.
- kazinator 4y ago> It’s also a feature you never ever have to know about or touch. The "never have to know or touch" argument applies only to the lone hacker working on a completely new project with no inherited legacy code.
- zqlark 4y agoIndeed. Most Python code bases I have seen are maxing out all obscure features like those in the article. In practice, Python today is one of the most unreadable languages in existence.
- pansa2 4y agoIt’s quite clear from the design of Python, both of recent features and of fundamentals like `+=`, that its designers never got that memo either. I’m baffled as to how it retains its reputation of being a simple language.
- shepherdjerred 4y agoI think it’s a pretty simple language for how powerful it is. But it’s not simple compared to some other languages like Go
- defen 4y agoWait, what's the deal with `+=` ?
- CGamesPlay 4y agoThe obvious x = x + y and the also-works x += y. There is more than one way to do the operation. The conceptually more simple way would be the former as it does not require the programmer to know an extra operator.
- patrec 4y agoIt can mean two completely different things. `let x = x + 1` (rebinding) or `x += 1` (mutation). In [5]: def cap(x): ...: xs = [] ...: for i in range(3): ...: x+=1 ...: xs.append(x) ...: return xs ...: ...: In [6]: cap(numpy.array(0)) Out[6]: [array(3), array(3), array(3)] In [7]: cap(0) Out[7]: [1, 2, 3]
- pansa2 4y ago`a += b` sometimes does the same thing as `a = a + b`: >>> a = b = (1, 2) >>> a = b = (1, 2) >>> a += (3,) >>> a = a + (3,) >>> print(a, b) >>> print(a, b) (1, 2, 3) (1, 2) (1, 2, 3) (1, 2) Sometimes it does something different: >>> a = b = [1, 2] >>> a = b = [1, 2] >>> a += [3] >>> a = a + [3] >>> print(a, b) >>> print(a, b) [1, 2, 3] [1, 2, 3] [1, 2, 3] [1, 2] IMO if that behaviour had been "carefully thought out" by the language designers, it should have been obvious that it's a bad idea. Failing that, the implementation of that behaviour is convoluted - so the designers should have paid attention to the Zen of Python: "If the implementation is hard to explain, it's a bad idea". Failing that, if the behaviour had been "explored to great lengths", the designers would have understood how it interacts with other language features - in particular, nested mutable and immutable objects. Python's designers failed to do any of these things, so we've ended up with an operator with unpredictable behaviour and a long FAQ entry [0] about how its possible for an operator to both succeed and fail at the same time: >>> a = ([1, 2], 4) >>> a[0] += [3] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'tuple' object does not support item assignment >>> a ([1, 2, 3], 4) [0] https://docs.python.org/3/faq/programming.html#why-does-a-tuple-i-item-raise-an-exception-when-the-addition-works https://docs.python.org/3/faq/programming.html#why-does-a-tu...
- petters 4y agoI like Python, but it really isn’t “simple” (at least not for more than a decade).
- pjmlp 4y agoAll languages got the memo, including C++. Either you get Scheme, or languages with features. Even C isnt' as "simple" as people take it to be.