On Monday, 8 April 2024 at 20:21:35 UTC, Walter Bright wrote:
>The sad thing is if you don't want the GC in your program, don't use 'new'. I can never get this point across.
Also don’t use exceptions, don’t use lazy
, don’t use built-in dynamic and associative arrays, be careful to not accidentally allocate with an array literal:
if (arr[0..3] == [0, 1, 2]) { /*…*/ } // bad
int[3] arr2 = [0, 1, 2];
if (arr[0..3] == arr2) { /*…*/ } // good
…be careful to not accidentally create a closure:
int x;
auto r = arr[].map!(e = e*x); // bad
auto r = arr[].zip(x.repeat).map!(t = t[0]*t[1]); // good
…and don’t use a huge bulk of Phobos.
Writing no-GC code feels like walking through a minefield. Even seemingly innocent things like DateTime
can use GC internally.