How purity w/o the specific optimizations then allowed is useful ?

Timon Gehr timon.gehr at gmx.ch
Tue Apr 16 16:17:15 UTC 2024


On 4/16/24 17:07, Basile B. wrote:
> Short story for the context : someone has recently proposed the concept 
> of purity for FreePascal, and only for their own dialect (aka _ObjFPC_). 
> The proposition is to "check purity only when optimizations are enabled, 
> because essentially the point of purity is only to optimize more" (think 
> CTFE, think memoization).
> ...

Well, that is awful reasoning, but many language designers fall into the 
non-orthogonality trap due to a lack of imagination.

In contrast, D properly separates debug builds and optimized builds. 
(Within `debug` statements, `pure` is not checked.)

> But [I fail to explain the 
> opposite](https://gitlab.com/freepascal.org/fpc/source/-/merge_requests/645#note_1863564617). How is purity a useful concept if not leading to specific optimizations ?
> 
> And is that even the case ?
> 
> Side note: I dont plan the use your answers to arguee w/ the author. 
> It's more that conceptually I'm interested.

Purity enables reasoning based on determinism and commutativity and it 
implies that the involved data structures can have multiple instances.

Optimizations are one application of this improved capability for 
abstract reasoning.

(Of course, unfortunately in D determinism of `pure` functions is not 
properly ensured at the moment.)


More information about the Digitalmars-d mailing list