Answer the question
In order to leave comments, you need to log in
Is using a global variable considered shitty code?
I am freelancing and when I did the project I used something like data = {key: value} and imported it into some functions as global data. When I handed over the project, this moment was said to be redone without explanation. Why?
Answer the question
In order to leave comments, you need to log in
Yes. Global variables are an anti-pattern in many, if not all, programming languages.
Global variables are a normal tool. For example. here is from the official flask documentation. As an example of using a global variable to store a database connection.
from flask import g
def get_db():
if 'db' not in g:
g.db = connect_to_database()
return g.db
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question