Post B1kh4FSeCYBsAXBYvo by amonakov@mastodon.gamedev.place
(DIR) More posts by amonakov@mastodon.gamedev.place
(DIR) Post #B1keXwJhdzoTcRT52e by amonakov@mastodon.gamedev.place
2025-12-29T20:09:27Z
0 likes, 0 repeats
I/O by chaining applications of operator() — like print("Hi, ")(username)('\n'), as in https://godbolt.org/z/jzMzva749
(DIR) Post #B1keXx9oWFUsE3qhGa by wolf480pl@mstdn.io
2025-12-29T20:16:06Z
0 likes, 0 repeats
@amonakov I voted "hideous", but tbh it's only mildly bad taste
(DIR) Post #B1kenPVDPlqKTrEJd2 by amonakov@mastodon.gamedev.place
2025-12-29T20:18:57Z
0 likes, 0 repeats
@wolf480pl worse or better than chained applications of operator<< ?
(DIR) Post #B1kfMbQj3ml3bnuXZI by wolf480pl@mstdn.io
2025-12-29T20:25:20Z
0 likes, 0 repeats
@amonakov IMO worse, but that might be because I'm used to the << syntax
(DIR) Post #B1kg4LTfjSXOsI9BgG by amonakov@mastodon.gamedev.place
2025-12-29T20:33:13Z
0 likes, 0 repeats
@wolf480pl aren't we allbut printing one thing should be print(thing)! and then the rest falls out from thatok, how about chained applications of operator, ? https://godbolt.org/z/KfnMd6qcz
(DIR) Post #B1kgzrr21q4tnOVCAy by wolf480pl@mstdn.io
2025-12-29T20:43:38Z
0 likes, 0 repeats
@amonakov I like this more. Although varargs has all of its benefits...
(DIR) Post #B1kh4FSeCYBsAXBYvo by amonakov@mastodon.gamedev.place
2025-12-29T20:39:25Z
0 likes, 0 repeats
@wolf480pl or more lisp-flavoured https://godbolt.org/z/d1cnKbqTo
(DIR) Post #B1kh4GnbE8XoJnzoEC by wolf480pl@mstdn.io
2025-12-29T20:44:23Z
0 likes, 0 repeats
@amonakov ok, now this is something worth hating!
(DIR) Post #B1m71Xk0ZXYdxddWam by wolfpld@mastodon.gamedev.place
2025-12-30T11:27:14Z
0 likes, 0 repeats
@amonakov @wolf480pl Better, because much easier to shoot down. With << chaining you get some people citing books, demanding explanations, and generally wasting your time.
(DIR) Post #B1m71Z89PGSoGnwJrU by wolfpld@mastodon.gamedev.place
2025-12-30T11:37:32Z
0 likes, 0 repeats
@amonakov @wolf480pl My favourite shit argument is that iostream is C++, and printf is C, therefore it's deprecated and obsolete.This really shows you who have actually read the standard, where printf is used numerous times in various examples thorough the whole text, and (in C++20) 16.5.1.2 clearly states that "The facilities of the C standard library are provided in the additional headers shown in Table 22."
(DIR) Post #B1m71aQca4pgINaaI4 by artificialmind@fosstodon.org
2025-12-30T11:47:53Z
0 likes, 0 repeats
@wolfpld @amonakov @wolf480pl Imho a valid criticism of printf is lack of extensibility. Having to drop 10 lines just to debug print a vector<int> is grating. I've had the equivalent of std::print (the c++23 one) in my foundational lib for years and got great mileage out of that.
(DIR) Post #B1m71bLh9sUD9OIAFc by wolf480pl@mstdn.io
2025-12-30T13:09:53Z
0 likes, 0 repeats
@artificialmind@wolfpld @amonakov IMO iostreams are useless for anything serious due to how they do error handling.That leaves debug prints, which do benefit from using a method you can overload in each type... but outside of ad-hoc ones added mid-debugging and removed before commit, you'll want a wrapper anyway, one which you can control with logleves or statically turn into no-op... so I don't see a case for using iostreams directly.
(DIR) Post #B1m8kSlI22Q1VGDeQS by artificialmind@fosstodon.org
2025-12-30T13:29:16Z
0 likes, 0 repeats
@wolf480pl @wolfpld @amonakov I mean basically the same applies to printf and all other basic primitives. Actually, feel free to wrap almost any API to realize your particular needs!
(DIR) Post #B1mBRui4CIdwXiYfmi by wolf480pl@mstdn.io
2025-12-30T13:59:34Z
0 likes, 0 repeats
@artificialmindNot really - with printf you can use it for output data, if buffered writes in a text-based format is what you need. And it uses standard C-style error handling, so it's not worse than any other idiomatic C function.Or eg. in Java, you have OutputStream which throws exceptions like everything else in Java, and using it directly is as ergonomic as most things in Java.But with C++'s iostream, that's not the case.@wolfpld @amonakov
(DIR) Post #B1mGWy0tqCsI0Yb1V2 by artificialmind@fosstodon.org
2025-12-30T14:56:29Z
0 likes, 0 repeats
@wolf480pl @wolfpld @amonakov I mean I really don't want to "defend" iostreams. It's certainly old and with lots of worms. My production code uses wrapped versions, if at all.But I'm not sure I buy your "defense" of printf. Do you really want to argue that people properly handle all printf errors and test every cleanup path? Or is it the same fire-and-forget? Do you check fflush+fclose?Also, locale handling in printf is pretty unusable, especially threaded and with dependencies.
(DIR) Post #B1mGc8nXAjuqu3oNjU by wolf480pl@mstdn.io
2025-12-30T14:57:26Z
0 likes, 0 repeats
@artificialmind @wolfpld @amonakov shit, I forgot printf uses locale...yeah, you're right, write(2) all the way
(DIR) Post #B1mGf4W7Xq80Ul42rI by artificialmind@fosstodon.org
2025-12-30T14:57:56Z
0 likes, 0 repeats
@wolf480pl @wolfpld @amonakov I'm with you on that!