7 ms·
I'm pretty sure boost::format can do this, though not inline in the string. Do we really need more complexity in cpp? isn't it complex enough?
by puffybuf 2y ago
I'm pretty sure boost::format can do this, though not inline in the string. Do we really need more complexity in cpp? isn't it complex enough?
- mkoubaa 2y agoThis is the sort of change that adds complexity to the language but reduces complexity in the code written in the language. We take those
- puffybuf 2y agohow would this work with internationalized strings? especially if you have to change the order of things? You'd still need a string version with object ordering I would think
- mkoubaa 2y agoI'm skeptical that people would want to do this in a single expression.
- rerdavies 2y agoDo what? Allow translators to reorder the appearance of arguments in a translated format string? It's a completely routine (and completely necessary) feature when doing translations.
- edflsafoiewq 2y agof-strings are not an internationalization library.
- wakawaka28 2y agoThe question was, how would you use this if you have i18n requirements. Format strings are normally part of a translation. I think the bad answer is to embed the entire f-string for a translation as usual, except this can't work because C++ f-strings would need to be compiled. The better answer is, don't use f-strings for this because you don't want translators to monkey around with code and you don't want to compile 50 versions of your code.
- mkoubaa 2y agoC++ is such a narrow skillset that I'd rather not roll the dice on translators knowing what to do
- wakawaka28 2y agoEven if you told them, "just copy the names from the original string" it's still asking for trouble, and maybe even security holes if they don't follow instructions. But the biggest problem with the idea is surely that the strings need to be compiled.
- hackyhacky 2y ago> This is the sort of change that adds complexity to the language but reduces complexity in the code written in the language. We take those An admirable statement of policy, but I'm not sure it's possible. Adding complexity to the language means there are more gotchas and edge-cases that a programmer must consider, even if they don't use the feature in question.
- verall 2y ago> Adding complexity to the language means there are more gotchas and edge-cases that a programmer must consider, even if they don't use the feature in question. Since this is C++, this is not a problem we have to consider
- pjmlp 2y agoThis is a meme by now, yet it isn't as if Python 3.13 is a simple as Python 1.0, Java 23 versus Java 1.0, .NET 9 with C# 13 versus .NET 1.0 with C# 1.0 and a Framework reboot,....
- cylemons 2y agoC# has a lot of features but most of them feel like simple syntactic sugar that make the language a joy to use and they interact nicely together. C++ has lots of features that interact with each other in unexpected ways that could leak memory or access freed memory etc.
- pjmlp 2y agoC# has already enough material for pub Quiz, and no, not all of them are syntatic sugar, and require deep knowledge of the .NET runtime, and the way it interacts with the host platforms. I imagine you never went too deep into unsafe, cross language interop, lambda evolution since the delegate days, events infrastructure, pluggable GC, RCW/CCW, JIT monitoring, the new COM replacement, how the runtime and language features differ across .NET Framework, Core, .NET MicroFramework, UWP, AOT compilation, Mono, .NET standard versus Portable Class Libraries, CLS friendly libraries,... On top of that, all the standard frameworks that are part of a full .NET install on Visual Studio, expected that most C# developers know to at least have some passing knowledge on how to use them.
- HeliumHydride 2y agoC++ also has std::format, which was introduced in C++20. This is just sugar on top of it, except it also returns a container type so that printing functions can have overloads that format into a file or stream directly from an f-string, instead of going through the overhead of a temporary string.
- rerdavies 2y agoI'm wonder what this mysterious application is that is doing heavy formatting of strings but can't afford the overhead of a temporary string, and therefore requires horrifying and inscrutable and dangerous language extensions.
- gpderetta 2y agoFor example, an high performance logger can ship the tuple object to a background thread for actual formatting and I/O, after converting the capture to by-value. Formatting on the foreground thread would be a non-starter.
- chlorion 2y agoBeing able to use string formatting without a heap is pretty cool. Rusts string formatting machinery does not require any heap allocations at all, you can for example impl fmt::Write for a struct that writes directly to a serial console byte-by-byte with no allocations, and then you have access to all of rusts string formatting features available to print over a serial console! I'm not sure about the horrifying and dangerous extensions part though, I'm not really a C++ expert so I don't know if there's a better way to do what they want to do.
- badmintonbaseba 2y agofreestanding maybe? Embedded apps often don't shy away from using something like printf, yet they don't like unnecessary allocations.
- richrichardsson 2y agoSo it's less complex bringing in a 3rd party library and having to pass arguments? fmt library can also do something similar, but still requires the complexity of adding the library and passing arguments.
- nikhilsimha 2y agojust skimmed the proposal, dont see how inline rendered f-strings are more complicated than the alternative.