-
Notifications
You must be signed in to change notification settings - Fork 266
Description
I really liked the fprintf
demo in the cppcon talk, but either I'm missing something (more likely) or it simply cannot work (sad).
In cpp1+cpp2 mode, let's assume we have this code:
struct S
{
int a;
};
get: (s: S) -> int = s.a;
Now we can call both:
a := get(s)
b := s.get()
So far so good. But let's say that S
is actually defined in some library's header file, and the author decides it would be a good idea to add a member callable, be it a member function, lambda, std::function
, function pointer, or whatever, that is also called get
.
In cpp1, that would be totally fine. In cpp2 however, it seems to me that it would break everything. Even if you add a rule saying that a member callable takes precedence over the one we defined in the first bit of code, that would still mean that b
's assignment now calls a different function, without us changing any of our code, only because of a library update that would be a-OK in cpp1. Backwards-compatibility broken, silently, and unexpected behavior that will be very fun to debug, I'm sure.
But it gets worse: if we define get
as a template instead:
get<T>: (t: T) -> int = ...;
part of the design goals as far as I understand is making cpp2 more toolable. But without concepts or something, Intellisense would probably show this as a member function of every single variable in your code.
Oh, and what about more basic stuff, like factorial? Cause this syntax looks kinda weird imo:
fact: (n: int) -> int = n ? (n * fact(n - 1)) : 1;
main: () -> int = {
std::cout << 5.fact(); //do I really want Intellisense to recommend every function that takes an integer whenever I type an integer?
}
I don't know, maybe I'm missing something, but it seems like something to think about for sure.