Memory safe in D

Alex akornilov.82 at mail.ru
Tue Mar 12 08:26:28 UTC 2024


On Tuesday, 12 March 2024 at 03:13:54 UTC, Walter Bright wrote:
> On 3/11/2024 3:42 AM, Alex wrote:
> Null references are not unsafe, that's why it is not in SafeD.

The Java has negative experience with null: 
https://www.infoq.com/presentations/Null-References-The-Billion-Dollar-Mistake-Tony-Hoare/
In modern C++ preference is given to `std::optional`.
For developer, who want make reliable software, it menas many 
rutinic checks for null. But mistakes are inevitable because of 
human factor. On other hand compiler can do it better (with 100% 
guarantee).

In my opinion, Kotlin nullable types with compiler vaidation in 
compilation time is a powerfull feature:

```d
A? a; // without explicit initialization is ok here, because 
<type>? can hold null

a.run(); // compilation error, because can be null (the type of 
"a" is "A?")

if (a != null) {
    a.run(); // ok, because can't be null in this branch (now type 
of "a" is "A")
}
```



More information about the Digitalmars-d mailing list