2

Programming languages like sEnglish, Inform7, WolframAlpha, and even AppleScript purport to use the "natural language programming" (NLP) paradigm. Even SQL is a kind of NLP, if you think about it.

Since I've only ever seen these in English, I wonder if the grammar and syntax of English make it a great candidate for programming expressions.

I'm inclined to doubt it, because my beef with NLP is that English vocabularly is overloaded and is particularly ambiguous, whereas programming languages (even NLP) demand clarity and precision of expression. So you get sucked into thinking "Hey, natural language, this should be easy. I already speak English!" And you wind up unconsciously extending the syntax with other constructions that are understood in English by humans, but don't survive the compiler's syntax checking.

Note that I'm not asking if English is "logical," because it isn't. And, as John McWhorter says, "No language makes perfect sense."

3
  • Rob., the more a language is inflected, the more it fits NLP; and, at the contrary to what Mitch says, in this respect Latin is the best. Dec 18, 2013 at 21:06
  • 1
    There is no evidence that any natural language would be better suited than another, and I am strongly inclined to believe that there is little difference. Apparent ambiguity is a feature, not a bug, of all natural languages, because it is extremely efficient for humans. Dec 20, 2013 at 15:50
  • @Cerberus: Agreed.
    – Robusto
    Dec 20, 2013 at 15:51

3 Answers 3

7

<statement type="highly opinionated"> I don't think any human language is well-suited to "natural language programming". I don't think there is any such thing in real life.

Computer people are always saying, "Wouldn't it be great if instead of having to learn all these complex commands, you could just tell the computer what you want in ordinary [English/Russian/Swahili/whatever]!" And yeah, that would be really great. But every time they try it, what they come up with is always just another computer language with little noticeable difference from other computer languages. Well, other than being more verbose, i.e. using words instead of symbols. So instead of saying "x+=5" they say "add 5 to x". Gee wow.

I recall a program for drawing graphs that I used a few years back that boasted "natural language" to describe the graphs. It turned out that what this meant was mostly that it ignored any words it didn't recognize with no warning. They gave an example in the manual: The command to put tick marks along an axis was "tick marks on x axis" or "tick marks on y axis". And so they boasted that if you said "add minor tick marks on x axis" it would ignore the "add" and "minor". Personally I'd prefer if software told me that it didn't understand something rather than silently ignoring anything it didn't understand, because then I know that what I tried to say isn't valid rather than having to guess which part was ignored.

Right now I'm working with a tool called Django that boasts that users can design web pages without having to know any programming!!! It turns out that was this means is that if, say, you want a certain block of text to appear only when a variable called x is equal to 1, then instead of having to write a line of code in Java or Visual basic or whatever, like "if (x==1)" or "if x=1 then", instead you can do it with no code at all! Just in the HTML page write "<% if(x=1) %>". Yeah, that's not like programming at all!

I question if the idea is even possible. One of the beauties of human languages is that it allows us to communicate without having to specify every detail. We can rely on the hearer's experience and knowledge to fill in all the gaps. We can discuss things in general terms. We can discuss difficult to define concepts like "beauty" and "freedom", or for that matter "good customer".

So suppose a boss said to his marketing director, "Make me a list of our best customers who live near our main stores, and suggest some incentives we could give them to increase sales." Any good marketing person could do that. But now suppose you gave that command to a computer programmed to respond to "natural language". How could it answer? What is a "best customer"? How is that defined? What is "near"? What is a "main store"? The problem isn't that the boss forgot to give the details. It is that he wants the marketing director to use his intelligence to come up with details that make sense.

Don't even get me started on "artificial intelligence".

PS: My credentials: I've been developing software since 1980. I have published a book on database design. </statement>

5
  • 4
    New Command: Whatever you do, do not put tick marks on x axis.
    – horatio
    Dec 18, 2013 at 20:32
  • Perhaps NLP should be seen an an analogue property, rather than a binary one; I agree that no programming language can ever be so close to a human language that knowing one means you can use the other, but I also think that a programming language closer in terminology and syntax to a real-world language may be easier for a human to learn and understand than one that isn't.
    – user867
    Dec 19, 2013 at 3:47
  • Horatio: That's actually pretty close to another example from their manual. One of their commands was "frame", which drew a box around the graph. They amitted that there were limits to their "natural language" processing, and gave the example that if you wrote "by all means do not draw a frame", it would recognize "frame" and draw the box!
    – Jay
    Dec 19, 2013 at 18:03
  • user867: To an extent, sure. I personally prefer Visual Basic to the C/Java family in some ways, namely I find it easier to read things like "if x>0 and y=7 then ... end if" then "if (x>0 && y==7) { ... }". Yeah, it's more to type, but it just reads nicer. But that's a long, long way from what proponents of NLP claim that they will be able to do Any Day Now.
    – Jay
    Dec 19, 2013 at 18:07
  • Bravo to you, sir.
    – Robusto
    Jan 25, 2014 at 19:03
5

There are too many ambiguities in English as a whole to make it useful as an NPL. Even in languages that use pieces of English, prepositions like in and from can point to the same idea but yield drastically different results when the implied meaning "looks right" to the human eye but causes the interpreter or compiler to go in the (from a human viewpoint) wrong direction.

Still, we often use even the wrong operators (= when we mean == or == when we mean ===). But because those concepts aren't words with syntactic counterparts among English words (yes, they can be paraphrased, but mostly not without multi-word circumlocutions: "is the identical object as x and not one just like it" for === and so forth), we don't confuse them as easily as we mix up from and in and of.

Computers can't yet deal well with ambiguity in any language, and English is no exception. That is why the old joke still stands:

A computer doesn't do what you want it to do. It does what you tell it to do.

2
  • 1
    The way I've heard the joke is "Computers are stupid. They do what you tell them to do, not what you want them to do."
    – Marthaª
    Dec 20, 2013 at 15:48
  • @Marthaª: I bow to your superior rendering.
    – Robusto
    Dec 20, 2013 at 15:50
0

Compare:

debug.print "Hello World"

with (http://daimi.au.dk/~eriksoe/Flip/hello-small.flip)

0>1\ />2\ />2\ />2\ />2\ />2\ />2\          
 @  \ X @>*X @>*X @>*X @>*X @>*X @>*\    / \  
 //   v\ / v\ / v\ / v\ / v\ / v\ / v\    Q
    /1*X /1*X /1*X /1*X /1*X /1*X /1*X/   //
    ^  +\^  +\^  +\^  +\^  +\^  +\^  +\   \\
     @ // @ // @ // @ // @ // @ // @ //   //
   0 @  0 @  0 @  0 @  0 @  0 @  0 @      \\
  > X/,  X/,  X/,  X/,  X/,  X/,  X/, / + //
   0>/  0\/  0\/  0\/  0\/  0\/  0\/ >   X
   0 + >   \>   \>   \>   \>   \>   \   @\+|
  \,X  /   \/   \/   \/   \/   \/   \/    P 

 \,<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      8518742187541875418754321718643218754321876318754187417215319
 \    /////////////////////////////////////////////////////////////
     @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Certainly there is a gulph of possibilities between these two examples, but it is clear that NLP is easier to grasp--in basic terms--for a naive reader.

As to whether English is especially well suited to programming, I doubt there is any real benefit aside from the fact that a lot of the documentation is in english. English certainly does not map especially easily to mathematical concepts.

3
  • Though debug.print isn't exactly natural language either ;) Dec 18, 2013 at 22:14
  • 1
    If you examine the documentation for the NLP languages cited in the question, you might change your opinion.
    – horatio
    Dec 18, 2013 at 22:22
  • 1
    I disagree with the premise that SQL for example is near natural language. In contrast, Inform uses statements like 'Instead of taking the crate, say "It's far too heavy to lift."' But in fairness you're right, I could've posted the comment to the OP either. Dec 18, 2013 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.