FG_Regulus
FG_Regulus

Reputation: 11

Language Design - Uppercase Keywords

So I recently decided that for a fun little pet programming project, I would design my own language and build tools around it (compiler, autodoc, autolint). So far, I'm still on the language design stage, and I came across a topic that I'm kind of stuck on: Should keywords be upper-cased?

By keywords, I don't mean built in types or functions, I mean the words like "FOR" "IF" "ELSE", etc. My logic behind using it would be that it's much faster to recognize the code structure and syntax, especially if syntax highlighting weren't available (some places it still isn't, such as print sources or websites). The majority of time is spent reading code, so it would make sense to increase efficiency of the reading of code, at the cost of having to press caps lock twice per keyword, or hold down shift while typing them. What's everyone's opinion here?

Also, I know it's just a silly pet-project, but I want it to be done right, I'm a bit of a perfectionist. And I also plan on using it myself just to play around, while continuing it's optimization/development (learning purposes of course). So I don't to make decisions I'll regret or have to break all my previous code or possibly even compiler for.

Thank you in advance.

EDIT: And because it's only used on major keywords like that, it would also avoid the cognitive slow-down of reading upper-case and keep the code from "SCREAMING" to much.

Upvotes: 0

Views: 608

Answers (3)

August Karlstrom
August Karlstrom

Reputation: 11377

Here are the advantages I can think of. Point 2 and 3 assume that the programmer uses only lower- or mixed-case identifiers.

  1. When reading the source code it is immediately clear what is a keyword and what is not.

  2. A programmer can use any name for an identifier.

  3. New keywords can be added to the language without breaking existing programs.

  4. When keywords are written in prose no extra formatting, like bold or typewriter font, is needed. Also, in the language grammar no extra quotes are necessary to separate keywords from non-terminal symbols.

Here are the disadvantages I can think of:

  1. Upper-case words are harder to type (they are also slower to write by hand).

  2. Source code with lots of upper-case words may look unfamiliar in these days when lower-case keywords is the norm.

The first disadvantage can partly be overcome by using a "smart" editor which converts some lower-case words to upper-case as you type.

Upvotes: 0

tangentstorm
tangentstorm

Reputation: 7315

The Oberon programming language works this way. I found it to to be very readable, but somewhat unpleasant to type by hand. It was annoying enough that I set up auto-completing templates for all the control structures in my editor, but after that I was happy with it.

I say go for it, if you like the way it looks. Lots of people won't like it, but maybe a small few people will share your tastes and love it.

BTW, Dr Wirth (creator of oberon, modula-2, pascal) has pretty decent great book on building compilers on his home page:

All the code is written in Oberon, so you can see what a language looks like using the style you're talking about.

Upvotes: 2

paxdiablo
paxdiablo

Reputation: 882366

Personally I think that's a mistake. I'm not likely to use a language that keeps me hovering over the CAPSLOCK key while I'm typing in code, or forces me to hold down the SHIFT key more than I need to.

This is probably something I'd leave up to the editor or IDE, if it was considered a necessity. But, to be honest, there are both color printers and color HTML markup tags, so I'm not convinced of that necessity based on your question content.

Upvotes: 2

Related Questions