Questions tagged [strings]

For questions about the implementation or design of strings within a programming language.

Filter by
Sorted by
Tagged with
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: ...
mousetail's user avatar
  • 6,736
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 ...
Safwan Samsudeen's user avatar
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 ...
user23013's user avatar
  • 2,010
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: ...
Redz's user avatar
  • 900
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 ...
Dannyu NDos's user avatar
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, ...
Bbrk24's user avatar
  • 8,563
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....
Rydwolf Programs's user avatar
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 ...
Michael Homer's user avatar
  • 10.9k
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 ...
user16217248's user avatar
  • 7,285
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 ...
Michael Homer's user avatar
  • 10.9k
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: ...
The Thonnu's user avatar
  • 1,474
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 (...
Bbrk24's user avatar
  • 8,563
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 ...
Ginger's user avatar
  • 2,451
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 ...
user16217248's user avatar
  • 7,285
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 ...
justANewbie's user avatar
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,...
user16217248's user avatar
  • 7,285
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 ...
James Risner's user avatar