this post was submitted on 17 Sep 2024
36 points (95.0% liked)

C++

1778 readers
1 users here now

The center for all discussion and news regarding C++.

Rules

founded 1 year ago
MODERATORS
36
submitted 2 months ago* (last edited 2 months ago) by cmeerw to c/cpp
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] -3 points 2 months ago (2 children)

Rust still allows people to do (basically) whatever they want via unsafe blocks.

[–] FizzyOrange 8 points 2 months ago (2 children)

Yeah but I have written a lot of Rust and I have yet to use a single unsafe block.

Saying "but.. unsafe!" is like saying Python isn't memory safe because it has ctypes, or Go isn't memory safe because of its unsafe package.

[–] [email protected] 1 points 2 months ago (1 children)

You don't have to use unsafe C++ functions either

C++ is technically safe if you follow best practices

The issue, to me, is that people learn older versions of the language first, and aren't aware of the better ways of doing stuff.

IMO people should learn the latest C++ version first, and only look at the older types of implementation when they come across them

[–] FizzyOrange 2 points 2 months ago (1 children)

C++ is technically safe if you follow best practices

Yeah but it's virtually impossible to reliably follow best practices. The compiler won't tell you when you're invoking UB and there is a lot of potential UB in C++.

So in practice it is not at all safe.

[–] [email protected] 4 points 2 months ago

I agree

I was only adding my opinion (that people should try to always use the latest version of C++, which is inherently safer, but still not 100% safe)

[–] [email protected] -5 points 2 months ago

See my reply to funtrek's reply.

[–] [email protected] 7 points 2 months ago (1 children)

Sure, but you have to explicitly enable this feature. In c++ you can use the oldest shit from twenty years ago and your compiler happily does its job. All my c++ books are full of "you shouldn’t use xy as it is deemed unsafe now, but of course you still can".

[–] [email protected] -4 points 2 months ago (1 children)

If a "safe C++" proposal truly proposes a safe subset, then yes your C++ code would have to opt-in to doing unsafe things. For the purposes of this discussion of a safe subset ... the point is moot.

[–] FizzyOrange 6 points 2 months ago (1 children)

It's not moot. The Safe C++ is opt-in to safety. It has to be because otherwise it wouldn't be compatible with existing C++.

[–] [email protected] -3 points 2 months ago* (last edited 2 months ago)

That's a laudable difference /s. Using Rust is also an "opt-in" option.