-1

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)?

Safwan Samsudeen
  • 1,645
  • 1
  • 10
  • 25
  • While this question is off-topic on Stack Overflow, you may be able to ask it on [Programming Language Design Stack Exchange](https://langdev.stackexchange.com/) – Brian61354270 Aug 27 '23 at 14:54
  • _"It admittedly will cause problems, but I'm wondering why it's so rare"_ ???? – Brian61354270 Aug 27 '23 at 14:55
  • @Brian61354270, there are so many examples of syntax/features that cause problems which are solved in other ways, as I've mentioned in the question very clearly. Moreover, there are other [fairly](https://stackoverflow.com/questions/3488229/why-do-programming-languages-use-commas-to-separate-function-parameters) [famous](https://stackoverflow.com/questions/4418708/whats-the-rationale-for-null-terminated-strings?rq=2) [questions](https://stackoverflow.com/questions/12694530/) very similar to this one - even if they were closed, why couldn't you wait for a few answers and general reaction? – Safwan Samsudeen Aug 28 '23 at 11:49
  • Also, why is the reason marked as not focused? – Safwan Samsudeen Aug 28 '23 at 11:50
  • 1
    Times change and questions on Stack Overflow should focus on a single *answerable* problem that does not elicit an opinion. Saying that, given the question you have already linked to surely the reasons are obvious - what about a function call with 2 string parameters which in your world would be `function_name(string value 1, string value 2)` - but what if you wanted to pass `("string with, a comma", "another string")`...? Clarity and no ambiguity require clear delimiters. – Stu Aug 28 '23 at 11:56

0 Answers0