[DGD] Inherited objects list

Erwin Harte harte at is-here.com
Fri Oct 28 15:06:01 CEST 2005


On 10/28/05 4:40 AM Lord Lerkista wrote:
[...]
> I've another question, it's safe to remove all variables and use mappings??
> For example:
> 
> int ac;
> int weight;
> string name;
> string short;
> 
> ac = 10;
> weight = 5;
> name = "shield";
> short = "a small wooden shield";
> 
> i want to do something like this:
> 
> mapping vars;
> 
> vars = ([ ]);
> 
> vars["ac"] = 10;
> vars["weight"] = 5;
> vars["name"] = "shield";
> vars["short"] = "a small wooden shield";
> 
> I like this way because i can get a list of variables - values from any 
> object
> Any disadvantage of this method??

Aside from what Mordengaard wrote, you would be able to do:

   vars["ac"] = this_object();
   vars["weight"] = "Hello World";
   vars["name"] = -1;
   vars["short"] = 0.0;

And the compiler wouldn't stop you when compiling the code because it has 
no idea that vars["ac"] should probably be an integer value, etc.

So you lose the compiler-enforced distinction between static, private and 
regular variables, you can run into conflicts between variables from 
different (inherited) programs, and you lose type information.

Cheers,

Erwin.
-- 
Erwin Harte <harte at is-here.com>



More information about the DGD mailing list