Questions tagged [strings]
For questions about the implementation or design of strings within a programming language.
17
questions
9
votes
1
answer
365
views
Creating an interface for stringifying objects that allows loop detection
Suppose a language has a rust-style trait system but is garbage collected and most types are reference types by default.
I could create a trait like this:
...
27
votes
6
answers
11k
views
Why do programming languages use delimiters (quotes) for strings?
Almost every programming language requires strings (or char* or equivelent) to be marked with quotes. Few languages allow other delimiters, many languages allow ...
12
votes
4
answers
429
views
Prior art on modeling characters of variable lengths
In some encodings such as UTF-8, characters are of variable length in bytes. It's a bit like a tagged union, but the exact size could be computed, so the next element in a string could follow ...
9
votes
1
answer
1k
views
In Python, why isn't it a syntax error when a list of strings is defined without comma separators?
When coding in Python, I found that defining a list of strings without separating the strings with a comma is not a syntax error. When running this code:
...
2
votes
5
answers
722
views
To what degree is it practical to let objects be stored packed? [closed]
Let's say I want my compiler to store objects packed (data and collection members aligned to non-word boundaries).
Situation #1: I want to store an array of booleans.
A few languages already let the ...
4
votes
2
answers
213
views
Why would Short String Optimization not apply to dynamic arrays?
Short string optimization is the optimization that sufficiently short strings have their data stored inline rather than an external buffer, so the string type ends up being a union. Swift does this, ...
15
votes
9
answers
462
views
What are some different approaches to raw string syntax, and what are their pros and cons?
Many languages include a "raw string" literal type, intended for arbitrary (or as close as possible to arbitrary) strings of characters (and/or bytes), ignoring escape sequences and the like....
25
votes
6
answers
1k
views
How have modern language designs dealt with Unicode strings?
Languages developed over the last fifteen years or so have been within the era where Unicode is ubiquitous, and so could design their core string types accordingly. There are a lot of new issues that ...
7
votes
1
answer
253
views
Why do many dynamically typed languages identify types with strings?
I noticed in JavaScript and Lua, 'types' i.e., those returned by typeof()/type() are just identified by strings. As such we see ...
7
votes
1
answer
974
views
What design trade-offs led to the "Norway problem" in YAML, and when are they worthwhile?
A well-known problem in YAML is a type-inference issue in parsing where a string is misinterpreted as a boolean. This is known as the "Norway problem", because it occurs when a field or ...
8
votes
9
answers
350
views
What are the different syntax options for formatted string literals?
One option in Python is the f-string:
f"{a} {b} {c}"
Which is equivalent to:
...
11
votes
6
answers
278
views
What ways exist for handling object to string conversion?
For example:
Java uses a toString() method, and calls that behind the scenes. If you don't implement one, you inherit it from the base class (...
11
votes
4
answers
263
views
Should my language distinguish between single- and double-quoted literals?
In most modern languages, string literals can use either single (') or double (") quotes. Are there any reasons to ...
4
votes
1
answer
190
views
Implementing a number to string semantics efficiently in a C-style language?
In C our options for converting numbers to strings and adding them to a string are limited to:
Write your own function.
sprintf() to a buffer.
Either way, one ...
17
votes
11
answers
908
views
What are the advantages/disadvantages of null-terminated strings vs length-prefixed strings?
There are two main ways to implement strings in a language: null-terminated and length-prefixed strings.
From Wikipedia:
A null-terminated string is a character string stored as an array
containing ...
12
votes
10
answers
833
views
What are the advantages of strings and character arrays being different?
In many languages such as Java, strings and character arrays are distinct types. In Java one must use toCharArray() in order to use array semantics on strings.
In C,...
8
votes
3
answers
289
views
What are the downsides of making all strings immutable to improve security and concurrency?
Many programming languages (such as Java) make strings immutable to mitigate many potential serious security threats.
Are there any major downsides or issues with a language having all strings ...