Learning to Program in Plain English (Prosaic Version)

Gerry Rzeppa

Member
Dec 13, 2013
195
1
76
www.osmosian.com
Plain English is an experimental programming language. It was developed to answer several questions about programming languages that we felt had not been adequately addressed elsewhere. A lively discussion of those questions can be found here:

http://forums.anandtech.com/showthread.php?t=2358744

Plain English was also developed as an ideal first language for new programmers: we thought, by eliminating (or at least minimizing) the "syntax barrier" present in other languages, we could get the student to focus on fundamental programming concepts instead of punctuation, etc. The purpose of this thread is to show how those fundamental concepts are realized in Plain English code. Let us begin.

Statements

Most programming languages consist of different kinds of "statements" that instruct the compiler (at compile-time) and/or the computer (at run-time) to do something. In Plain English, such statements are called sentences because they are, in fact, grammatically typical English-language sentences. Five kinds of sentences are used in Plain English code, as described below.

1. Type Definitions

Sentences defining types, in Plain English, always start with indefinite articles: specifically, A, AN, or SOME. For example:

A total is a number.

This sentence defines a new data type, called total, and specifies that it is a subset of the built-in type, number.


2. Global Variable Definitions

In Plain English, Global Variables are defined with sentences that start with the definite article, THE. Like so:

The grand total is a total.

The above sentence defines "grand total" as a variable of type "total" which is a sub-type of the built-in type "number". Note that spaces are allowed in names in Plain English; more on names in the next post.


3. Routine Headers

Routine headers, in Plain English, always start with the preposition TO and end with a colon. For example:

To triple a total:

This sentence begins the definition of a routine that will (presumably) triple any variable of type "total" that is passed to it.


4. Conditional Statements

Conditional sentences always begin with the word IF. Like this:

If the grand total is more than 100, beep.

As you can guess, this sentence, when executed, will cause the computer to make a beeping sound if the value of the grand total global variable is greater than a hundred.


5. Imperative Statements

Everything else is considered an imperative sentence in Plain English. For example:

Triple the grand total.

In fact, the "beep" in the conditional statement above is also an imperative sentence (technically, a clause -- a sentence within another sentence). There is a built-in imperative for exiting a routine (EXIT), and three built-in imperatives for the construction of various kinds of loops: one to mark the start of a loop (LOOP), another to break out of a loop (BREAK), and a third to repeat the loop, starting at the top (REPEAT). Here is a sample showing how these statements are typically used in actual practice; note that everything in square brackets is considered a comment:

To loop around:
[stuff we want to do before the loop]
Loop.
[stuff we always want to do in the loop]
If [we want to jump out of the loop], break.
If [we want to jump out of the whole routine], exit.
[stuff we may want to do in the loop]
Repeat.
[stuff we want to do after the loop]


Future versions of Plain English will undoubtedly include other kinds of loop constructs, such as "For each..." and "While...", etc. We've found with beginners, however, that this form is both easy to explain (as above) and easy to use (ie, the student doesn't have to decide what "kind" of loop to employ).


But enough for a first post. More to come. Stay tuned...
 
Last edited:

Gerry Rzeppa

Member
Dec 13, 2013
195
1
76
www.osmosian.com
Names

As mentioned above, in Plain English, names can contain spaces. A good working definition of a name in Plain English is this: anything after A, AN, ANOTHER, SOME, or THE, up to:

(a) any simple verb, like IS, ARE, CAN, or DO, or
(b) any conjunction, like AND or OR, or
(c) any preposition, like OVER, UNDER, AROUND, or THRU, or
(d) any literal, like 123 or "Hello, World!", or
(e) any punctuation mark.

Note that names are not case-sensitive (eg, Grand Total and grand total refer to the same variable).

Names appear in various places in Plain English programs. Specifically:

1. As types

Type names are defined in type definition sentences, as in the previous post:

A total is a number.

Here, "total" is a new type based on the built-in type "number". Note that type names can be used in other type definitions, like this:

A running total is a total.

This sentence defines "running total" as a "total" which is (due to the preceding type definition) a "number".

2. As global variables

Global variable names are defined like so:

The grand total is a total.

Here, "grand total" is defined as a global variable of type "total".

3. As parameters

Parameter names appear in routine headers:

To triple a total:

Here, "total" is the name of a parameter. The parameter is referenced within the body of the routine using the definite article, like so:

Multiply the total by 3.

4. As local variables

Local variables are defined within routines "on the fly" whenever a type name is preceded by an indefinite article. Like this:

Add 1 to a running total.

But good God this is boring! [rest of paragraph deleted by moderator with the remark below]

If you want to discuss the moderation do so in the Moderator Discussions forum, or you'll get this thread locked too.

Markbnj


In any case, I think there are better ways to describe Plain English programming. One can be found here:

www.osmosian.com/instructions.pdf

And a spirited discussion of the pros and cons of natural language programming can be found in a very popular thread right on this site:

http://forums.anandtech.com/showthread.php?t=2358744
 
Last edited: