Method/Function arguments: Value then index or vice versa
-
26-06-2021 - |
سؤال
Which would you do:
setter(index, value)
or
setter(value, index)
المحلول
I would say the first. I normally put the high level argument first, i.e. the index decides where to place the value in.
From a computer's perspective: first you need the location of where to store, when that is found, the value can be set.
It is similar as setting a property of e.g. an element of a car:
SetWheelDiameter(CarModel model, Part.Wheels, Wheel.Diameter, 19.0) Parameters are from high level to low level.
نصائح أخرى
Googling:
"T value int index"
suggests that it is a lot more common than:
"int index T value"
لا تنتمي إلى StackOverflow