3 ms·
Not sure why the author compares Rust's: println!("{} is {} years old", person.name, person.age); with C++: cout << person.name << " is " << unsigned
by einpoklum 2y ago
Not sure why the author compares Rust's:
println!("{} is {} years old", person.name, person.age);
with C++:
cout << person.name << " is " << unsigned(person.age)
<< " years old" << endl;
... while C++ actually has:
println("{} is {} years old", person.name, person.age);
essentially identical to Rust. See: https://en.cppreference.com/w/cpp/io/println https://en.cppreference.com/w/cpp/io/println
- glandium 2y agoProbably because it's very new (C++23)
- vlovich123 2y agoWell C++23 is fairly new so they probably just didn't know about it?
- cjfd 2y agoSome people are noticing that println is very new. But there already is https://github.com/fmtlib/fmt https://github.com/fmtlib/fmt and it has been there quite a long time.
- Philpax 2y agoThat would require introducing a dependency, which is a digression from the point of the article and would complicate reproduction for the reader.
- bangaladore 2y agoI can assure you that using a new language is a substantially greater task than introducing a dependency (or using -std=c++23). So you might as well show off the latest and greatest for all the competitors.
- account42 2y agoUsing random libraries in example code isn't good practice though. Still, even (C) printf would have been better than the iostreams monstrosity.
- tovej 2y agofmt is not a random library, it's the inspiration and reference implementation for std::format
- Aurelius108 2y agoIt’s very new to the standard library (latest version of GCC this year was the first version to support it). Additionally, I’ve found that println adds 30+ seconds to my compile time even for hello world so I’ll be avoiding it unless I need it
- einpoklum 2y ago> It’s very new True, but Hylo is so new that it's not even an established language. Plus using this should serve to higlight the differences the author actually cares about between the languages.
- bangaladore 2y agohttps://godbolt.org/z/MTo11voes https://godbolt.org/z/MTo11voes > println takes 9 seconds https://godbolt.org/z/he6Phr7nG https://godbolt.org/z/he6Phr7nG > cout takes 6 seconds What machine / compiler are you on where the difference between these are 30 seconds? GCC is also quite a bit faster based off a quick tests in godbolt.
- nicce 2y ago> https://godbolt.org/z/MTo11voes https://godbolt.org/z/MTo11voes > println takes 9 seconds https://godbolt.org/z/he6Phr7nG https://godbolt.org/z/he6Phr7nG > cout takes 6 seconds That is 50% increase.
- bangaladore 2y agoI don't believe I claimed anywhere it is not a 50% increase. The OC said 30 second difference.
- nicce 2y agoI missed the "Hello, world!" mention, but otherwise you only need to have 10 prints in your whole project to have the 30 second increase. That is pretty significant.