News for hackers. Stuff that matters.
Re:It's not what programming languages do, it's what they sh... by ghostwriter on Friday March 27, 2020 @10:02AM (#22702877)
> As long as the function performing the I/O doesn't affect the outcome of the computation, everything is safe.

except it's not! Your IO action may not affect the outcome of the computation but it may launch the missiles in background, which changes everything. The less contrived example would be - "computation is fine and is not affected, yet we have our [production cluster deleted / disk space run out / money sent to wrong recepients] by the IO action".

Re:It's not what programming languages do, it's what they sh... by nybble41 on Friday March 27, 2020 @06:34PM (#22707524)
Despite the name, unsafePerformIO isn't automatically akin to undefined behavior in C. It can cause undefined behavior if misused, the most obvious example being the creation of polymorphic I/O reference objects which act like unsafeCoerce—but that would be affecting the outcome of the computation. If the value returned from unsafePerformIO is a pure function of the inputs then the only remaining risk is that any side effects may occur more than once or not at all depending on how the pure code is evaluated. As long as you're okay with that there isn't really any issue with using something like Debug.Trace for its intended purpose, debugging.

There are better ways to handle logging, of course—you generally want your log entries to be deterministic, and the ability to produce log entries (as opposed to arbitrary I/O actions) should be reflected in the types.

Re:It's not what programming languages do, it's what they sh... by gowld on Friday March 27, 2020 @11:31AM (#22703689)
Debug.Trace doesn't launch missiles or delete clusters or send money. It might run you out of disk space, but so can safe IO.