NonNull template
kdevel
kdevel at vogtner.de
Mon Apr 21 11:15:38 UTC 2025
On Sunday, 20 April 2025 at 22:19:39 UTC, Jonathan M Davis wrote:
>> I consider nonconforming generally inacceptable.
>
> Writing a program which doesn't behave properly is always a
> problem and should be consider unacceptable.
The problematic word is "behave". Only recently there was a
thread on reddit where the user Zde-G pinpointed the
problem while discussing a "new name" for undefined
behavior (UB) [5]:
'90% of confusion about UB comes from the simple fact
that something is called behavior. Defined, undefined,
it doesn't matter: layman observes world behavior,
layman starts thinking about what kind of behavior can
there be.
The mental model every programmer which observes that
term for the first time is “some secret behavior which
is too complex to write in the description of the
language… but surely I can glean it from the compiler
with some experiments”.
This is entirely wrong mental model even for C and doubly
so for Rust or Zig. And it takes insane amount of effort
to teach **every single newcomer** that it's wrong model.
I have seen **zero** exceptions.
New name should talk about code, not about behavior.
“Invalid code” or “forbidden code” or maybe “erroneous
construct”, but something, anything which is not related
to what happens in runtime.
There are no runtime after UB, it's as simple as that.
The only option if your code have UB is to go and fix
the code… and yet the name doesn't include anything
related to code at all and concentrates on entirely wrong
thing.'
> [...]
>
> If you create a reference from a null pointer, you have a bug
> whether the program is written in C++ or D.
That is not true. A D program like this:
void main ()
{
int *p = null;
ref int i = *p; // DMD v2.111.0
}
is a valid program and there is no UB, no crash and no bug.
I already pointed this out earlier with reference to the D spec.
[3].
[3] https://dlang.org/spec/type.html#pointers
"When a pointer to T is dereferenced, it must either contain
a null
value, or point to a valid object of type T."
[5] Zde-G kommentiert Blog Post: UB Might Be a Wrong Term for
Newer Languages:
https://old.reddit.com/r/rust/comments/129mz8z/blog_post_ub_might_be_a_wrong_term_for_newer/jep231f/
More information about the Digitalmars-d
mailing list