Memory safe in D

Walter Bright newshound2 at digitalmars.com
Tue Mar 12 17:47:32 UTC 2024


On 3/12/2024 1:26 AM, Alex wrote:
> 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).

Yeah, I know about that article. It's very popular. I've written a sort of rebuttal:

https://www.digitalmars.com/articles/C-biggest-mistake.html

With Java, it is also not a memory safety issue when there's a null exception.


> 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")
> }
> ```

It is always better to catch null mistakes at compile time rather than runtime, 
but it isn't a memory safety issue.



More information about the Digitalmars-d mailing list