Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • -1. Writing to database depends on external state that generally cannot be determined looking on the inputs. The database may be unavailable for a number of reasons and whether the operation will succeed is not predictable. This is not deterministic behavior. Commented Nov 1, 2018 at 8:06
  • @Frax System memory might be unavailable. The CPU might be unavailable. Being deterministic doesn't guarantee success. It guarantees that successful behavior is predictable. Commented Nov 1, 2018 at 9:48
  • OOMing is not specific to any function, it is different category of problem. Now, let's just look at point 1. of your "pure function" definition (which indeed means "deterministic"): "The function result value cannot depend on any hidden information or state that may change while program execution proceeds or between different executions of the program, nor can it depend on any external input from I/O devices". Database is that kind state, so OPs function clearly doesn't fulfill this condition - it isn't deterministic. Commented Nov 1, 2018 at 11:11
  • @candied_orange I would agree if the write to the DB was dependent on the inputs only. But it's Math.random(). So no, unless we assume a PRNG (instead of a physical RNG) AND consider that PRNGs state part of the input (which it isn't, the reference is hardcoded), it's not deterministic. Commented Nov 1, 2018 at 11:14
  • 2
    @candied_orange your citation of deterministic states "an algorithm whose behaviour can be completely predicted from the input." Writing to IO, to me, is definitely behaviour, not result. Commented Nov 1, 2018 at 12:51