Hacker News new | ask | show | jobs
by nmrm 4442 days ago
The postscript is irrelevant to the claim made in the original post on this thread. It's a conflated example and not indicative of real programming.

if "get" returns different values when called multiple times within a single expression, one of two things must be true: * Someone's overriding "get" with a mutation to the variable. In all but the very rarest of circumstances, that someone should be publicly shamed. It's a nice hack for the purpose of the article, but not real code. * there's some very fine-grained concurrency. This case is irrelevant to the OP's claim because concurrency of this sort is very likely a fundamental characteristic of the system at hand, and never an artifact of the language.

1 comments

Which claim is that, exactly? And are you implying that the author's original solution is more indicative of real programming?

Both solutions work the same way - when accessing the value of "b" for the first check, b is mutated such that the next check will return a different value. Both of them are equally bad practices.

The == vs. === issue is the part that's actually irrelevant, it served as a red herring.

> Which claim is that, exactly? A

"This difference in how syntax is understood actually presents a barrier to programming for modestly trained mathematicians, who would otherwise be expected to excel."

> And are you implying that the author's original solution is more indicative of real programming?

Well, neither is... but yes, overriding == or .equals is somewhat common.

> when accessing the value of "b" for the first check, b is mutated such that the next check will return a different value.

The difference is that you could easily imagine a sane example where x == y != x === y, whereas it's hard to imagine a situation where I would want to override get (or ==) with a method that mutates the requested variable.

> The == vs. === issue is the part that's actually irrelevant, it served as a red herring.

For the claim re: syntax and compatibility with mathematician's expectation, it's exactly the other way around.

FWIW I feel the quoted claim re: syntax claim is interesting, whereas the contents of the article (summarily, "you can override == or .get and cause crazy stuff to happen") is unsurprising and kind of silly to most programmers even moderately experienced with OOP in dynamic languages (for the reasons given in this post and others -- everyone knows about it, it shouldn't take 11 days to figure it out, and in practice no one does purposefully obscure stuff like mutating values when == or .get is called).

edit: grammar