5 ms·
A few months ago, I was daydreaming about creating a new programming language and started thinking about language internationalization. I found this page, with
by dguo 9y ago
A few months ago, I was daydreaming about creating a new programming language and started thinking about language internationalization. I found this page, with some interesting comments: https://blogs.msdn.microsoft.com/alfredth/2011/07/21/why-are-all-programming-languages-in-english/ https://blogs.msdn.microsoft.com/alfredth/2011/07/21/why-are...
As an aside, this one stuck out to me: "One of the difficulties in allowing the keyword to be switched on the fly to a different language is that keywords have to be 'reserved' such that they cannot be used as identifiers"...
I find the concept of reserved keywords kind of strange. It seems like a "smarter" language/parser should be able to handle a keyword being used as an identifier.
- yoz-y 9y agoIt 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.
- amyjess 9y ago> 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) https://en.wikipedia.org/wiki/Stropping_(syntax) [1] Example from an HTML-ized copy of the spec: http://www.masswerk.at/algol60/report.htm 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;
- yoz-y 9y agoIt 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.
- delian66 9y ago>>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" ?
- xenadu02 9y agoProgramming 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.
- Retra 9y agoA "smarter" language/parser has implications, though. It means your text editors & IDEs need to be more elaborate to handle it. It means new users have more to take in before they can be productive. It's more complexity and thus more effort to maintain. All in all, making a smarter language/parser means making a more expensive language/parser, and that means you're making a tradeoff that isn't always justifiable.
- RubenSandwich 9y agoThere seems to be a few ways around this issuie: 1. You could create a programming language where every keyword is a symbol: http://ccsenet.org/journal/index.php/cis/article/view/23904 http://ccsenet.org/journal/index.php/cis/article/view/23904. This is what mathematics does. 2. You could also create a programming language where every reserved keyword is a special type and then expose that type to the programmer. Thereby allowing them to reuse that word just with a different type then the reserved keyword. This would come with a lot of complexity costs however because now you don't know if your generated AST is valid until the typechecker.
- JasonFruit 9y agoBASIC on the ZX80 and its variants encoded keywords as bytes in memory but displayed them as English-like words; there's no reason those keywords couldn't be displayed in another language, regardless of their internal representation.
- tjalfi 9y agoAn advantage of reserved keywords is that users cannot write code like this PL/I snippet. IF IF = THEN; THEN ELSE = IF; ELSE ELSE = THEN;