Manim is incredibly cool, but my biggest takeaway from the video is how insane it is that Python apparently lets you reference a variable in a function that was defined outside the scope of the function.
Maybe I'm misunderstanding you, but isn't that standard for pretty much every C-style language? Define a variable outside a function, parallel to the function, and even though that variable is outside the scope of the function it's still accessible inside the function. Or did you mean something else?
In languages I'm most familiar with, you can't access variables defined outside of the function within the function unless the variable is a class or global variable. So for example in Python you can do:
irb(main):001> x = "hello"
=> "hello"
irb(main):002\* def test
irb(main):003\* puts x
irb(main):004> end
=> :test
irb(main):005> test
(irb):3:in `test': undefined local variable or method `x' for main:Object (NameError)
This makes much more sense to me, since x is defined outside of the scope of test, so why should test have access to it?
Python has nested functions which does allow access to the nest...er function's variables. The rest does conform to expectations, you get to use parameters, locally declared variables and globals.
I'm not too familiar with Python, but isn't that just lexical scope, the same as most languages that support nested functions? Starting with the lambda calculus and all the languages it influenced, including even JavaScript.
Correct. It behaves like JavaScript and many other languages. You can't modify such variables in the outer scope from the inner scope unless you explicitly use the "nonlocal" declaration.