News for hackers. Stuff that matters.
Re:C++ Filesystem Technical Specification approved by ISO by huhtenberg on Saturday January 03, 2015 @07:45AM (#8830630)
As someone who writes portable high-performance C++ code for living I see this as no more than a great prototyping aid.

Adding a non-trivial system abstraction to your code - be it a file system or a socket/networking API - is always a tricky task, even for the simplest of requirements. For example, Windows API is inherently UTF16, so if you want good performance, you need to keep all your filesys references in wstirngs. But not on Windows, you'll need strings instead. If you are to abstract this, you have a choice of either using an opaque "filesystem_string" type that maps to wstring/string (with an API for cross-conversion) or defining, say, an UTF8 API and then doing a boatload of run-time Unicode conversion on Windows. The fun part is that while this makes the filesystem code more compact, it has a negative effect on the rest of the application. The app will either need to deal with conversions to/from "filesystem_string" when serializing/displaying them or the abstraction layer will be busy converting utf8's to the native string format. Either way you pay with performance for "portability".

This doesn't apply to just this new C++ TS. It's the same issue with the existing standard POSIX API as well (fopen/fread/etc). It's great for hacking together something that builds on Linux, BSD and Windows, but you'd typically want to put in your own system interface before shipping production version.

Re:C++ Filesystem Technical Specification approved by ISO by roel_v on Saturday January 03, 2015 @08:29AM (#8830697)
" so if you want good performance, you need to keep all your filesys references in wstirngs."

Why? For path manipulation, you can still use whatever format internally that you want. Only just before the native API calls you'll need to convert. I'm open to many arguments on performance, but I have a hard time believing that this conversion would matter (or even be measurable) relative to the time the actual I/O will take.

Filesystem is a great addition to the C++ standard library. If you're seriously claiming that filesystem will not be suitable for production code, I can't help but put you in the (hypothetical) group of people who say 'the standard allocator is only a great prototyping aid, you'd typically want to put in your own allocator before shipping production version.'. Uh no, millions of application ship just fine with the standard allocator, just like thousands (or maybe even hundreds of thousands) of applications are already shipping just fine with boost filesystem.

Re:C++ Filesystem Technical Specification approved by ISO by MaulingMonkey on Saturday January 03, 2015 @10:26AM (#8830923)
>> " so if you want good performance, you need to keep all your filesys references in wstirngs."

> Why?

I'd take this even further: The less (re)interpretation the better. Will my UTF16 <-> UTF8 conversion roundtrip my malformed UTF16 codepoints? If not, I've just lost compatibility with (admittedly buggy) software. But I've seen bugs from far tamer, such as from the simple act of converting from a fixed width wchar_t[] that was observed to be a NUL terminated UTF16 string to std::wstring. It turned out that under certain circumstances that couldn't be tested, it was an opaque binary blob with NULs in the middle... and the bit after the NULs being important. Whoops!

Less relevant here though: std::experimental::filesystem::v1::path::value_type looks to match the native OS character type. But then again, is that unichar (16-bit) or wchar_t (32-bit) on iOS? Fufufufu~

It's also just plain easier when you're dealing with native filesystem APIs for whatever reason to work in the native character type, which is the main reason I'd prefer it.

> but I have a hard time believing that this conversion would matter (or even be measurable) relative to the time the actual I/O will take.

RE: Performance: If you're doing actual I/O, agreed. If you're dealing with OS or application cached filesystem entries, it becomes more believable. If you're enumerating over and only conditionally performing I/O over hundreds of thousands of paths - you'll want to be quite cautious of conversions if you care about performance (potentially see: directory enumeration via backups, stale file scans during builds, or comparing file lists between VCS revisions...) It drives me absolutely insane when a 'nothing changed' build takes 10, 20 seconds just from filesystem scanning. And I've seen and fixed far worse (think O(n*n) scans -_-;;). As others have noted though, if you keep your conversions 'reasonable' you should be able to get away with UTF8 paths from a performance perspective.

> Filesystem is a great addition to the C++ standard library.

Agreed.

Re:C++ Filesystem Technical Specification approved by ISO by kuschku on Saturday January 03, 2015 @11:12AM (#8831055)
Also another problem:

UCS-2, commonly used as implementation for UTF-16, doesn’t support all the characters that UTF-8 does, which can lead to other nice problems during conversion.

Re:C++ Filesystem Technical Specification approved by ISO by kevin_thibedeau on Saturday January 03, 2015 @11:47AM (#8831167)
UTF-16 covers the full Unicode space just like UTF-8. You're thinking of UCS-2 (limited to plane 0) as implemented by Windows.
Re:C++ Filesystem Technical Specification approved by ISO by kuschku on Saturday January 03, 2015 @12:12PM (#8831245)
Which can create nice issues, especially because stuff like Java is limited to UCS-2...
Re:C++ Filesystem Technical Specification approved by ISO by vardump on Saturday January 03, 2015 @01:56PM (#8831604)
> Which can create nice issues, especially because stuff like Java is limited to UCS-2...

Not true. Java uses UTF-16, not UCS-2. There are no encoding representation issues.

Re:C++ Filesystem Technical Specification approved by ISO by heinrich5991 on Saturday January 03, 2015 @05:03PM (#8832180)
I believe strings in Java are not checked for UTF-16, but are just arrays of 16-bit integers and as such used as UCS-2 by most Java code.
Re:C++ Filesystem Technical Specification approved by ISO by jerven on Sunday January 04, 2015 @08:15AM (#8834313)
Most code written in the US/UK does not care about multiple codepoint used to represent one glyph. But that does not change the fact that the String representation inside Java are actually encoded in UFT-16 since Java1.5 (i.e. since 2004).

Actually dealing with multi codepoint characters is hard in any programming language and most people ignore it as often GUI stuff already takes care of it.

By the way any string encoded in UTF-16 is an array of 16bit unsigned integers. It just has variable length encoding which UCS-2 did not have. Just like UTF-8 is an array of bytes just like 8bit ASCII.

Re:C++ Filesystem Technical Specification approved by ISO by MaulingMonkey on Saturday January 03, 2015 @11:42AM (#8831150)
I suspect you're thinking of UCS-2 (UTF-16's precursor), not UTF-16 proper. Both UTF-8 and UTF-16 are variable length encodings capable of storing the entire unicode character set.
Re:C++ Filesystem Technical Specification approved by ISO by vardump on Saturday January 03, 2015 @11:34AM (#8831118)
That's not true. Both UTF-16 and UTF-8 can encode any valid unicode code point.
Re:C++ Filesystem Technical Specification approved by ISO by Hydraulix989 on Saturday January 03, 2015 @11:35AM (#8831125)
Something might expose bugs in my code? Better lambaste that something, rather than, you know, fix my own problems that have been there all along...
Re:C++ Filesystem Technical Specification approved by ISO by MaulingMonkey on Saturday January 03, 2015 @11:56AM (#8831189)
> Something might expose bugs in my code?

You're assuming the worst of me. Please try again, starting with this: Something might expose bugs in other people's code that I don't have source for, can't assume will be fixed if reported upstream, and can't assume will be patched downstream even if fixed?

Re:C++ Filesystem Technical Specification approved by ISO by gilgoomesh on Saturday January 03, 2015 @09:09AM (#8830744)
UTF8/UTF16 conversions are far cheaper than you think they are. Especially when compared to the cost of a GetFileAttributesExW or other filesystem operation.

I use boost::filesystem for a server that performs large numbers of bulk file system traversals. I keep all my pathnames in UTF-8 and make boost::filesystem perform all the conversions (you need to imbue the boost::filesystem locale with a UTF-8 conversion facet to force UTF-8 on Windows but that's straightforward). When reading from NTFS cached data, the overhead of UTF-8 to UTF-16 conversions is around 15% in the worst case of ~300 char Long Path operations and much less for smaller paths or uncached data.

If 15% overhead is going to kill your performance then yes, avoid the standard library and write your own classes; that's probably true for all standard library classes. For all other cases, you'd be foolish to write everything yourself.

Re:C++ Filesystem Technical Specification approved by ISO by sjolsen on Sunday January 04, 2015 @02:39AM (#8833765)
> It's the same issue with the existing standard POSIX API

It's only an "issue" if you look at this as being an attempt to create a be-all end-all API, and it isn't. Things like std::filesystem (and POSIX file APIs) are made not to replace the native APIs but to complement them. They exist to fill the need for cheap, simple auxiliary tools, not the need for high-performance tools.

In other words, std::filesystem doesn't exist to facilitate writing a high-performance whole-filesystem search engine. It exists to facilitate writing high-performance audio analysis tools, image manipulation libraries, funky customizable desktop widgets, or really any conceivable program which uses the filesystem, but never in a hot loop. It exists for the same reason std::string exists in spite of the fact that it would a terrible core data structure for a text editor. It exists for the same reason std::iostream exists even though you would have to be insane to try to write an HTTP engine with it. It exists because when you need to load up three 200-megabyte files to grab the input for an hour-long simulation, you don't care about an extra five milliseconds at startup as much as you care about dead-simple, reliable code. Or maybe you do, in which case you can still happily use the native API.

Re:C++ Filesystem Technical Specification approved by ISO by aristidb on Saturday January 03, 2015 @08:13AM (#8830665)
I think for most programs, path manipulation is fortunately not in the performance-critical parts.
Re:C++ Filesystem Technical Specification approved by ISO by tedunangst on Saturday January 03, 2015 @08:32AM (#8830698)
Re:C++ Filesystem Technical Specification approved by ISO by calvins on Saturday January 03, 2015 @09:24AM (#8830772)
That's not about path manipulation. It's about resizing the hash table that is required for keeping track of hard links when copying hundreds of millions of files using cp. The path manipulation that cp does would still be inconsequential in that example.
Re:C++ Filesystem Technical Specification approved by ISO by blt on Saturday January 03, 2015 @12:06PM (#8831222)
Maybe true for filesystem-heavy applications, but many C++ programs only need to do something simple like load a small directory of plugins. this lib will be perfect for stuff like that.