r/javascript • • Aug 27 '16

Is your JavaScript function actually pure?

http://staltz.com/is-your-javascript-function-actually-pure.html
8 Upvotes

48 comments sorted by

View all comments

Show parent comments

-3

u/DanielRosenwasser TypeScript Aug 27 '16

I'm not sure if you read through the whole thing, but that's sort of the point of the article. There's crazy stuff you can do in JS, but for the most part there are ways that are good enough to run with certain assumptions. Otherwise you'll vex over these ridiculous corner cases and never get anything done.

0

u/[deleted] Aug 27 '16

[deleted]

1

u/vinnl Aug 28 '16

I think the main point is not that you should or could breach the contract, but rather to make you aware of the implicit parts of the contract, and how you can make some parts of it explicit as desired. For example, passing undefined or null when an actual value is expected is a breach of contract that does happen in practice, so you might want to defend against that.

1

u/Reashu Aug 28 '16

Then arguing about function purity is just... I don't know the English idiom, but it's an unnecessary and uninteresting complication.

1

u/vinnl Aug 28 '16

I suppose that depends on how you learn best. For me, it helps to understand the bigger picture and abstract concepts so I will be able to generalise it to future situations.

1

u/Reashu Aug 28 '16

But purity is not the "big picture" of function contracts. It is a special case, and one of the more thorny ones, to boot.

1

u/vinnl Aug 28 '16

But there is a scale of contracts in terms of how pure your function is, and they're easy to overlook - this article focuses on that bigger picture rather than just passing in undefined. But yes, I consider a look at more extensive typing systems and their encoding of function contracts (i.e. an even bigger picture) to be interesting as well.