9
$\begingroup$

Some languages such as Lua and Assembly Basic use keywords for syntax. This includes spelling out words such as do and end in Lua, or spelling out add or mov in assembly.

Other languages such as C or Java use punctuation marks in many parts of the syntax such as using { and } to designate a block, or using + - * / = etc as operators.

What are the advantages and disadvantages of each approach?

$\endgroup$

4 Answers 4

10
$\begingroup$

Advantages of keywords:

  • Makes the language more closely resemble natural language, making it more accessible for beginners who are literate in the given natural language.
    • ...and for blind or visually-impaired programmers using audio screen readers.
  • Depending on your editor font, can be easier to visually distinguish (compared to say, : versus ;).
  • Often easier to type on a keyboard due to not requiring Shift or Alt combinations.
  • Less likely to tempt people into making questionable operator overloading decisions like using bitshifts to do file I/O.

Advantages of punctuation:

  • More concise, especially for mathematical expressions (e.g., a = b * c + d; instead of COBOL-style MULTIPLY B BY C GIVING TEMP. ADD TEMP TO D GIVING A.)
  • Cannot conflict with a user-defined identifier, thus avoiding a backwards-compatibility issue when adding a new operator to the language.
  • Is (human) language independent, thus reducing the amount of vocabulary that a non-English-speaker (or whichever language your keywords are from) needs to learn in order to use your language.

Note that most languages aren't purely keyword-only or punctuation only, but a mix of both.

  • Famously wordy COBOL still uses punctuation: * to start a comment, . to terminate a statement, ' to quote a string literal, < = > for comparisons, and ( ) for field lengths and array indexes.
  • Punctuation-heavy C still uses words for its data types and control-flow statements.
$\endgroup$
5
  • 2
    $\begingroup$ COBOL also works without some of the punctuation operators, as in "IF PAYMENT IS LESS THAN BILLED PERFORM FORECLOSURE, OTHERWISE …". One of the major design points of the language was that managers (with little math and no programming skills) should be able to read the code and sort-of understand it. $\endgroup$ Jul 8, 2023 at 3:04
  • 2
    $\begingroup$ I think the bitshifts in C++ were actually intended to mean "send" and "receive". Other languages still have vestiges of this. go uses <- for recieve from channel. Without a "channel" style model it didn't really take off. $\endgroup$ Jul 8, 2023 at 7:31
  • $\begingroup$ "more accessible for beginners" That's purely subjective. If you only understand English and I task you to write an application in a keyword-only COBOL-like Chinese language, you'll be a beginner and won't have a clue what's going on (and it's more than about vocabulary). But the average programmer is Han, so should I expect you to understand it? $\endgroup$
    – Longinus
    Jul 10, 2023 at 0:17
  • $\begingroup$ @Longinus: Well, I meant beginners who are already literate in the particular natural language on which your programming language's syntax is based. An English speaker is obviously not going to think that Mandarin Chinese-based keywords are intuitive (or vice-versa), which is why I listed "human language independent" as an advantage of punctuation. $\endgroup$
    – dan04
    Jul 21, 2023 at 22:13
  • 1
    $\begingroup$ "often easier to type on a keyboard" but words are typically longer than punctuation, so it cancels out $\endgroup$
    – Seggan
    Jul 24, 2023 at 14:29
6
$\begingroup$

One significant advantage of keywords over punctuation is searchability. If you are not sure what a keyword like async or strictfp means, you can search for it online. Most search engines can't handle search queries for punctuation like :: or ~=, and just ignore the punctuation in your query.

$\endgroup$
2
  • $\begingroup$ Searchability is also useful to consider when naming the programming language itself. $\endgroup$
    – dan04
    Jul 24, 2023 at 23:38
  • $\begingroup$ Try searching for anything in the bash manual (Linux shell). $\endgroup$ Jul 29, 2023 at 12:47
5
$\begingroup$

Another advantage of keywords: the language can be designed to allow extending the keywords (meaning the original grammar is simpler). Whereas operators will always cause a more complicated grammar (consider, for example, ++ vs + operators).

One such language is Kotlin. While it still has reserved keywords and a whole array of operators, you can simulate keyword operators through extension methods and alternative method call syntax (e.g. 5.and(6) can be written as 5 and 6).


On a funny side-note, I'm currently working on a prototype language which specifically follows this approach and is completely operator-less (even the keyword kind).

$\endgroup$
1
  • $\begingroup$ Interesting, thanks for sharing. $\endgroup$ Jul 8, 2023 at 22:31
3
$\begingroup$

Some main perceived advantages of punctuation-heavy syntax are that:

  1. it tends to fit more functionality into a smaller screen space;
  2. it's usually easier to scribble out on paper;
  3. it can avoid visual noisiness in the code.

Some disadvantages are that:

  1. there is a learning curve for meaning of symbols;
  2. certain symbols are relatively more difficult to enter on a standard keyboard;
  3. there is no standard and obvious names or pronunciation for code elements.

There are older languages that exemplify both extremes.

COBOL is wordy to the extent it almost acquires the property of being grammatically correct English - carrying the full overheads of natural language, though without anything like the full expressivity.

APL is so terse as to be almost unreadable, a quality that was widely regarded as having harmed not just the language but the credibility of its tenets more broadly.

The outer limits nowadays are regarded as being somewhere between Basic and C.

In my view, the relative advantages of punctuation-heavy languages have reduced over time:

  • Screens have become much larger - enough that using a short word is no longer a real penalty against using a symbol.

  • Speaking about code has become far more important than handwriting or printing the code itself - emphasising standard vocabulary and pronounceability, rather than speed of writing out and compactness.

  • Code colourisers have made wordiness less visually ambiguous and cluttering.

$\endgroup$
2
  • $\begingroup$ APL is only unreadable to those who don't understand it $\endgroup$
    – Seggan
    Jul 24, 2023 at 14:31
  • $\begingroup$ @Seggan-OnStrike, indeed, and the syntax helps maximise that number. $\endgroup$
    – Steve
    Jul 24, 2023 at 14:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .