News for hackers. Stuff that matters.
Re:Zig 0.9.0 by coldtea on Tuesday December 21, 2021 @03:16AM (#29635159)
It seems they don't want unicode strings as part of the language, at best as a library. But unless there's a single sactioned one, this will not end well.

And this is met with answers like "just avoid string handling" from the language designers...

It's probably because they don't work in any related domain, and even less so have to do with international strings (except as byte buckets they don't care about and don't have to do anything do).

Re:Zig 0.9.0 by jorangreef on Tuesday December 21, 2021 @03:26AM (#29635221)
No, I believe it's the right decision and I respect it. Encoding charsets are continuously evolving and shouldn't be baked into a language specification.
Re:Zig 0.9.0 by roca on Tuesday December 21, 2021 @03:30AM (#29635240)
Evolving how? I'm not aware of any reason to move beyond UTF8 for encoding Unicode.
Re:Zig 0.9.0 by jorangreef on Tuesday December 21, 2021 @03:31AM (#29635246)
Which version of UTF8?
Re:Zig 0.9.0 by coldtea on Tuesday December 21, 2021 @03:45AM (#29635360)
When adopting a new niche language, with hardly any following, and frequent changes, and not even an 1.0, like Zig, "which version of UTF8" (as if that's an issue) is the least of your worries...

"Which third-party strings lib of several half-complete incompatible libs" will be a much realer concern...

Re:Zig 0.9.0 by jstimpfle on Tuesday December 21, 2021 @04:30AM (#29635603)
For systems programmers the answer to "which third-party strings lib" is probably "None, write your own that fits with the rest of the system". A ready-made lib will be a lot of work to fit in - consider choice of internal encoding, allocation, hashing, buffering, mutable operations, etc....

Assuming that you really want to use UTF-8 internally, which is probably a sensible choice, the reusable part of a string library is basically the UTF-8 encoded/decoder. A useful implementation of UTF-8 is about 100-200 lines, I could probably rewrite what I use in an hour or two without an internet connection. The rest of the work is integration stuff that doesn't make sense to put in a library IMO. The idea of a string library fits much better with garbage collected and scripting languages (which includes C++ with RAII mechanism, but consider that std::string and similar often cause bad performance).

Many programs, in particular non-graphical programs don't need any UTF-8 code at all - UTF-8 handling is basically memcpy().

Re:Zig 0.9.0 by rightbyte on Tuesday December 21, 2021 @05:47AM (#29636062)
> Many programs, in particular non-graphical programs don't need any UTF-8 code at all - UTF-8 handling is basically memcpy().

argv to main is utf8 on my system.

Re:Zig 0.9.0 by jstimpfle on Tuesday December 21, 2021 @09:38AM (#29637723)
On Unix/Linux, it is binary data without any restrictions except that each argument is zero-terminated (the typical argument is probably UTF-8 if you have set a UTF-8 locale). You'll see exactly the bytes that were put in as arguments to execlp() et. al. by the parent process.

On Windows, I believe it is Unicode converted to current codepage.

In any case I don't need to care about it since I can simply treat arguments as ASCII-extended opaque strings as described.

Re:Zig 0.9.0 by anonymoushn on Wednesday December 22, 2021 @09:19AM (#29649611)
> argv to main is utf8 on my system.

That sounds totally compatible with programs that don't know anything about utf8. Do programs need to normalize the utf8 you pass in before using it as an argument to open(2) or something?

Re:Zig 0.9.0 by chaz6 on Tuesday December 21, 2021 @09:34AM (#29637684)
How feasible would it be to defer string processing to the operating system so that the behavior of all software running on it is the same? Perhaps a new OS interface could be defined for this purpose using syscalls on Linux. At the very least, there should be one canonical set of algorithms per operating system, rather than everyone downstream reinventing the wheel. Please forgive me if this sounds absurd, I am not a low-level programmer.
Re:Zig 0.9.0 by anonymoushn on Wednesday December 22, 2021 @09:28AM (#29649763)
I certainly don't want to pay for a syscall to do string encoding.

Also, a lot of the time the problem isn't that people are using fundamentally incompatible string libraries, but that there isn't one correct answer to the question they're asking and they chose different ways to convert the question into code. A reasonable question to ask is "How many extended grapheme clusters are in this string?" The answer is "It depends on what font you plan to use to render it." Not great!

Some programmers would still like to e.g. write a reverse() function that returns ":regional_indicator_f::regional_indicator_r:" unmodified (because it is the French flag emoji) and returns ":regional_indicator_i::regional_indicator_h:" when given ":regional_indicator_h::regional_indicator_i:". If such people want to avoid having nonsensical behavior in their programs, the only solution available is to decide what domain the program should work on and actually deal with the complexity of the domain chosen.

Re:Zig 0.9.0 by ShrigmaMale on Wednesday December 22, 2021 @10:16AM (#29650389)
Because string processing is not slow enough? Making string operations eat the performance impact of that context switch in and out of kernel is not a good idea. Library is better. This is not string but I'm thinking to some language like Rust where the "time" crate is not language feature but just about standard and all the other library use it. This is possible if a library like it is good quality and exist early in the language.
Re:Zig 0.9.0 by jorangreef on Tuesday December 21, 2021 @03:51AM (#29635400)
Zig's C interop is pretty good though, and there must be some decent native Unicode library out there somewhere right? ;)

I've worked on a full-duplex file synchronization system that had to support cross-platform operating systems and file systems, across a variety of Unicode normalization schemes (and versions [1], which is why I introduced the question), and I'm personally satisfied that baking this into the language specification would be a mistake.

[1] For example, depending on the file system, there's simply no way to get the normalization right unless you reverse engineer the actual table they're using, or probe the file system to do the normalization for you.

Re:Zig 0.9.0 by motiejus on Tuesday December 21, 2021 @07:19AM (#29636645)
Would Bellard's libunicode[1] work?

[1]: https://github.com/bellard/quickjs/blob/master/libunicode.h

Re:Zig 0.9.0 by roca on Tuesday December 21, 2021 @05:30PM (#29642901)
Regular UTF8, not WTF-8 or any of those other variants (which are for encoding data that is not necessarily Unicode).
Re:Zig 0.9.0 by jorangreef on Thursday December 23, 2021 @09:35PM (#29669371)
Also excluding Unicode normalization? Or should that also be baked in?
Re:Zig 0.9.0 by roca on Friday December 24, 2021 @02:30AM (#29671254)
No need to drag Unicode normalization into it; don't require strings to be normalized. Normalization is only relevant in very specific contexts and you don't want to pay for it elsewhere.
Re:Zig 0.9.0 by jorangreef on Saturday December 25, 2021 @06:37AM (#29682426)
Agreed, but I think that many people would consider Unicode normalization to be part of what they want from the std lib when they mean that UTF8 should be baked in... so that they can manipulate UTF8 as they want, including in various normal forms according to platform. It's hard to imagine people being satisfied without having access to Unicode normalization.

For example, consider JS' introduction of String.normalize(). This is a slippery slope. It had a huge impact on Node's build process and binary sizes because now all the tables had to be shipped. But it's still broken in JS, because no matter the Unicode normalization support provided, it will never match the exact tables used e.g. in Apple's HFS.

I feel that by the time it gets to String.normalize(), it's too far gone.

Re:Zig 0.9.0 by anonymoushn on Tuesday December 21, 2021 @03:25AM (#29635215)
It seems way nicer to have a language that treats strings as byte arrays and use libraries to handle encodings than to have a language that treats strings as UCS-2 and use libraries to handle UTF-8 strings that live inside of UCS-2 strings.
Re:Zig 0.9.0 by coldtea on Tuesday December 21, 2021 @03:43AM (#29635336)
I don't know, it has been a pain to work with strings in any language that does the above, and has seldom (if ever) been a problem with Java, Go, Swift, or even modern Python 3, and so on...
Re:Zig 0.9.0 by jstimpfle on Tuesday December 21, 2021 @04:36AM (#29635651)
I don't get what's so hard about it. Most of my programs deal with UTF-8 simply by doing memcpy(). Parsing code just loops over the bytes and compares to ASCII characters (0-9, A-Z, a-z, \n, \r, \t ...). That's how UTF-8 was designed to be used.
Re:Zig 0.9.0 by SuchAnonMuchWow on Tuesday December 21, 2021 @05:11AM (#29635840)
I assume you never had to deal with unicode normalization ?

When you send your unicode string to an external system (for example a storage server with a database) and latter retrieve the string, only to find out that it has been normalized differently so it no longer match byte-for-byte what is stored in your program, and all of a sudden strcmp no longer works.

Or all kind of weirdness like that because every system outside of your program will handle unicode differently, and you will need to adapt to them, and having a string library to do most of the heavy-lifting will avoid the need for every user to rewrite a library from scratch.

Not to mention that for every developer which rewrite unicode handling functions, you will probably end up with a function with subtly different behaviors from others, which aggravate the problem for others when they will try to communicate with your system.

Re:Zig 0.9.0 by jstimpfle on Tuesday December 21, 2021 @09:35AM (#29637700)
> I assume you never had to deal with unicode normalization ?

I hadn't, and as long as I control the data I'm displaying, I won't have to.

> Or all kind of weirdness like that because every system outside of your program will handle unicode differently

Blame those systems, not me.

What you suggest is surrendering to the state of affairs, which we collectively self-inflicted.

When I have to deal with normalization issues and have to interface with external systems, I can still go looking for a library if I don't feel like implementing it on my own (which is likely).

But unless I need to do normalization, I'm way worse off with a complicated library than with just doing memcpy() or using a simple decode_codepoint() routine.

Re:Zig 0.9.0 by SuchAnonMuchWow on Wednesday December 22, 2021 @10:08AM (#29650286)
> Blame those systems, not me.

Yes I completely agree with you, and if you don't need it, any unicode handling library is overkill and add more headaches than simply handling utf-8 string as byte arrays.

I just wanted to insist on the fact that some people will have to deals with theses kind of issues. And these issues are self inflicted, but it gets worse every time someone try to reinvent the wheel or rely on byte array when they shouldn't.

Having a standard library in the language make the issue less worse: the core of the language still handle only byte arrays, and for the cases where it's not enough you still have only one library so you don't add your own subtly different mishandling of the standard by implementing your own.

So memcpy is fine, but that's about it: for example, please don't use strcmp when you need to sort data alphabetically and please don't try to reimplement the standard algorithms designed for that, otherwise you will be part of the problem.

Re:Zig 0.9.0 by anonymoushn on Wednesday December 22, 2021 @11:34AM (#29651546)
Can you really fix anything by changing the native string type? You'll inevitably need to exchange bytes with different systems that demand different encodings and different normalization forms.
Re:Zig 0.9.0 by anonymoushn on Tuesday December 21, 2021 @03:59AM (#29635438)
I'm not sure how to explain the difference in experience here. Python 3's built-in string encoding support has been a source of endless pain to me, and Lua's belief that strings are byte arrays has been much easier to deal with.