Earlier quoted context omitted.
I agree, there is a long list of things I would change in Python. And believe me when I say people involved in the community listen to this very carefully. This is why we had Python 3 in the first place. Because text handling was such a cause of pain. This is why we have type hints in the first place. Because big projects using Python felt let down. And Python 3 and type hints are also a huge source of criticism (I w…
> Because big projects using Python felt let down. Why big projects started using Python in the first place is a very good question, given that this language had not been designed for them...
WTFPython – Understanding Python through surprising snippets
111–120 of 199 posts
Re: WTFPython – Understanding Python through surprising snippets
#112Earlier quoted context omitted.
Maybe I’m misunderstanding, but I’d argue that arrow syntax in js is equally special syntax as lambda function. They’re both native ways of making anonymous functions. Python’s version is more clunky, but no more special
Aren't Python's lambdas expressions while JS's arrow functions are not?
Re: WTFPython – Understanding Python through surprising snippets
#113Earlier quoted context omitted.
What do you mean by "external encoding", "internal encoding", "secondary buffer"?
Encoding strings internally as UTF-8 is a bad idea, since you can't do efficient constant time access (utf-8 isn't fixed width).
Re: WTFPython – Understanding Python through surprising snippets
#114Earlier quoted context omitted.
I've coded in python for >10 years and C# for ~half of that. I prefer indentation-based control flow purely because it condenses code vertically and creates consistent indentation with actual purpose (many of the devs on C# projects I've dealt with have had inconsistent tab/space settings and no linting). If anything, the one thing I hate about Python3 is dynamic typing - inferring datatypes in function bodies is gre…
Python does have a lot of problems, but it's so far the most flexible language like English. High level programming language is meant to communicate, not to dictate the computation. Python happens to be easy to understand by humans.
Re: WTFPython – Understanding Python through surprising snippets
#115Earlier quoted context omitted.
Encoding strings internally as UTF-8 is a bad idea, since you can't do efficient constant time access (utf-8 isn't fixed width).
Encoding strings internally as UTF-8 is a fine idea, usually you don't need constant-time access to individual code points. E.g. PyPy (faster Python, with JIT) does so. Many other languages also save strings as UTF-8.
Re: WTFPython – Understanding Python through surprising snippets
#116My biggest complaint about Python is that it somehow doesn’t get flak for having the same (if not worse) scoping as JS, which gets endless hate for its function-scoped variables. (So much so that block scoped variables are the new normal in JS, but not in Py!) Take for instance: >>> powers_of_x = [lambda x: x^i for i in range(10)] >>> [f(2) for f in powers_of_x] [512, 512, 512, 512, 512, 512, 512, 512, 512, 512] To m…
Even more fundamental is the nonlocal/global stuff required in order to avoid declaring your variables. Many people are surprised by what this snippet does: a = 0 def f(): print(a) a = 1 f() f()
Re: WTFPython – Understanding Python through surprising snippets
#117Earlier quoted context omitted.
> there should be one-- and preferably only one --obvious way to do it. Yes, this has been one of the hardest balance to find. And believe me when I tell you the community tries very, very hard. But it's a difficult problem: making the language evolves fast enough, but keeping it solid and stable. Very difficult indeed. > Python became a language that can be really hard to read now. Not in my experience. My job invol…
The new walrus operator now makes indentation obsolete. You can write averything within one line as an array and it is hard to read. This in combination with syntactic sugar, operator overloading and unicode variables can make the language very hard to read. e.g. # compute pi 1000000 >> ψ( ψ(χ>>op("(x**2+y**2)**0.5 >Σ*4>> _/_) or this: # 10 fibonacci numbers [x:=[1,1]] + [x := [x[1], sum(x)] for i in range(10)] is va…
let x = in
into this: (lambda x: )()
(as the lambda calculus does)or this:
[ for x in (,)][0]
of course the readability is terrible, but the power was always there if you wanted to (ab)use it :)(yeah, i've used the second one in a repl, don't @ me)
Re: WTFPython – Understanding Python through surprising snippets
#118Earlier quoted context omitted.
What do you think each(), map() and filter() do ? But even without that, I'm not saying they are comparable. I'm saying the same API will use explicit anonymous callbacks in JS and something else in Python (decorators, subclassing, protocols, generators...). I'm saying that the same API will use __iter__ in Python and something else in JS (type conversion, proxy object, explicit method call...). E.G, this is a Python…
Map, filter, and fold are higher order functions, functions which take functions as parameters. You are misusing the word callback. A callback is a function passed to another thread that will maybe be invoked later as a response (like it calls you back).
Re: WTFPython – Understanding Python through surprising snippets
#119Earlier quoted context omitted.
What do you think each(), map() and filter() do ? But even without that, I'm not saying they are comparable. I'm saying the same API will use explicit anonymous callbacks in JS and something else in Python (decorators, subclassing, protocols, generators...). I'm saying that the same API will use __iter__ in Python and something else in JS (type conversion, proxy object, explicit method call...). E.G, this is a Python…
Map, filter, and fold are higher order functions, functions which take functions as parameters. You are misusing the word callback. A callback is a function passed to another thread that will maybe be invoked later as a response (like it calls you back).
Even MDN uses the term callback to describe e.g. the argument to 'map': https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
In contrast, Lodash goes out of its way not to use the term "callback", presumably to avoid confusion since it's a place where many functions-that-take-a-function-argument do not call the provided function, e.g. https://lodash.com/docs/#curry
Re: WTFPython – Understanding Python through surprising snippets
#120It's a good repo, but remember a lot of those are "A Good Thing™". The first snippet is a very good example: a := "wtf_walrus" doesn't work while: (a := "wtf_walrus") works. It's a fantastic design decision. Python took a long time before getting this operator, because it's a language that favors being readable, easy to use, and above all, to learn. But in many other languages, the very same operator is often misused…
in the zen of python (import this) it says: there should be one-- and preferably only one --obvious way to do it. sadly this is not true for a while in python now. Python became a language that can be really hard to read now.
And as far as I'm concerned, the walrus operator breaks it in no way whatsoever: an assignment statement is the one obvious way to perform an assignment, and it's a syntax error to use a walrus as an assignment statement.