In dynamic programming language like Python, Javascript, it's very easy to make a function return an object:
def make_vector2(a, b):
return {"x": a, "y": b}
The 'signature' of the returned object from make_vector2
acts as a protocol or interface to other functions.
For example:
def norm(v):
return math.sqrt(v["x"]**2 + v["y"]**2)
During the evolution of a program, there may be changes on the signature of the returned object.
For example, I would change above vector definition to {"x0": a, "x1":b}
.
This protocol change may invalidate its related functions(i.e. norm
in above example).
In static programming language, I have compiler help me to keep the protocol consistent. While in dynamic programming language I cannot detect the problems unless I actually run the code.
Is there any suggestions/good tools for this problem?