Okay, I am confused on the global statement. To my knowledge it lets you easily access variables from a function to be used in the session. Now someone said that it's useless and you shouldn't use it in your code. Is this true?
AutoPython 5 Junior Poster
Recommended Answers
Jump to PostAs your code gets more complex and longer, a function could change the value of the global variable and make your code buggy. This kind of bug might be hard to figure out! Now your life has just been made a lot harder!
Jump to PostWell, I always set the global variables in the function to a new variable, then delete the original global variable. So then would the new variable (outside the function) inherit the global trait?
Can you give us an example?
Jump to PostGribouillis is right, global constants have their place, but like he mentioned, make them stick out. One time when all upper case is appropriate.
Jump to PostI was once a fond of global variables as "child" programmer.
As I went on coding, things turned harsh on me. Thanks God I then learned OOP. In OOP, you do alot of stuffs without global variable.
I have forgotten even last time i used global keyword. all I remember …
All 16 Replies
JugglerDrummer 0 Junior Poster
AutoPython 5 Junior Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
AutoPython 5 Junior Poster
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
AutoPython 5 Junior Poster
Gribouillis 1,391 Programming Explorer Team Colleague
sneekula 969 Nearly a Posting Maven
jice 53 Posting Whiz in Training
AutoPython 5 Junior Poster
Stefano Mtangoo 455 Senior Poster
snippsat 661 Master Poster
jice 53 Posting Whiz in Training
AutoPython 5 Junior Poster
Gribouillis 1,391 Programming Explorer Team Colleague
AutoPython 5 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.