Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUGGESTION] move away from std::cout << #89

Closed
h-vetinari opened this issue Oct 22, 2022 · 2 comments
Closed

[SUGGESTION] move away from std::cout << #89

h-vetinari opened this issue Oct 22, 2022 · 2 comments

Comments

@h-vetinari
Copy link

h-vetinari commented Oct 22, 2022

There's been a lot of work in C++20/C++23 around text handling, and formatting/printing in particular. From the goals laid out in the readme, the "feels like a new language" should IMO definitely apply to one of the cruftiest (again IMO) corners in common syntax (so common it's in the splash example...) - the overloaded bitshift and std:cout.

In other words, I think a better advertisement for cpp2 could be (using P2093; also matches import std; default):

main: () -> int = {
    print("Hello, {}!", "world");
}

rather than

main: () -> int = {
    std::cout << "hello world!";
}

In the broader scope, this would also need some decent string manipulation APIs (concatenation, slicing, etc.), which C++ is lacking quite a bit. Xref also #45

@gregmarr
Copy link
Contributor

I think part of the reason that this particular example was used is that it is the "classic" hello world from C++98, and shows that you can easily convert it to Cpp2, and also that compiling with import std; is faster than #include <iostreams> for the same program. So it's a good "conversion" story. I agree that your version is a good "next generation" example.

@hsutter
Copy link
Owner

hsutter commented Nov 26, 2022

Yes, I absolutely do love C++23 print and I considered showing it.

But:

  • none of the vendors implement it yet... here is a Godbolt link for std::print Hello world using "trunk/latest" for Gcc, Clang, and MSVC... as of today not one of them compiles it, though I hope this link should gradually show them supporting this in the future)
  • a major point of using the usual cout << "Hello"; example is to bold-underline-italic-double-underscore that this is C++, you can use the whole standard library and operator overloading etc.

I'm definitely watching it though, and when it's shipping I can start showing it. Also, as soon as the C++ vendors do implement it, it will work seamlessly in Cpp2 via cppfront. :)

Thanks!

@hsutter hsutter closed this as completed Nov 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants