3 ms·
it's all about surprises. Programmers hate them. You want to be able to reason about your code For example: fact: a == b fact: f(x) is p determini
by toolslive 6y ago
it's all about surprises. Programmers hate them.
You want to be able to reason about your code
For example:
fact: a == b
fact: f(x) is p deterministic pure function.
So I figure f(a) == f(b)
Well, maybe... Javascript (obviously) and Python are amongst the programming languages where the above reasoning is not true. (there are exceptions).
- masklinn 6y ago> Well, maybe... Javascript (obviously) and Python are amongst the programming languages where the above reasoning is not true. (there are exceptions). There are lots of exceptions. For starters (2) seems like an assumption rather than a fact. An other assumption which is just that is that equality is transitive through f. This is not a generalised fact in any language which allows overriding equality.
- masklinn 6y ago> An other assumption which is just that is that equality is transitive through f. This is not a generalised fact in any language which allows overriding equality. Simple example: hashsets equality & conversion to sequences. Hashset equality, to the extent that it's present, is always based on the presence of items in the set. But the iteration order of two hashsets with the same contents can depend on the way they were initialised (as that influences whether collisions happen) and the order in which items were added. So given a and b be hashsets and f be toArray (or whatever), it is very common to have a == b but f(a) != f(b).
- toolslive 6y agoeven with the python `int`s a: int, b:int and the `str` function as the pure deterministic function you still cannot make the conclusion. It's an utter mess