Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why don't popular programming languages use some other character to delimit strings? [closed]

Every programming language I know (Perl, Javascript, PHP, Python, ASP, ActionScript, Commodore Basic) uses single and double quotes to delimit strings.

This creates the ongoing situation of having to go to great lengths to treat quotes correctly, since the quote is extremely common in the contents of strings.

Why do programming languages not use some other character to delimit strings, one that is not used in normal conversation \, | or { } for example) so we can just get on with our lives?

Is this true, or am I overlooking something? Is there an easy way to stop using quotes for strings in a modern programming language?

print <<<END
I know about here document syntax, but for minor string manipulation it's overly complicated and it complicates formatting.
END;

[UPDATE] Many of you made a good point about the importance of using only ASCII characters. I have updated the examples to reflect that (the backslash, the pipe and braces).

like image 686
Andrew Swift Avatar asked Jun 08 '09 15:06

Andrew Swift


1 Answers

Perl lets you use whatever characters you like

 "foo $bar" eq
 qq(foo $bar) eq
 qq[foo $bar] eq
 qq!foo $bar! eq
 qq#foo $bar# etc

Meanwhile
 'foo $bar' eq
 q(foo $bar) eq
 q[foo $bar] eq
 q!foo $bar! eq
 q#foo $bar# etc

The syntax extends to other features, including regular expressions, which is handy if you are dealing with URIs.

 "http://www.example.com/foo/bar/baz/" =~ /\/foo/[^\/]+\/baz\//;
 "http://www.example.com/foo/bar/baz/" =~ m!/foo/[^/]+/baz/!;
like image 113
Quentin Avatar answered Oct 14 '22 17:10

Quentin