Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make use of single quotes? #193

Closed
jclark opened this issue Jun 6, 2019 · 8 comments
Closed

How to make use of single quotes? #193

jclark opened this issue Jun 6, 2019 · 8 comments
Assignees
Labels
Area/Lang Relates to the Ballerina language specification design/dislike Do not like something about the design

Comments

@jclark
Copy link
Collaborator

jclark commented Jun 6, 2019

Single quotes were used by symbolic string literals but are not any more.

Should we use them for something for which we are now using a less pleasant syntax? e.g.

  • ^"xxx" delimited identifiers
  • string`${x} and ${y}` interpolated strings
@jclark jclark added the status/discuss Needs discussion outside github comments label Jun 6, 2019
@jclark jclark added this to the 2019R2 milestone Jun 6, 2019
@jclark jclark self-assigned this Jun 6, 2019
@jclark jclark mentioned this issue Jun 15, 2019
@jclark
Copy link
Collaborator Author

jclark commented Jun 15, 2019

Some languages (e.g. XML) allow both " and ' with the same semantics so you can easily include strings that use one of these two characters without bothering about quoting.

@jclark jclark pinned this issue Jun 20, 2019
@jclark
Copy link
Collaborator Author

jclark commented Jun 20, 2019

Our delimited identifier syntax is ugly, so it's an obvious choice to make use of single quotes. The question is whether delimited identifiers are sufficiently widely used to justify dedicating single quote to them. They are not much used in other languages, but maybe we can use them more:

  • if you are using a GUI to create programs, it is much less natural to restrict identifiers as textual programming languages typically do
  • XML allows characters in names that Ballerina doesn't (most notably hyphen)
  • JSON data formats may also use field names (i.e. property names) that are not Ballerina identifiers
  • for resource functions, URL segments might want to allow things that are not Ballerina identifiers

Is that enough? I'm not sure.

@jclark
Copy link
Collaborator Author

jclark commented Jun 23, 2019

In Excel, single quote is used at the beginning of a cell to indicate that something that looks like a number should be treated as text.

@jclark
Copy link
Collaborator Author

jclark commented Jun 23, 2019

So I think the realistic options are:

  1. Use single quotes for delimited identifiers
  2. Use single quotes for string. Two variations depending on how content of single-quoted string is treated:
    1. Same as double-quoted string (XML, Python, JavaScript)
    2. Different from double-quoted string (perl, sh; escapes are not recognized in single-quotes)

@jclark
Copy link
Collaborator Author

jclark commented Jun 23, 2019

I think 2(i) is the most Mort-friendly, and the most consistent with our "be familiar" design principle. There's a strong C-family expectation that 'X' means character X, and the way we represent characters in Ballerina is by strings of length one; JavaScript is very similar in this respect, and allows single quotes for strings, interpreting them exactly the same as double quotes.

At the same time, I do not like our delimited identifier syntax, and think we should make another effort to find something better.

@jclark
Copy link
Collaborator Author

jclark commented Jun 23, 2019

Another data point: SQL 92 uses double quotes for delimited identifiers.

@jclark
Copy link
Collaborator Author

jclark commented Jun 25, 2019

Could use 'x to mean "x".

@jclark jclark unpinned this issue Jun 25, 2019
@jclark jclark removed the status/discuss Needs discussion outside github comments label Jun 25, 2019
@jclark
Copy link
Collaborator Author

jclark commented Jun 25, 2019

Using single quotes for delimited identifiers would cause problems for the unwary:

string s = "!whoops!";
// lots of code here
string x = "person";
x = x + 's';

@jclark jclark added Area/Lang Relates to the Ballerina language specification design/dislike Do not like something about the design labels Jun 25, 2019
@jclark jclark modified the milestones: 2019R2, 2019Rn Jun 25, 2019
@jclark jclark closed this as completed in aa9f05f Jun 28, 2019
@jclark jclark removed this from the 2020R2 milestone Mar 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area/Lang Relates to the Ballerina language specification design/dislike Do not like something about the design
Projects
None yet
Development

No branches or pull requests

1 participant