[Info-vax] Unsafe coding, was: Re: Rust as a HS language

Simon Clubley clubley at remove_me.eisner.decus.org-Earth.UFP
Wed Apr 6 08:25:42 EDT 2022


On 2022-04-05, Arne Vajhøj <arne at vajhoej.dk> wrote:
>
> I think there is a big difference between what older languages (Ada,
> Pascal etc.) did and what Rust/C# does with unsafe blocks.
>
> The older languages typical enable/disable per compilation
> unit and common practice is to enable/disable for the entire
> project.
>
> (admitted Ada can simulate a block with pragma's)
>

That is most certainly _NOT_ what Ada does. Not at all.

In Ada, you don't need unsafe blocks as the unsafe attributes are
on specific uses of a variable, and not even on the variable as a
whole. That means you can do one very localised unsafe thing while
the code immediately surrounding that unsafe thing is still subject
to full checking.

A couple of examples:

https://www.adaic.org/resources/add_content/docs/95style/html/sec_5/5-9-3.html

for Unchecked_Access and:

https://www.adaic.org/resources/add_content/docs/95style/html/sec_5/5-9-1.html

for Unchecked_Conversion. With Unchecked_Conversion, you even get the
Valid attribute so you can check in a controlled way that what you have
done is acceptable so you don't even have to blindly hope that an unchecked
conversion is ok.

I like Ada.

Simon.

-- 
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Walking destinations on a map are further away than they appear.



More information about the Info-vax mailing list