r/cpp
•
u/steveklabnik1
•
Oct 24 '24
•
1
Why Safety Profiles Failed
https://www.circle-lang.org/draft-profiles.html
180
Upvotes
View all comments
Show parent comment
3
u/ContraryConman Oct 25 '24 edited Oct 26 '24
Uh, you can call regular functions from coroutines, you can call non const functions in const functions much of the time. Someone else mentioned inline, templates, classes, or structs-- you can call non-inline functions from inline functions just fine. Calling a template function doesn't require other functions being called to be templates.
I will maybe give you consteval, as everything in a consteval expression has to be a compile-time constant. I will also say that consteval, conceptually, is very straightforward and has little rules, whereas a safe keyword basically introduces a second language with different rules.
I don't think saying "types are viral annotations, so there" is as much of a gotcha as it seems because have you done any refactoring in a large codebase lately? Straight up changing the type of something is a pain in the ass. I changed one function argument from an int to an enum class the other day in our work's codebase and it was like multiple changes across multiple projects. It took like an hour. I think the way Herb worded P3466 was probably too strict, but if it is possible to avoid that kind of situation it is good in principle to do so. And it's not always possible, by the way
E: actually, another example of a viral C++ feature would be std::expected. We took it from modern languages like Rust that prefer functional-style error objects to exceptions. But using std::expected in one spot forces your entire call stack to pass std::expected objects around everywhere. It's a pain, it pollutes all your types, and it's not efficient. I actually think safe may actually be less of a hassle than std::expected can be, but it is a thing to think about