views:

39

answers:

2

Are there techniques for this, or does it come down to the individual language and compiler?

+2  A: 

Dictionaries, HasSets, HashTables, Associative Arrays, or similar are the thing to look for. The usually provide O(1) access to the named parameters.

Obalix
And are positional parameters faster than O(1)?
Zubair
No, they are also O(1) operations.
Obalix
O(1) means constant, there is nothing really faster then O(1).
Vlad
Ok, briliant, I see no reason to use positional parameters then
Zubair
Goof reasons to use positional parameters is to save on typing and improve clarity of the code. This usually applies to methods that have gazillions of parameters and you are happy with most of the defaults.
Vlad
@Zubair: Whether to use positional or named parameters depends upon teh the problem you are looking at. If you have a list that has an order and needs to be iterated over, then positional access is the way to go. If you have a dictionary (key value pairs) and the order of the items does not matter than named access is preferred. There are also constructs (e.g. SortedList in c#) that provide for both access methods at the same time (with O1 access).
Obalix
A: 

Have the compiler convert the named parameter to a positional parameter at compile time.

Which will certainly depend on the language and the compiler.

nos
Are there compilers that already do this?
Zubair