Almost every programming language requires strings (or char*
or equivelent) to be marked with quotes. Few languages allow other delimiters, many languages allow single and double quotes.
Why is it that we even need delimiters to mark strings? What's wrong with code like this?
name = I do not want to give my name
As I see it, there is one primary problem - using one variable name = safwan
might cause confusion as to whether safwan
is a variable or a word. However, a language could enforce quotes in this case alone. For a similar situation, {hey: 9}
is valid JS, but if you wanted a key like hey-foo
, you'd have to say {"hey-foo": 9}
. No quotes except when it's necessary in key definitions - why couldn't that be extended to all strings in general? Another possible area of problem might be concatenation, but concatenating two string literals is highly unusual, after all, so hello
and world
in hello + world
might be assumed to be variables instead of strings.
It admittedly will cause problems, but I'm wondering why it's so rare (if it's ever occurred). It would not be the first widespread programming concept that's been questioned. Multiple languages have rebelled against the parenthesis around function calls phenomenon. If Python's print("Hello World")
is pretty to a C programmer, Ruby has print "Hello World"
- even better.
Why not print(Hello World)
?