Hacker News new | past | comments | ask | show | jobs | submit login

Why must every educational python library insist on teaching kids with global variables? I know parameters aren't easy for novices, but it feels like it's missing a lot of the value when we don't attempt to teach them...



Because it's perfectly fine for 100 line programs. Beginners don't need to write extensible code that will be maintained for 30 years on business critical systems. You start by learning what a fuckin for loop does.


Not only that, it's a relatively gentle introduction into object oriented concepts, where an instance is just like independent copies of modules, as they're using them: module.function(), with function accessing some global conceptually turns into instance.function() where function accesses some instance "global".

I was always a bit surprised that python didn't allow "module instances" that automatically did that.


Honestly the way I learned not to use a ton of global variables was because I used so many and would forget what they'd do. But that was back in the days of Apple // BASIC so when I was introduced to C I rejoiced. People need to learn from mistakes.


For me, I learned when I wanted all my function calls to do the same thing no matter how many times, or order, I called them.

I often wonder how much "pain" is required to really learn something. I would claim that 90% of how I write code is the result of pain, not patterns, even though they often end up being similar.


Because the concept of variables must be learned before the concept of scope.


True, but having a single scope is more intuitive at first for people who don't have a good grasp of what a function is and are still trying to understand programming. Also processing/p5 kind of focuses on the speed and accessibility of getting an idea going, for which a game-loop and a single func scope are quite powerful!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: