Associative array mutation of a value

renoX renozyx at gmail.com
Mon Feb 10 07:13:57 PST 2014


On Friday, 7 February 2014 at 20:22:54 UTC, Idan Arye wrote:
> I'm always for little helper functions, but I don't think 
> Erlang's idiom of using maps as records is good for D. That 
> model works well with dynamic typing, where record types are 
> meaningless and only their structure is important(JavaScript is 
> fine example). With static typing it's better to declare a type 
> for the record, so whether the field you are trying to set 
> exists or not can be checked at compile-time.

The thing is, you don't always have those key at compile time..

Anyway, the discussion here is about map not record and IMHO it 
is a good idea to have two short functions for 'replace an 
existing value' and 'add a new key' then a long one for 'do both' 
because users tend to use short names and from a maintainability 
point of view, it's much better to know what was the exact 
intended meaning of the one who wrote the code, instead of having 
to guess, he wrote "array[key] = value" did he want to add the 
key or did to replace an existing key?

BR,
renoX


More information about the Digitalmars-d mailing list