Shouldn't safety be the default.

Hors q at q.com
Tue Dec 26 07:05:48 UTC 2023


Optional safety is really outdated, I think some people can't see 
how important is safety almost everywhere (both for system and 
general purpose). Safe by default allows you to catch bugs 
without possibly wrecking your entire system (or systems' of 
users of your app).
Some people are defending "Just don't make mistake" but we are 
all human and make mistakes, even experienced progammers can 
easily make mistakes, it's normal. So I think @safe should be 
default in dlang.

Advantages:
Not being scared to code - unsafe languages makes you scared to 
code (I experienced this the hard way) you usually never use the 
language's power at %100, because if you make mistake it can 
easily get you in trouble.
In @safe code, making mistakes and learning from them is easier.

Less security vulnerabilities - Mistakes throw helpful exception 
and halts program instead of causing security issues.

Also some myths about @safe:
"It's slow and uses a lot memory" - It is true that safe can be 
slower than unsafe and use more memory, but performance is not 
the only thing a language can offer. I am asking, did you ever 
hit %100 CPU usage or ran out of memory, yet still needed more 
performance or storage (ram), if it's the case I recommend you to 
first optimize code before switching to unsafe.

"It's protects agaisnt all security vulnerabilities" - It is true 
@safe can prevent some security issues, but not all of them, 
remember to never trust user input.


More information about the Digitalmars-d mailing list