English-like Python
Terry Reedy
tjreedy at udel.edu
Fri Jan 16 02:20:25 EST 2009
The Music Guy wrote:
> Just out of curiousity, have there been any attempts to make a version
> of Python that looks like actual English text? I mean, so much of Python
> is already based on the English language that it seems like the next
> natural step would be to make a programming language which is actually a
> spoken one.
>
> For example, the following code...
>
>>>> import os
>>>>
>>>> def list_files(dirname):
>>>> for p in os.listdir(dirname):
>>>> print p
>>>>
>>>> list_files("some_dir")
> foo
> bar
> etc
>
> ...might be translated as...
>
>>>> Import the operating system module.
>>>>
>>>> Define a new function as "list files" which accepts
> "a path" and does the following:
> For every item in the list returned by the operating system's
> directory listing of the given path, do the following:
> Print the item.
>>>> List files from "some_dir".
> foo
> bar
> etc
> Obviously, creating a parser capable of handling such "code" would
> require a very good understanding not only of the English language but
> also of how ideas expressed in spoken languages are represented in terms
> that a computer can understand.
>
> A language like this would, of course, blow a lot of staple coding
> coding concepts like "variables," "objects," etc. right out of the
> water. I think, however, that it could be done, and wouldn't necessarily
> have to be any slower than any other scripting language as any text/code
> could be cached as bytecode, just like Python.
>
> I know it's sort of silly but I think something like this would be very
> interesting, maybe even useful. ^_^.
Others have mentioned some examples in this direction. Some problems:
English is not a context free language; a constrained context-free
subset is needed for algorithmic parsing. Should Pynglish change 'a' to
'an' before vowels?
'Define new function "list files"' is good English too. In your
example, you changed '"a path"' to 'the given path'. This will not
parse very easily. Etc.
Writing within such a subset is likely to be more difficult than writing
in Python. It would be easier to slip up and less easy to notice an
error. (Of course, some think Python is too wordy. I think is strikes a
fair balance.) It would also soon get tedious.
It would also be more tedious to read. There is a reason math shifted
from 'plain Greek' to the use of symbols.
While Python uses names derived from English, it is used
internationally. Pynglish would be harder for non-native-English
speakers to learn. I think random indentifiers in non-Latin alphabets
would be more grating in Pynglish sentences than in Python statements.
def #&*#&*$(#%,#^): # versus
Define a new function #&*#&*$ which accepts #% and #^
One could disagree though.
Terry Jan Reedy
More information about the Python-list
mailing list