Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It is always good to not have possible ambiguity in a language though.

A classic example is a C++ line such as:

    a ** b
Before you know if a and b are variable names or type names, you do not know whether this line is a variable declaration or a multiplication or a syntax error.

My point is that some keywords could be used as identifiers in some situations, but this might not always be the case.

One option would be to not have any keywords, just operators. Or maybe a special keyword decoration.



Programming languages already use contextual parsers. C# and Swift both allow you to re-use some keywords as identifiers, function names, etc and use context to disambiguate.

Both inherited the restricted list from C so for legacy reasons they prohibit those keywords from being used as identifiers, but newly introduced keywords are always contextual due to compatibility concerns.


> Or maybe a special keyword decoration.

What you're asking for is called stropping [0], and it's actually a very old concept going back to the early days of Algol.

Algol didn't have any concept of reserved words. Instead, keywords were typographically distinguished from identifiers. In publications, keywords were typically rendered in bold and/or underline, and identifiers were not. Representing this in a computer encoding proved problematic, so people came up with a number of ways to distinguish keywords from identifiers. The most common way was to enclose keywords in 'apostrophes', and from there 'strop' originated as an abbreviation for 'apostrophe', giving rise to the term 'stropping'.

But despite the etymology, stropping doesn't have to use apostrophes. When Algol 68 came out, the spec defined three acceptable styles, called 'stropping regimes'. 'Quote' stropping was the traditional form using 'apostrophes', .point stropping would prefix .keywords with a .decimal .point, UPPER stropping would render keywords in ALL CAPS (which forces identifiers to be all-lowercase, but that's ok because Algol 68 offers something much better than CamelCase). There was actually a fourth stropping regime, res stropping, which is different because it would treat keywords as reserved words and thus restrict how you can use identifiers.

a68g, the only modern-day Algol 68 interpreter I know of, can be configured to use either UPPER or res stropping. UPPER stropping is preferred, as res stropping changes the way the language works (for the worse, IMO).

The really cool thing about stropping is that it enables you to put spaces in your identifiers, since something other than whitespace is used to separate your identifier names from keywords [2] [3].

[0] https://en.wikipedia.org/wiki/Stropping_(syntax)

[1] Example from an HTML-ized copy of the spec: http://www.masswerk.at/algol60/report.htm

[2] Here's an example from Algol 68 of a function called days in month (yes, with spaces), taken from Wikipedia. I've rendered the keywords using UPPER stropping for the benefit of anyone wanting to try it in a68g:

    PROC days in month = (INT year, month)INT:
      CASE month IN
        31,
        IF year MOD 4 EQ 0 AND year MOD 100 NE 0  OR  year MOD 400 EQ 0 THEN 29 ELSE 28 FI,
        31, 30, 31, 30, 31, 31, 30, 31, 30, 31
      ESAC;
[3] Another Wikipedia example of a variable delcaration, showing how stropping enables both spaces in identifiers and identifiers that share words with keywords:

    INT a real int = 3;


It feels good that somebody thought about the trouble that spaces in identifiers can bring.

I am currently using the robot framework language which combines the worst of all worlds. It supports spaces in identifiers, but it does so by using “more than one white space” as a separator for everything. No parentheses, no commas, and of course identifiers are case insensitive.


>>The really cool thing about stropping is that it enables you to put spaces in your identifiers.

I think that this is a recepie for confusion and misunderstanding, both for humans and for developer tools. I do not understand how can it be "cool" ?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: