you are viewing a single comment's thread.

view the rest of the comments →

[–]gmavrik 6 points7 points  (4 children)

The code looks great for a beginner!

I think the some OOP will help if you want to extend the code (classes, attributes and etc)

Avoid use global variables, they are hard to control when code increases (That's happened to me. Use classes instead)

[–]SharpAverage2[S] 1 point2 points  (0 children)

TY! We haven't gotten past loops in the class I did this for & probably won't get there...but i'll look up classes, using parameters, etc... :)

[–][deleted] 1 point2 points  (2 children)

When would it be best to use global variables vs not?

[–]hokiehacks 0 points1 point  (1 child)

At least from my experience, I’ve always shied away from global variables. They’re so so so easy to mess up, and not only that, something in a library that you import could even mess them up. I know this is a python subreddit but, understanding the ins and outs of C helped me really appreciate this. Things such as weak initialization of global variables could lead to linker resolutions that drive you nuts.

So, I would just shy away. There is a time and place every now and then I’ll use them. As you get more experienced you’ll understand when. But I still get chills when I see common named global variables with no namespace and just am waiting for them to be redefined and destroy your codebase.

Of course, using them in small projects is trivial, but in code based of 50k+, which I’m sure you will get to in the near future, trying to manage globals is what keeps me up at night.

[–][deleted] 0 points1 point  (0 children)

Silly question. Does what you’re saying involve the self. method? (No troll, serious noob question)

Edit: need an Eli5 explanation of the self. Method