Quick design question. How come when I pre-declare a global list I need to have:
var/L = list()
Why is it not good enough to have:
var/list/L
I've noticed if I do the latter, I cannot simply add items to the list using += in a proc elsewhere in the code.
ID:152174
Nov 18 2007, 8:32 am
|
|
Nov 18 2007, 8:41 am
|
|
I'm not sure, but not having list() after it means it's null, not a list. Having /list means you can do the list procs.
|
For
var/list/L
You can have the following as well, which defines the variable as a list AND initializes it: var/list/L=new() |
In response to GhostAnime
|
|
Is there any time you'd want to declare a list and not initialize it?
|
In response to BigJMoney
|
|
Yes. Say each player has a Special Weapns list. Not every player would need this list, since they won't all get special weapons. BYOND will only allow you to have a certain number of lists initialized at runtime. 65535, if I recall correctly. That may seem like a lot, but if you take into consideration all the lists a game could have, it adds up pretty quick.
So back to the special weapons. It's best for lists that you aren't sure you'll actually use all the time, not to initialize them at the start of the game, since you'll have a bunch of empty lists taking away from your total number that are not actually being used, just taking up space. LummoxJR is a big proponent of what he calls List Husbandry. It basically means only initializing lists when you need them, and nullifying any lists you are no longer using. Basically, everytime you want to work with a list, you first check to make sure it's not null. If it is null, do a list = new() before working with it. When you remove items from a list, or do anything that might result in the list being empty, check to see if it is empty and if it is, set it to null so it doesn't take away from your total number of lists. It's just good programming practice to always make sure your lists are being used, and to nullify the ones that aren't. ~X |
In response to Xooxer
|
|
Thank you.
|