News for hackers. Stuff that matters.
Re:How I Animate 3Blue1Brown by chris12321 on Saturday October 19, 2024 @10:10AM (#41887853)
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:

  >>> x = "hello"
  >>> def test():
  ...     print(x)
  ...
  >>> test()
  hello
which seems very odd to me. In Ruby you get:

  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?

There are no comments on this comment yet.