if you use it in a different part of your program you should also make it a global
There's a whole semi-religious argument about globals. (Java, for instance doesn't allow them at all, sort of, whereas in some early versions of basic, all variables were global). There are basically two ways to cope with much-used data:
Make it global
It is easy to view (in Python), but requires you to declare it global if a function needs to alter it
In the presence of threads, there are potential race conditions or serialization through locking
It is somewhat harder to reason about what the program does because you don't know exactly which other functions may touch it without examining the entire program.
Make it local and pass it around as argument to functions that need it
It is a little harder to deal with because functions have to accept it as a parameter, and calling code needs to pass it
In the presence of threads it is easier to prevent race conditions: Either pass a copy or pass a locking object along with it.
It is easier to reason about which functions have access to it: They name it in their parameter lists
As a general rule, I think that global data is if not downright bad, at least a little distasteful; so I oppose a generic broad-brush 'Make your data global'. And bear in mind that Python passes arrays by reference, so there is small cost to passing an array to a function.
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.