Memory safe in D

Alex akornilov.82 at mail.ru
Thu Mar 14 08:17:00 UTC 2024


On Thursday, 14 March 2024 at 02:09:15 UTC, Steven Schveighoffer 
wrote:
> No, Kotlin also performs a check at runtime. The same hardware 
> runs the machine code, and the MMU is the same one that runs D 
> code.
>
> However, the check is not considered to cost anything. It's 
> part of how the MMU works.

Yes, sure, you right. Checks will be in runtime too and thanks to 
MMU hardware checks are cheap.

To be clear:
- Kotlin compiler rejects code wthout all required null reference 
checks for nullable type.
- Null refrence checks will be performed in runtime (like in D).
- Kotlin compiler give 100% guarantee that null pointer exception 
never happend in runtime (exclude unsafe operations where 
developer take responsibility).

I give Kotlin as example because familar with it, but other 
languages with null safety do something like this.
And this powerful feature is possible thanks to language type 
system. The nullable type is special case of cool idea - the 
union type:
https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html
http://web.mit.edu/ceylon_v1.3.3/ceylon-1.3.3/doc/en/spec/html_single/#unionandintersectiontypes



More information about the Digitalmars-d mailing list