math - Right behavior for variable-arity sum function -
i'm defining variable-arity sum function toy language. seems natural me allow called without arguments , return 0, real languages (and implementations) disagree among themselves.
is there use-case returning 0 less correct throwing exception?
mathematically speaking, empty sum (the sum of no numbers) defined zero. mathematically correct, returning 0 seems proper choice here. throwing exception in case potentially complicate use of function, since have sure guard each call try/catch in case provide 0 arguments somehow.
hope helps!
Comments
Post a Comment