4 ms·
Having characters at all is probably a mistake.
by neolog 6y ago
Having characters at all is probably a mistake.
- alpaca128 6y agoHow so? Character doesn't necessarily mean ASCII char nowadays, if that's what you mean. And other than that I don't know how it's a mistake to have a concept for the individual parts that make up a String.
- JadeNB 6y ago> How so? Character doesn't necessarily mean ASCII char nowadays, if that's what you mean. And other than that I don't know how it's a mistake to have a concept for the individual parts that make up a String. But why? It seems like having a `Digit` type, and having a `NatNum` type that's `List<Digit>`. (OK, to nerdsnipe myself, that runs into trouble with leading 0's, but hopefully the point is clear. `0 | NonZeroDigit:List<Digit>` is maybe more accurate but less punchy.)
- alpaca128 6y ago> But why? It seems like having a `Digit` type, and having a `NatNum` type that's `List<Digit>`. BigInt types are in fact more or less List<Digit>, normal integer types just aren't implemented like that for performance reasons. A char is the primitive type that makes up a string if chained together. It's more or less a practical naming convention, just like we can call a tuple of floats a vector. Maybe you could get by without chars, but then String would be the only type in your language that doesn't consist of any scalar element but always has an arbitrary length in every situation.
- reikonomusha 6y agoArguably strings these days don’t really have scalar elements, not at least in the way we think. One “character” might be several distinct code points, and character access might not be a linear time operation.
- alpaca128 6y agoIt still makes sense to expose those codepoint sequences as individual symbols for the sake of the programmer's sanity. In most cases we don't really need to care if it's a single latin letter or a combination of bytes that make up a weird emoji, we just want a simple way to iterate over what a human reader would call a single character.
- chrisseaton 6y ago> we just want a simple way to iterate over what a human reader would call a single character But that's almost never what a language is giving you with their 'characters'.
- Dylan16807 6y ago> BigInt types are in fact more or less List<Digit>, normal integer types just aren't implemented like that for performance reasons. Right. Because you only use BigInts, you don't use isolated BigInt digits. > but then String would be the only type in your language that doesn't consist of any scalar element but always has an arbitrary length in every situation. Sure, why not? Every type has something special about it. Integers have overflow, floats have precision, infinities, and NaN, and booleans don't map cleanly to bytes. There's enough different ways to iterate over a string; you don't need a canonical way to decompose them, which is basically what a char type is. I wouldn't go as far as "mistake", but it's definitely fine to go without it. > A char is the primitive type that makes up a string if chained together. It's more or less a practical naming convention, just like we can call a tuple of floats a vector. For chars more complex than a byte, there are multiple practical conventions and it's hard to pick one. For char=byte there's a very natural convention, and an array of bytes reflects what's actually in memory, but char=byte is something that should be avoided. So it's either "none of these stand out" or "don't do this". So you might as well keep the language slightly simpler and not have a char type.
- Akronymus 6y agoWhat about multiple leading 0's? Like how in some phone systems you need to do double 0's to call to somewhere not within the company. Also: What about negatives?
- JadeNB 6y agoI'm not sure what the question is. As you say, I can imagine the need for, say, a `PhoneNumber` type that can remember leading 0's, and certainly there's use for an `Integer` type that can store negatives, but neither of those probably belongs in a `NatNum` type.
- Akronymus 6y agoOh right, completely forgot about using more advanced data types. Sometimes I surprise myself with how stupid my statements can be.
- neolog 6y agoWhat is the use case for breaking up a string into parts? What are the individual parts that make up a string in that use case: bytes, code points, code units, extended grapheme clusters? What should happen when a different partitioning is needed, for a different use case?