What programming language is most like natural language? [closed]
Asked Answered
A

33

61

I got the idea for this question from numerous situations where I don't understand what the person is talking about and when others don't understand me.

So, a "smart" solution would be to speak a computer language. :)

I am interested how far a programming language can go to get near to (English) natural language. When I say near, I mean not just to use words and sentences, but to be able to "do" things a natural language can "do" and by "do" I mean that it can be used (in a very limited way) as a replacement for natural language.

I know that this is impossible (is it?) but I think that this can be interesting.

Anatomical answered 29/1, 2009 at 15:12 Comment(4)
I was going to suggest APL, but I know some people on this site have no sense of humor.Navarre
And what it is are you trying to do ? Or is this just a hypothetical discussion ?Dymoke
There are several natural language programming systems that resemble the English language, including EnglishScript.Glaab
I don't think any programming language can be used as a replacement for natural language. They're both called languages but they're not really the same thing at all. For example, how would you say "We're out of apples, could you get some on the way home from work."?Devise
C
120

There is a programming language called Inform that, in its most recent incarnation, Inform 7, looks a lot like natural language...in particular, written language.

Inform is very specifically for creating text adventure games, but there is no inherent reason that the concepts couldn't be extended into other realms.

Here's a small snippet of Inform 7 code, taken from the game Glass, by Emily Short.

Stage is a room. 

The old lady is a woman in the Stage. Understand "mother" or 
"stepmother" as the old lady. The old lady is active. The description 
of the lady is "She looks plucked: thin neck with folds of skin
exposed, nose beaky, lips white. Perhaps when her fortunes are mended
her cosmetics too will improve." 

The Prince is a man in the Stage. The description of the prince is
"He's tolerably attractive, in his flightless way. It's hard not to
pity him a little." The prince carries a glass slipper. The glass
slipper is wearable. Understand "shoe" or "heel" or "toe" or "foot"
as the slipper. The description of the slipper is "It is very small
for an adult woman's foot." 

Complete code can be found here.

This is a small simple example...it can actually handle a surprisingly robust set of ideas.

It should be pointed out that the code isn't really a strange cypher where the constructs have hidden meanings...this code does more or less what you would expect. For example:

The old lady is a woman in the Stage. Understand "mother" or 
"stepmother" as the old lady. 

creates an object that happens to be a female person, names that object "old lady", and places that object within the room object called the "Stage". Then two aliases ("mother" and "stepmother" are created that also both reference the "old lady" object.

Of course, as the examples get increasingly complex, the necessary hoops to jump through also become more complex. English is, by its very nature, ambiguous, while computer code is most definitively not. So we'll never get a "perfect marriage".

Chrysostom answered 29/1, 2009 at 15:12 Comment(6)
Oh yes, I once saw this but forgot it... You go up! :)Anatomical
very funny what the code highlighter did to the snippetHoofed
Be warned, writing in Inform is not half as intuitive as reading it is! Fun, though.Yeti
Can you do anything useful in this language?Puzzle
@Zubair: Well, the language is very good at what it is designed for, which is the creation of text adventure games. It is actually remarkably robust at handling the vargaries of language, but it can also handle more abstact concepts like those that would be found in a puzzle oriented game. Many objects are pre-built into libraries, but a programmer can choose build objects with arbitrary sets behaviors from scratch. Not surprisingly, the more abstract the concept, the further the language deviates from what one might deem "natural."Chrysostom
What a piece of news! A lot more elegant than the English language itself. Greatly simplified our lives as Non-Native-English speakers!Etiquette
E
44

Depends on what circles you roll in, but LOLCODE could be considered like natural language ;)

Example loop:

HAI
    CAN HAS STDIO?
    I HAS A VAR
    IM IN YR LOOP
        UP VAR!!1
        VISIBLE VAR
        IZ VAR BIGGER THAN 10? KTHXBYE
    IM OUTTA YR LOOP
KTHXBYE

On a serious note, VB is a pretty natural language. It's easy for non-programmer types to learn, so the syntax must be pretty easy to understand.

Edom answered 29/1, 2009 at 15:12 Comment(10)
Heh, I'm not sure what natural language that is. ;)Ishmael
I also suggested VB - but got downvoted. Annoying. I've got to agree though, LOLCODE is brilliant :)Cinnabar
Ya, VB doesn't get a lot of love.Avoirdupois
It may not get a lot of love, but people can't really deny that it's easy to understand. Hence there are a lot of junior-grade VB programmers running around giving the language a bad name.Edom
@EB What is pathetic is how people downvote for emotional reasons when in fact VB (other than being the work of the devil) is a really easy-to-read language.Cinnabar
I agree that it certainly fits as a valid answer to the question. I don't even think the most recent incarnation of VB is bad as a language (don't get me started about VB6 though).Avoirdupois
Sorry but VB is not a natural language.. I understand if you have been coding in VB for a while so it can look natural to you, so maybe your eyes have been VBfiedDavid
I've written very little VB code, but the syntax does seem very easy and natural to me. To each his own, though.Edom
Honestly, LOLCODE is a better example of natural language than VB is. Granted, it's a crazy, silly language, but it's not overly dissimilar from English.Chrysostom
It's not natural language for humans, but cats have no trouble with it... ;)Narceine
P
34

The language Richard Pryor used to transfer millions of dollars with in Superman III was very close:

> TRANSFER $1,000,000 DOLLARS TO WEBSTER'S ACCOUNT.... NOW

;-)

EDIT: characters corrected ;-)

Peculiarity answered 29/1, 2009 at 15:12 Comment(0)
C
21

Lisp (of course (if you know what I mean (LOL)))

Caa answered 29/1, 2009 at 15:12 Comment(4)
oh... i get it (damn right (it's really funny))!Wennerholn
(Read from in to out (Wrong!))Gand
(yeah! (programming in lisp (is fun)))Nuclide
LISP == Language Involving Speech Pathology.Lungki
E
21

COBOL reads a lot like English

000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID.     HELLOWORLD.
000300
000400*
000500 ENVIRONMENT DIVISION.
000600 CONFIGURATION SECTION.
000700 SOURCE-COMPUTER. RM-COBOL.
000800 OBJECT-COMPUTER. RM-COBOL.
000900
001000 DATA DIVISION.
001100 FILE SECTION.
001200
100000 PROCEDURE DIVISION.
100100
100200 MAIN-LOGIC SECTION.
100300 BEGIN.
100400     DISPLAY " " LINE 1 POSITION 1 ERASE EOS.
100500     DISPLAY "Hello world!" LINE 15 POSITION 10.
100600     STOP RUN.
100700 MAIN-LOGIC-EXIT.
100800     EXIT.

source

Enrichetta answered 29/1, 2009 at 15:12 Comment(2)
When I used COBOL, we didn't have line numbers. We had to read it both ways, uphill, in neck-deep snow.Klein
I heard that when COBOL was released, many people expected that there would be no more professional programmers within a few years - since obviously, COBOL was so easy to use that anyone who needed a program could write it themselves.Wittol
C
19

Good 'ol AppleScript touts its likeness to english as one of its strengths. However, it's not very fun to work with.

Confiscable answered 29/1, 2009 at 15:12 Comment(2)
tell author "bartek" "I tend to agree" end tellChristi
AppleScript is a read-only language =)Millymilman
J
17

HyperTalk - the language behind Apple's HyperCard.

 on mouseUp
   put "100,100" into pos
   repeat with x = 1 to the number of card buttons
     set the location of card button x to pos
     add 15 to item 1 of pos
   end repeat
 end mouseUp

HyperTalk on Wikipedia

James answered 29/1, 2009 at 15:12 Comment(1)
HyperTalk is also the ancestor of AppleScript.Narva
F
17

If you're a connoisseur, the Shakespeare Programming Language is fairly natural ;)

There is a limit to how 'natural' you can get in programming though. Human languages are too open to interpretation - a programming language needs to be specific and precise, I don't think that meshes well with having a 'natural' programming language.

Flouncing answered 29/1, 2009 at 15:12 Comment(2)
Makes me wonder--is "Hamlet" a valid program? And if so, what does it do?Nutrient
Uses up 100% CPU whining about its parent processes, doesn't do anything for days, and then finally kills all processes on the system including itself!Flouncing
V
9

I don't know that I'd go as far as to say that VB.NET is close to the English language, but I think it's about as close as you really get. Sure, once you've programmed it for a while, it seems like English - it does read like a book to a seasoned VB programmer, but if you stop and think about real world English:

For i As Integer = 1 To 10
  Console.WriteLine("Hello World")
Next

Is a long way from:

Write "Hello World" and move to the next line of the console 10 times.

Of course, the English is ambiguous - does it want you to do the whole thing 10 times, or just write "Hello World" once and then move to the next line 10 times?

I guess we need to learn to talk in a less ambiguous fashion:

Do this 10 times: In the console, write "Hello World" and move to the next line.

But I doubt very much there's a programming language that really reads like English. Even those Cobol fanatics that say it's like natural language - it really isn't if you stop and think about how you think about things in a real way instead of in the manner defined by the programming language.

Even in VB you're limited to the way the framework dictates the way you do things...

Vise answered 29/1, 2009 at 15:12 Comment(0)
I
7

gherkin is a domain specific language to describe executable bdd-specifications. It is used among other by cucumber (ruby) and specflow (dotnet).

Example

    Feature: Browsing
        In order to see who's been on the site
        As a user
        I want to be able to view the list of posts

    Scenario: Navigation to homepage
        When I navigate to /Guestbook
        Then I should be on the guestbook page

    Scenario: Viewing existing entries
        Given I am on the guestbook page
        Then I should see a list of guestbook entries
            And guestbook entries have an author
            And guestbook entries have a posted date
            And guestbook entries have a comment

    Scenario: Most recent entries are displayed first
        Given we have the following existing entries
            | Name      | Comment      | Posted date       |
            | Mr. A     | I like A     | 2008-10-01 09:20  |
            | Mrs. B    | I like B     | 2010-03-05 02:15  |
            | Dr. C     | I like C     | 2010-02-20 12:21  |
          And I am on the guestbook page
        Then the guestbook entries includes the following, in this order
            | Name      | Comment      | Posted date       |
            | Mrs. B    | I like B     | 2010-03-05 02:15  |
            | Dr. C     | I like C     | 2010-02-20 12:21  |
            | Mr. A     | I like A     | 2008-10-01 09:20  |
Interpenetrate answered 29/1, 2009 at 15:12 Comment(2)
The Github link seems to be broken now. Can this link be updated?Glaab
I have updated the moved linksInterpenetrate
A
7

Perl has some design principles that are based on how humans process natural languages (see http://www.wall.org/~larry/natural.html ).

That's a different thing from syntactical hacks to make code read like sentences in English or some other language. I'm not entirely convinced that those are useful. As an analogy, I can also make ASCII art with my code, but that doesn't mean that my language is based on principles of visual composition.

To give an example of where it may not be useful,suppose this does what it looks like it does in some rubyish/smalltalky language:

3.times say "hello!" 

That's nice, it makes my code a bit more readable, and there's a similar sort of fun in it to having a parrot that can talk, but it's only useful if I know the underlying rules of the computer language. The fact that it happens to look like English gives me no extra leverage or insight. I can't use the English grammar processing engine in my brain to generate sentences like the following:

// The dot looks like misplaced punctuation 
// in the "English" above, but it's essential in 
// the computer language
3 times say "hello!" // syntax error

// In a natural language, a reordering might make
// sense, but it's impossible here because the word
// order was essential to carrying the parameters
// to the method invocation in the right order.
say "hello" 3 times // syntax error
Alexandria answered 29/1, 2009 at 15:12 Comment(1)
Yep, but Perl needs all of the help it can get in readability, IMO.Boisvert
T
7

Well, Plain English, of course!

To sing the beer song:
  Put 99 into a number.
  Loop.
  If the number is 0, break.
  Format a string given the number and "bottle" and "bottles".
  Write the string then " of beer on the wall, " then the string then " of beer.".
  Format another string given the number minus 1 and "bottle" and "bottles".
  Write "Take one down and pass it around, " then the other string then " of beer on the wall.".
  Skip a line.
  Subtract 1 from the number.
  Repeat.
  Write "No more bottles of beer on the wall, no more bottles of beer.".
  Write "Go to the store and buy some more, 99 bottles of beer on the wall.".

To format a string given a number and a singular string and a plural string:
  If the number is 0, put "no more " then the plural into the string; exit.
  If the number is 1, put "1 " then the singular into the string; exit.
  Put the number then " " then the plural into the string.

I haven't actually used this - I found it here.

Tulle answered 29/1, 2009 at 15:12 Comment(0)
S
5

I'd say SQL or COBOL.

Schooling answered 29/1, 2009 at 15:12 Comment(6)
"SELECT ID, LNAME, FNAME, CONCAT(FNAME, LNAME) AS FULLNAME FROM tblA LEFT JOIN tblB ON tblB.FKID = tblA.ID" is like natural language?Kreiner
Damn - if that's like natural language - what the heck language do you speak? I mean, after you've coded in them for a while, sure it makes sense - but that's because you begin to think like the code, not the other way around.Vise
No, but if someone who knew nothing about SQL saw "select name,phone_number from customer where city='Las Vegas'", they'd have a pretty easy time figuring out what it did. If you name your tables things like "tblA and tblB" that's your problem. :-)Schooling
yah, SELECT phNum FROM customers WHERE email='[email protected]' is pretty much natural languageZiwot
To follow up, this is pretty readable: "SELECT id, last_name, first_name, CONCAT(first_name, last_name) AS full_name FROM people LEFT JOIN last_names ON last_name.id = first_name.id" Like others have said, it depends on variable names.Ishmael
I dunno. There's a big difference between "being able to infer what the statement will do" and "being like natural language". I'd say some of these examples of sql would be pretty easy to have novices decipher...but none of them are very much like a natural language.Chrysostom
I
5

Well, Ruby and Python are supposed to be fairly close. Ruby even goes to the length of adding special keywords that simulate real life. Such as the unless keyword, etc.

Of course, one you type real code in either of those 2 languages, it's not really like natural language, but then again what is?

Ishmael answered 29/1, 2009 at 15:12 Comment(3)
I think "unless" is from Perl...Evolutionist
ugh, i've seen both and i don't think they qualify.Pollster
5.times{ print 'Chunky Bacon!' }Theresatherese
K
4

Forth is reverse-Polish based, and would work naturally for some people.

"Learn Forth quickly I will" - Yoda.

Klein answered 29/1, 2009 at 15:12 Comment(1)
.mazdagz ein ęis aJMedusa
K
4

the syntax of VB.NET is very near to English language

Kickback answered 29/1, 2009 at 15:12 Comment(0)
S
3

Although not exactly what you asked for, there are languages that accomplish what you want, but from the other direction. Lojban, for example, is a language made to be used as a natural language, but without ambiguity.

Lojban (pronounced [ˈloʒban]) is a constructed, syntactically unambiguous human language based on predicate logic.

Sworn answered 29/1, 2009 at 15:12 Comment(0)
O
3

That is called "pseudocode". You use whatever means necessary to communicate the intent of the code (you have written or will later write).

Any programming language has some features that are ambiguous to outsiders.

Osterman answered 29/1, 2009 at 15:12 Comment(0)
E
3

Well natural language is equivocal, and takes a bit more than a literal linear reading to understand. But that being granted, VB.NET is getting close in some constructs. Closest I've seen.

For Loop in VB.NET

For i = 0 To 2
  'loop time!
Next i

It's about as "natural" as I've seen without being too verbose.

Estriol answered 29/1, 2009 at 15:12 Comment(3)
"Dim i as integer" means nothing to those not familiar with basic. And how is "System.Control.Writeln" more natural than "print"?Schooling
@Graeme - Yes, "Dim" is pretty non-natural. My example was the for loop syntax, not the dim, or the system.control.writeln(). I do agree with you though.Cinnabar
@Graeme: Dim is just short for Dimension, and Dimension myVariable as Integer, set value to 0 sounds like english to me. And WriteLine sounds to me more natural then print, if I wanna write a line.Acosta
P
2

I believe your question is based on a fallacy. Programming is not mainly about translating from human to computer language. It is understanding technical problems and designing programs that is hard, typing in the code is a minor part. Learning a programming language won't make someone a programmer any more than learning musical notation will make them a composer.

That said, if you write at a high enough level in almost any language and spend a few minutes explaining syntax, you can communicate the gist of a piece of code to a dedicated non-programer. Conversely, a precise enough natural language specification can sometimes be translated into high level functions (although people are rarely willing to put in the effort to write such a spec.)

Planking answered 29/1, 2009 at 15:12 Comment(0)
G
2

I believe William Shakespeare was the world's best programmer...

The Shakespeare Programming Language

Gumboil answered 29/1, 2009 at 15:12 Comment(0)
T
2

Applescript looks like natural language.

Thormora answered 29/1, 2009 at 15:12 Comment(0)
K
1

Sanskrit comes close to what you describe. It has no redundancies, it was the first language to follow BNF which is the basis of all modern prog. language grammar, and it shares a common Indo-European descent with English

Kinsey answered 29/1, 2009 at 15:12 Comment(5)
Is that why indians are so good at coding? :DSpindry
Thats a different story, India has a huge population of engineers (due to the upbringing and education) and most of them are developers. Hence, even though the probability of finding a talented coder is low, the numbers makes up for it. Also its fair to say that they are given a overdose of math at school. Sanskrit is really difficult to master so only a few choose it as a language at school.Kinsey
This is an answer to the converse question, "What natural language is most like a programming language?"Nuts
@Nuts since OP is trying to find a convergence i think its okay for (a == b) to the same as (b == a) in this caseKinsey
The question was about programming languages.Veilleux
S
1

With Ruby and Oslo (and possibly F#), you could build a very language-friendly DSL. That's at least the promise of Oslo. You can find an example of an Oslo grammar for BDD here.

Sutler answered 29/1, 2009 at 15:12 Comment(0)
D
1

COBOL was created with the specific intent of being like natural language (English in this case)

Diesis answered 29/1, 2009 at 15:12 Comment(2)
and it proved perfectly that English is not suitable for writing large programs ;)Brockwell
@Aaron: Or even small ones - I had to think really hard about how to remove ambiguity from my English to write something that took me 5 seconds to type in VB...Vise
W
0

For me, It is Python.

YMMV

Wilda answered 29/1, 2009 at 15:12 Comment(0)
M
0

I thought of Eiffel. Quote from here:

Raphael Simon, lead software engineer for Eiffel Software, said the language was designed so that one could use natural language to write the program.

See for example the 99 bottles of beer program.

I wouldn't say it's the "most" natural, but I find it rather natural.

Mallorca answered 29/1, 2009 at 15:12 Comment(0)
W
0

What we normally call "pseudo-code" is very, very close to Pascal. That probably doesn't make it particularly close to natural English, but if it weren't simpler than most langauges, we wouldn't write pseudo-code at all (we'd just write code).

Wot answered 29/1, 2009 at 15:12 Comment(0)
S
0

I wish there was a COmmon Business Oriented Language that read like English so everyone, even non-programmers could unterstand it... Maybe we should create one! (stolen from here)

Sfax answered 29/1, 2009 at 15:12 Comment(1)
If you could understand it, wouldn't you become a programmer?Swart
M
0

Cobol is close to English as it gets

I believe Logo is also not too far from the English language

Meat answered 29/1, 2009 at 15:12 Comment(0)
P
-1

I propose Lua. Sample Code:

function modulus(num, mod)
    return num % mod
end
for i = 1, 1000 do
    local done = false
    if modulus(i, 3) == 0 then
        print("Fizz")
    else if modulus(i, 5) == 0 then
        done = true
        print("Buzz")
    end
    if modulus(i, 5) == 0 and not done then
        print("Buzz")
    end
    print(" ")
end

not the most english-like, but pretty darn readable even if i do say so myself!

Pollster answered 29/1, 2009 at 15:12 Comment(0)
T
-2

Of course it would also have to have an ability to generate concepts and then "name" these concepts, so these could be used to express more complex construct, i.e. basically would have to have some sort of support for ontology of the world, it is supposed to be used in. I think if something like "inform" language describe in an earlier post, coupled with some backend concept network or ontology database, would be a good way to start.

Terceira answered 29/1, 2009 at 15:12 Comment(1)
Hard to read - consider revising. Also, your point isn't getting across to the OP.Menticide
A
-3

Natural languages are notorious for their inconsistent grammars. The most consistence grammar of any natural language is of Sanskrit. In fact the structure of this language is so solid that it was possible to have a prominent search engine based on pronunciation. Alas, this language is more or less is dead.

Allowedly answered 29/1, 2009 at 15:12 Comment(1)
That's not true about Sanskrit. If you were to make that argument, then actually Avestan (a sister language in the Indo-Iranian family which fixed the syntactical, semanatical and lexigraphical errors of Sanskrit) would be more consistent. But saying that one natural language is better than another is extremely subjective.Scapolite

© 2022 - 2024 — McMap. All rights reserved.