4 ms·
I've never used Flask before and come from mostly PHP/JavaScript. One of the first things that struck me reading the tutorial was the use of "g" which seems to
by 12907835202 4y ago
I've never used Flask before and come from mostly PHP/JavaScript.
One of the first things that struck me reading the tutorial was the use of "g" which seems to stand for "global" and is used to access things like the DB via "g.db".
This seems similar to using $GLOBALS['db'] in PHP which would be a code smell and I think it's impossible as of PHP 8.1.
If I saw this in a PHP Framework I would assume it was made by an amateur. Can anyone explain if this is common practice in Python and perhaps why it's different and not a worry?
- teen 4y agousually there is a single interface to a DB. whether that's supplied via import / dep injection / global is specific to the language / framework. there are pros and cons with each.