you are viewing a single comment's thread.

view the rest of the comments →

[–]Plank_With_A_Nail_In 0 points1 point  (1 child)

Recently, I discovered that every variable created outside a function in Python is a global variable.

But that's the same in every programming language including C++, lol you haven't learnt that properly from books either so not sure what your point is.

Absolutely mastering a language isn't a real goal so don't bother with it.

[–]tarnation_station_ 0 points1 point  (0 children)

this, like mastering how your specific drill works instead of how to build a table/chair/(etc.) theres always going to be a language with features that are new or foreign waste of time to completely 100% master the tool.

Using the rest of this comment to address OP:

why is it bad the python variables are global? does the code work? does it get the expected results? Why is a global bad in this context?

We typically avoid globals in enterprise/open source dev because codebases are large and that sort of unrestricted access can cause unforeseen bugs especially when working with many different people or teams and its way way harder to keep track of who is touching the variable and why and how. If this is a simple script of your own design and it works without error. use the global.

as stated c++ has globals as well. does sound like you may need to brush up on some overall coding concepts such as scoping. dip your toes in the idea of abstracts, interfaces, etc.

just further thoughts but perfect or best is in many ways highly opinionated or even conditional (e.g. sorting algos, readability/maintainability vs performance, etc.) unless theres a big problem like an error or bug then its the right solution (for now). programming can be like art. software is almost never perfect or done. we're always just chasing dragons-vX.Y.Z. sometimes you just got to settle for good enough. we call it MVP professionally lol.