Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

According to The Principle of Least Surprise (Principle of Least Astonishment, POLA)[1] there is should be a symmetry: either a function receives a single input value, and returns a single output value, or it may receive multiple values and return multiple values, any other combination is problematic.

The only advantage to multiple inputs - single output, is that it's resembling the math notation, but it also inherits all of its shortcomings, and obviosly it wasn't designed with computers in mind.

Same with function taking or returning 0 values (e.g. void).

Function receiving 0 inputs should be a constant.

Function returning 0 outputs, is a procedure with a side-effect, and should be implemented using a different construct.

---

1. https://en.wikipedia.org/wiki/Principle_of_least_astonishmen...



> According to The Principle of Least Surprise (Principle of Least Astonishment, POLA)[1] there is should be a symmetry

I'm not sure you can say that. You might be the only one surprised by multiple inputs single output.


What's more predictable: symmetry or assymetry?

Why there is so much symmetry in our world (Nature)?


I’m not sure what the name for this fallacy is. Appeal to unrelated concept?

Among the first functions children learn are things like addition of two numbers which lack this supposedly natural property.


IMO you mistaken math-like infix notation with the number of arguments function receives.

  Tuple(Number,Number) -> add -> Number|Overflow


Depends how you imagine a function. Just imagine it like a funnel. Your argument is honestly at the very least irrelevant.


def add(a: int, b: int) -> int: return a + b

is this surprising to you ?


Yes, since I was a kid.

My first real computer was an RPN calculator.

Also one of my first programming textbooks back then used an educational PL which allowed multiple return values (late 80s).

I think in terms of data flows and circuits, so it’s natural for me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: