You jest, but I received this exact answer in an interview. It was a early-career programming position and we were starting with simple stuff to level set the interview.
Me: What is a thread and how would you use it? Them, with complete confidence: A thread is a lightweight string. Me: Elaborate. Them: If you have a string that's really short and you don't want to do very much with it, you can just use a thread. Me: What if I want to do a lot with it? Them: Use a rope. Me: Interesting. What sorts of tools would you use for managing concurrency? Them: You need to make sure the desk is big enough for two computers for that. And you need enough power to run both.
He did not ultimately get the job, but I'm assuming he's making bank as a mod of /r/confidentlyincorrect. His answers were always instantaneous, with no hesitation at all.
I'd've been more impressed with the correct rope answer if it weren't completely clear that he was right completely by accident. :D
I've never thought about it, but does every major programming language call a group of characters a string? I know there's some debate around string view/builder/slice/etc terminology but the core concept always seems to be a string in the ones I know.
Java has String of course, but it's but one implementation of the CharSequence interface. So a "group of characters" is not necessarily called a "string" depending on the context.
A string usually implies contiguous memory. Like in C, there’s no string type—just a char type, which you can put into an array.
Unfortunately, contiguous memory strings aren’t considered very secure. If something is able to read your memory, it can read your string pretty easily.
So some SecureString implementations use non-contiguous memory to store text. That is, each character is sprinkled around different places in memory, which makes them hard for a memory reader to discover and interpret.
Both of them are character sequences but only one of them is a string (in the typical sense).
contiguous memory strings aren't considered very secure
This sentence makes no sense. There is no such thing as an absolute value for security, security is always in relation to an attack vector.
For storing a password? You are right, for this use case a String in most languages is not a good fit, you don't want immutability, nor it being continuous in memory, and you want to zero it out right after use.
For most everything else, you want good performance and reading out your "--help" message from memory is not a vulnerability.
Except for the part where you implied that I claimed that all strings need to be treated securely. Most of them don’t, and that’s exactly why contiguous memory strings are popular.
Like you said, they’re fast, everybody understands them, nobody is surprised. They’re the best solution most of the time.
My point is that contiguous memory strings aren’t the only way to handle character sequences, and there are real cases when you’d pick one over the other. Not saying that one is universally better (which isn’t how engineering works).
Yeah I was sure you know it, it was just a bit unfortunate way to put it and I do see bad security takes all over the place so I just wanted to add my two cents so someone else doesn't misinterpret it
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
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".
A rope is what you use to hang yourself after O(n2) concatenation you shipped in a AAA game and wasted enough energy to make 100 bitcoin because of it.
Just kidding I bet R* don't care about wasting their players time.
View all comments
280
u/alficles Oct 27 '26
You jest, but I received this exact answer in an interview. It was a early-career programming position and we were starting with simple stuff to level set the interview.
Me: What is a thread and how would you use it?
Them, with complete confidence: A thread is a lightweight string.
Me: Elaborate.
Them: If you have a string that's really short and you don't want to do very much with it, you can just use a thread.
Me: What if I want to do a lot with it?
Them: Use a rope.
Me: Interesting. What sorts of tools would you use for managing concurrency?
Them: You need to make sure the desk is big enough for two computers for that. And you need enough power to run both.
He did not ultimately get the job, but I'm assuming he's making bank as a mod of /r/confidentlyincorrect. His answers were always instantaneous, with no hesitation at all.
I'd've been more impressed with the correct rope answer if it weren't completely clear that he was right completely by accident. :D