Skip to main content
50 votes
Accepted

Why do programming languages use delimiters (quotes) for strings?

The feature you're asking about is called "barewords" or "bare words", which means that identifiers in some contexts are taken to be string literals, and possibly also that ...
kaya3's user avatar
  • 19.7k
22 votes

How have modern language designs dealt with Unicode strings?

Swift Swift strings are complicated. At the time of writing, the implementation of Swift.String is split across more than 30 files in the standard library, and that'...
Bbrk24's user avatar
  • 9,067
20 votes

What are the advantages of strings and character arrays being different?

Different definitions of “character” In Swift, the Character type isn’t a single Unicode codepoint (that’s UnicodeScalar), nor ...
Bbrk24's user avatar
  • 9,067
20 votes
Accepted

In Python, why isn't it a syntax error when a list of strings is defined without comma separators?

The reason the first example does not error is because Python will automatically concatenate adjacent string literals. This happens inside and outside of lists. As mentioned in the Python ...
lyxal's user avatar
  • 1,785
16 votes

Should my language distinguish between single- and double-quoted literals?

Character Literals Rust, and several other languages, use single-quoted "strings" for literal character types.
Ginger's user avatar
  • 2,629
15 votes

What are the downsides of making all strings immutable to improve security and concurrency?

Performance Immutability in general is bad for performance. If you concatenate many strings together in a loop, for example, the needless copying and the GC overhead (if any) will hurt performance. ...
Seggan's user avatar
  • 2,723
15 votes
Accepted

What are the different syntax options for formatted string literals?

Warning: without any ill-intent, this answer post responds to the question by asking more questions (hopefully useful ones, and hopefully while imparting some useful information or insight). To start ...
starball's user avatar
  • 1,652
15 votes

Why do programming languages use delimiters (quotes) for strings?

The feature you're asking about is known as barewords, and they're common in markup languages such as HTML and (La)TeX, where the "strings" indicate text to be displayed, and data languages ...
Bbrk24's user avatar
  • 9,067
13 votes

Why do programming languages use delimiters (quotes) for strings?

Bare words make the language irregular and harder to maintain It will be almost impossible to generate an abstract syntax tree from the source code alone, as it may be necessary the run state to ...
André L F S Bacci's user avatar
12 votes

Should my language distinguish between single- and double-quoted literals?

Avoid escaping nested quotes This is what I do when programming in JavaScript: ...
Bbrk24's user avatar
  • 9,067
12 votes

What are the advantages/disadvantages of null-terminated strings vs length-prefixed strings?

Length-prefixed strings have the advantage of being able to find their length in O(1) time rather than O(n) time. This means you can find the end of the string more easily with the length prefix. They ...
Isaiah's user avatar
  • 789
12 votes

How have modern language designs dealt with Unicode strings?

Rust The default string types (&)str and String are both UTF-8, ignoring native encoding. There are various other types and ...
blueberry's user avatar
  • 2,465
11 votes

What are the advantages/disadvantages of null-terminated strings vs length-prefixed strings?

An option missing from the question is fat pointers ─ the type &str in Rust is an example of this. The length is not stored on the heap as a prefix to the ...
kaya3's user avatar
  • 19.7k
11 votes

What are the advantages/disadvantages of null-terminated strings vs length-prefixed strings?

Null-terminated strings can't include the null byte, whereas length-prefixed ones can include all 256 possible binary values.
pppery's user avatar
  • 920
10 votes

What are the downsides of making all strings immutable to improve security and concurrency?

Security is better for mutable strings in some situations When memory is freed it is not cleared. The string may stay in memory for a long time after you are done using it potentially exposing ...
mousetail's user avatar
  • 8,359
10 votes

What are the advantages of strings and character arrays being different?

Encapsulation Treating strings as character arrays entails a belief that a character array is an adequate model for a string - not just good enough now, but good enough that you won't want to be able ...
Karl Knechtel's user avatar
10 votes

What are the advantages of strings and character arrays being different?

An array must have a fixed stride, so that the memory address of the ith element equals the address of the start of the array plus i times the stride. If you really want an array of characters, so ...
kaya3's user avatar
  • 19.7k
10 votes

What design trade-offs led to the "Norway problem" in YAML, and when are they worthwhile?

It is a somewhat reasonable idea to provide convenient facilities for presumed common cases, but when done carelessly, it tends to backfire in unexpected situations. Javascript is notoriously plagued ...
abel1502's user avatar
  • 2,527
9 votes

What ways exist for handling object to string conversion?

Rust's approach: Display and Debug traits Rust uses the trait system, through the Display ...
Luiz Felipe's user avatar
9 votes

Should my language distinguish between single- and double-quoted literals?

It's a waste of a character to have both the same Having two semantically identical quotation mechanisms sitting on two keyboard characters may not be worth the cost. If there isn't a substantially ...
Michael Homer's user avatar
  • 13k
9 votes

What are some different approaches to raw string syntax, and what are their pros and cons?

No end in sight As used by Zig. Many (all?) of the raw-string formats adopted by mainstream languages still keep to the form start/end delimiter. This evidently immediately creates the issue that the ...
Matthieu M.'s user avatar
  • 3,038
9 votes
Accepted

Prior art on modeling characters of variable lengths

Swift Swift’s Character type represents an extended grapheme cluster. As you mention in your question, this means a single ...
Alexis King's user avatar
  • 8,731
8 votes

Should my language distinguish between single- and double-quoted literals?

Embedded variables/escapes Some languages, especially shell languages, use single quoted literals as raw literals, where things like backslash escapes are disabled. This can be handy when doing things ...
Rydwolf Programs's user avatar
8 votes

What are the advantages/disadvantages of null-terminated strings vs length-prefixed strings?

Length-prefixed can include capacity This lets you "over-allocate" storage and remember how much you did so: ...
Bbrk24's user avatar
  • 9,067
8 votes
Accepted

What are the advantages of strings and character arrays being different?

Separate string methods or going via arrays A disadvantage of a string type is that the methods available to manipulate arrays cannot just be used for strings. Instead, the language must either ...
Adám's user avatar
  • 3,156
8 votes

What are the advantages of strings and character arrays being different?

Resizing with Bounds Checking and Constant-Time Size Lookup The most common alternatives do not have all three. A fixed-length array is not resizable. And C-style arbitrary-length, null-terminated ...
Davislor's user avatar
  • 1,062
8 votes
Accepted

Why do many dynamically typed languages identify types with strings?

For the scripting languages that do this, strings are one of the few built-in types and have a major advantage in being printable and introspectable. This is particularly valuable for languages meant ...
Michael Homer's user avatar
  • 13k
8 votes

How have modern language designs dealt with Unicode strings?

Python 3 Conceptually, strings are immutable sequences of code points. Indexing strings results in a string containing a single code point. Characters not exposed as a separate type. Equality is based ...
Jasmijn's user avatar
  • 990
8 votes

Creating an interface for stringifying objects that allows loop detection

I don't think this requires changing your ToString interface itself, rather you can change the protocol by which the language invokes the ...
kaya3's user avatar
  • 19.7k
7 votes

What are the advantages of strings and character arrays being different?

Handling Encoding Arrays of raw data don't, generally speaking, have an encoding. Strings can be in UTF-8 or any number of other formats. In Ruby, a String object ...
Silvio Mayolo's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible