views:

2737

answers:

33

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.

+35  A: 

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.

Alex Fort
Heh, I'm not sure what natural language that is. ;)
Sasha
You got there first....
ck
It might be "natural language" to someone who speaks TXT, like any teenager, but nobody that speaks real languages would understand that at a glance.
BenAlabaster
I also suggested VB - but got downvoted. Annoying. I've got to agree though, LOLCODE is brilliant :)
Jonathan Sampson
Ya, VB doesn't get a lot of love.
EBGreen
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.
Alex Fort
@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.
Jonathan Sampson
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).
EBGreen
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 VBfied
TStamper
I've written very little VB code, but the syntax does seem very easy and natural to me. To each his own, though.
Alex Fort
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.
Beska
It's not natural language for humans, but cats have no trouble with it... ;)
MiffTheFox
I HAVE to learn LOLCODE!
PRINCESS FLUFF
+2  A: 

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.

Jonathan Sampson
"Dim i as integer" means nothing to those not familiar with basic. And how is "System.Control.Writeln" more natural than "print"?
Graeme Perrow
@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.
Jonathan Sampson
@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.
Bobby
+7  A: 

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?

Sasha
I think "unless" is from Perl...
Adam Neal
ugh, i've seen both and i don't think they qualify.
RCIX
`5.times{ print 'Chunky Bacon!' }`
Earlz
+16  A: 

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

jmein
Except the line numbers...
chills42
When I used COBOL, we didn't have line numbers. We had to read it both ways, uphill, in neck-deep snow.
David Thornley
+1 for David's comment...
bcasp
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.
Michael Borgwardt
+1  A: 

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

Jason Punyon
and it proved perfectly that English is not suitable for writing large programs ;)
Aaron Digulla
@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...
BenAlabaster
+2  A: 

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

Marwan Aouida
Be careful, I suggested VB.NET and got downvoted ;)
Jonathan Sampson
+5  A: 

I'd say SQL or COBOL.

Graeme Perrow
"SELECT ID, LNAME, FNAME, CONCAT(FNAME, LNAME) AS FULLNAME FROM tblA LEFT JOIN tblB ON tblB.FKID = tblA.ID" is like natural language?
MusiGenesis
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.
BenAlabaster
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. :-)
Graeme Perrow
yah, SELECT phNum FROM customers WHERE email='[email protected]' is pretty much natural language
Unkwntech
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.
Sasha
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.
Beska
Cobol, I can see, but SQL??
Shadowfirebird
+18  A: 

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 ;-)

Galwegian
you beat me to it. :(
Kevin
Nice. I found this http://meatfighter.com/superman3/part1/index.html but they leave out the salami slicing code. :(
Bill the Lizard
@Bill - excellent link - thanks!
Galwegian
I liked how be broke in at the beginning too: "OVERRIDE ALL SECURITY"
Matthew Crumley
I love the 'NOW' clause. If only SQL supported it no one would have problems with queries taking several minutes.
Sergio Acosta
A: 

Cobol is close to English as it gets

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

SQLMenace
+1  A: 

Applescript looks like natural language.

mouviciel
+16  A: 

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

Bartek Tatkowski
tell author "bartek" "I tend to agree" end tell
plinth
+1 for not fun to work with (read: sucks).
sirlancelot
AppleScript is a read-only language =)
Sergio Acosta
+1  A: 

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.

Leonidas
+1  A: 

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)

DrJokepu
It'll never work.
David Thornley
If you could understand it, wouldn't you become a programmer?
Jeff O
+15  A: 

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.

Phill Sacre
Makes me wonder--is "Hamlet" a valid program? And if so, what does it do?
Michael Myers
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!
Phill Sacre
+10  A: 

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

Tony Lambert
HyperTalk is also the ancestor of AppleScript.
bendin
+8  A: 

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...

BenAlabaster
+1  A: 

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.

Ryan Riley
A: 

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).

rmeador
+78  A: 

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".

Beska
Wow that's awesome - I'm sending this to my English teacher buddy
Mike Robinson
Oh yes, I once saw this but forgot it... You go up! :)
kliketa
That looks very nice :)
tunnuz
+1 now this is as natural as it gets
TStamper
very funny what the code highlighter did to the snippet
Marek
Be warned, writing in Inform is not half as intuitive as reading it is! Fun, though.
Shadowfirebird
Can you do anything useful in this language?
Zubair
@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."
Beska
+3  A: 

Well, Plain English, of course!
(I haven't actually used this - I found it here.)

Lucas Jones
+11  A: 

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

Carl Seleborg
oh... i get it (damn right (it's really funny))!
Beau Martínez
+2  A: 

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

The Shakespeare Programming Language

Mike Robinson
+6  A: 

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
d__
Yep, but Perl needs all of the help it can get in readability, IMO.
kenny
kenny , I think you will be killed
xxxxxxx
+4  A: 

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

"Learn Forth quickly I will" - Yoda.

David Thornley
.mazdagz ein ęis aJ
Artelius
+1  A: 

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 its one of the languages from which English was born.

Reno
Is that why indians are so good at coding? :D
Camilo Martin
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.
Reno
This is an answer to the converse question, "What natural language is most like a programming language?"
ShreevatsaR
A: 

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!

RCIX
+2  A: 

Assembly language.

Oh, you meant natural for a human

Carson Myers
+1  A: 

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.

Graphics Noob
+2  A: 

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.)

RossFabricant
A: 

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.

Daniel Daranas
A: 

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.

Dilawar
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.
Otaku
A: 

For me, It is Python.

YMMV

rpg
A: 

I think VB sample code here

Function factiorial(ByVal n)
    Dim fact As Decimal = 1
    For i As Integer = 1 To n
        fact *= i
    Next
    Return fact
End Function

Assembly language also because every step about an event like (MIPS assembly language ) a chunk of code here :

loop:   
 lb $s1, 0($t0)
 beq $s1,$zero,end
 slt $t5,$s1,$t7
 beq $t5,$zero,notupper
 slt $t5,$s1,$t6
 bne $t5,$zero,notchar
 addi $s1,$s1,0x20
 sb $s1,0($t0)

 addi $t0,$t0,1
 j loop

finally we cannot compare human languages to programming or machine languages.

Bobj-C