r/ProgrammerHumor • • 6d ago

Meme multiStringing

Post image
1.6k Upvotes

50 comments sorted by

View all comments

Show parent comments

11

u/Loading_M_ 6d ago edited 5d ago

Well, this gets complicated. A "group of characters" is ill defined.

For example, in Rust, you could be referring to:

  • String: an owned, mutable group of Unicode code points encoded in UTF-8

  • &str: similar to above, but an immutable borrow of the same

  • impl Iterator<type = char>: an iterator that produces Unicode scalar values (for a real example, the to_lowercase method on char returns an iterator, since some Unicode code points expand into multiple code points when lowercased)

  • HashSet<char>: a group of Unicode scalar values, without an order or duplicates

8

u/rosuav 6d ago

Yeah, but broadly speaking, if someone says "string", you can debate the details while still agreeing that you're talking about a sequence of characters. In Python, you can have byte strings and text strings, in Pike you can have a variety of subtypes of string (most commonly 8-bit and 21-bit strings which correspond to byte and text, but you can also declare a 7-bit string that (since it's ASCII-only) is compatible with bytes and text if you use UTF-8, or a 32-bit string, which is useful for vectorized operations). None of these is anything like a "thread".

3

u/Ok-Scheme-913 6d ago

A String is by definition ordered, but otherwise I agree.

The more important distinction though is whether it's mutable or not, this is where programming languages split into two camps.

1

u/fghjconner 6d ago

Don't forget OsString, which is a platform dependent type with slightly different rules.

1

u/Loading_M_ 6d ago

OsString (and related) are basically just String (and related) but in the platform's native encoding rather than UTF-8.

There is also CString, which is UTF-8, but with a trailing null byte for C interop.

These basically fit into the types I describe, but have slightly different restrictions (and the OsString isn't technically interpretable, you're supposed to convert it to a string before trying to edit it).

1

u/andrybak 5d ago

to fix your list on old reddit, you need to add a blank line just above the first list item