|
|
|
|
|
by hxtk
1425 days ago
|
|
The book "Building Secure and Reliable Systems" from Google's series on SRE actually talks about two examples of this in C++ and Go which forbid using anything but string literals in the query string of an SQL API. In Go, the solution was very tidy: it aliases string to an unexported internal type that consumers cannot instantiate. String literals can be coerced to that type, but variables that already have type information associated with them are rejected at compile time. The C++ solution was a bit more complicated and involved templates. |
|
However you would also probably want a language with some syntactic sugar that let users use your special string type easily otherwise the burden on users will be too high