Re: named array

new topic     » goto parent     » topic index » view thread      » older message » newer message
TheresNoTime said...
mattlewis said...

Then I would agree that I don't understand the point. I updated the code you posted:

skipped

All I did was replace the narr stuff with map stuff. Note that you can also nest maps, and store and retrieve the data with a single call. Is there a reason you can't simply store the information inside of maps?

Yes, two reasons: 1. It is senseless to store same keys two times.
2. I needn't side effects.

It's not senseless if it makes life easier. Though I must admit that I don't see how using a map would be storing the key twice.

You're not getting more side effects with your narr implementation (OK, I guess you could manage it doing things completely differently). Anyways, with maps, you're just passing a reference to your data and manipulating it directly instead of passing and returning by value. Doing it by reference is likely to be faster, especially as the amount of data grows. The map library goes to a bit of effort to avoid unnecessary copies on write.

TheresNoTime said...

Add a few more types of people (BOSS, CRIMINAL, BEAUTY, ASSISTANT). Each of them has three HUNDREDS of properties. Most of the properties are common to all. You may be hard-working Chinese. I'm lazy Russian. I want to quickly write a program to get a drink of vodka and go ride on a tank drawn by bears.

Nah...I'm a lazy American. I do what's easy and then if there's some performance problem, I fix that. If you aren't having to deal with a lot of data (I believe this is what you said) then why worry about duplicating some things? Just use nested maps:

map:put( people, { person_key, "first name", "John"} ) 
map:put( people, { person_key, "last name", "Doe"} ) 
map:put( people, { person_key, "income", 50_000 } ) 
-- ...etc... 
 
map John_Doe = map:get( people, person_key ) 
 
map:get( John_Doe, "first name" ) 
 

Of course, you could wrap that and assign constants to stuff like "first name" to make it easy and pretty.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu