Google Blogoscoped

Forum

Natural Language Programming?  (View post)

Reto Meier [PersonRank 10]

Monday, December 10, 2007
12 years ago8,663 views

Argh. The abiguity makes me want to weep, the lack of control makes me cringe. To top it all off it's so very wordy. I'd be upset if someone presented this as a spec, let alone finished code!

Interesting idea though, why'd you post it Philipp?

Ionut Alex. Chitu [PersonRank 10]

12 years ago #

I think it would stop at the first line:

<<If the database connection as specified in global settings isn't open>>

What database connection?

Tony Ruscoe [PersonRank 10]

12 years ago #

> What database connection?
The one which was specified in the global settings, of course.

Reto Meier [PersonRank 10]

12 years ago #

...What should it do if it fails to open the connection?

Reto Meier [PersonRank 10]

12 years ago #

What if I have three different database connections in my global settings?

Tony Ruscoe [PersonRank 10]

12 years ago #

> ...What should it do if it fails to open the connection?

It guess it would error, just like if a similar piece of code was written in another language without any error trapping.

> What if I have three different database connections in my global settings?

I guess if there was more than one specified, the code would say *which* one instead of just *the* database connection.

Nikos Kouremenos [PersonRank 1]

12 years ago #

abiguity

DiGi [PersonRank 1]

12 years ago #

Python isn't so far...

Reto Meier [PersonRank 10]

12 years ago #

[put at-character here]Tony: Exactly. The problem with a 'wordy' natural language code like this, is that when you've finished writing it 'properly' it's going to be a lot harder to figure out what's going on than if it were written in a more concise code.

Also, putting all those 'for this whole function' conditions *after* the meat of the code means that you have to read the whole thing before you can start processing.

Not to mention the ambiguity in the 'display important ambiguities' statement. What's important? According to who?

Ionut Alex. Chitu [PersonRank 10]

12 years ago #

This article has a good counter-example:
ptg-global.com/papers/developm ...

Suresh S [PersonRank 10]

12 years ago #

> ...What should it do if it fails to open the connection?

The answer is simple. If it fails to open connection.Show the this message. <I>The query you searched is not in cache or not searched frequently in the planet earth.</i>

Then show the following
"Do you want to raise Keyword Density for this query".

;)

NoName [PersonRank 4]

12 years ago #

You just invented AppleScript... :)

Reto Meier [PersonRank 10]

12 years ago #

Careful Suresh S, you're using markup! You mean:

If it fails to open connection.Show this message in italics, "The query you searched is not in cache or not searched frequently on the planet Earth."

:)

Rupert Goodwins [PersonRank 1]

12 years ago #

It's lovely, isn't it?

But either we have NL parsing so good that this and the near-infinity of functionally equivalent ways of expressing it in 'normal' English will work, or the programmer has to learn the strict subset of English which the parser groks. And English is, of course, nothing like a defined thing.

Then we get back to learning a programming language – and everything we've learned since Hopper.

And it's not as if the skills you need to learn to make databases work are that much softer than those you need to talk to them in their language.

There might be a half-way house, an Eliza-style interface that exposes ambiguity and guides the programmer/user towards a proper functional specification of what they want to do.

>What do you want to do?
Search for things
>What things are you looking for?
Stuff in books
>Are these books online?
Yes
>So you want to search online books for stuff.
Yes
>Is this stuff just words? Searching for pictures is much harder, but we can add that later if you wish.
>Yes, just words
OK. We're looking for words in online books. Do you want to see all the places those books might be now, or are there particular places you know you'll be looking?

...

>Do you want to see all the results at once? There could be thousands, each many hundreds of pages long!
No, I just want to see bits of each

(etc)

Which is really a text-based IDE, and nothing like a new idea!

Even better would be for the NL interface to know when others have done the same thing, and allow the user to pick by example. The Net may not be an infinite number of monkeys writing Hamlet, but it certainly has a large number of wheelwrights inventing the round thing.

Roger Browne [PersonRank 10]

12 years ago #

Natural-language programming is sometimes considered the "holy grail", yet it will leave us with all the ambiguities of natural language.

On the other hand, a rigorous notation in object-oriented style with powerful libraries and well-chosen feature names is more compact and probably more readable to an experienced practitioner.

Even in fields of human endeavour where natural language COULD be used, we frequently prefer to use a stylized notation instead. My daughter's dance might include a "demi plie" (which of course are French words but used in a specific pattern) instead of a "bend your knees halfway". Her piano music will say "Ritardando" (which of course is an Italian word but used in a specific way) instead of "slow down a bit here". Likewise, my software will use English words (if, else, loop, function, select, etc) but used with a domain-specific meaning rather than as natural language.

Anyway, here's a very rough implementation of your example, written in an arbitrary but regular notation. All of the constructs used do already exist in one or another programming language. For example, the "old" keyword (used to measure the elapsed time) does exist in the Eiffel programming language, and allows one to access the state of the variable as it existed at the start of the function call. Stuff like escaping HTML should of course be taken care of at the library level and shouldn't need to concern the application programmer.

This example passes the "telephone test" quite well. You could read it over the phone to another programmer who knows this language, and they would grok the meaning.

function show_books(search_query)
is medium_priority distributed_execution

   page = new page_builder

   if search_query.is_empty
   page.add_paragraph(internationalize(response(
   "empty_search_query"))
   else
   database_connection.open_or_reuse(global_settings)
   database_connection.find_matching_records("book",
   search_query)
   if database_connection.has_results
   table = new html_table_builder
   database_connection.for_each_result as row
   table.add_row(row.chop(30))
   end
   page.add(table)
   else
   page.add_paragraph(internationalize(response("sorry")))
   end
   database_connection.close
   end

   if time – old time > 0.5
   send_email(global_settings.admin_email, database_server.status,
   webserver.status)
   end

end

Reto Meier [PersonRank 10]

12 years ago #

The thing is, getting the syntax right is not the hard part of programming. It's the logic, the architecture, and everything else that goes in to it. Most programmers will have moved through multiple languages in their careers (Pascal, Java, Delphi, C# myself so far), learning the syntax takes a couple weeks at most.

The stuff that goes unspecified in Philipp's example (what servers are we using? How do we split the work across them? How do we sort, cache and search the books? How do we interpret the search term and what entries match it?) is the hard part. What's left is easy.

At best, if we have a natural language programming language the requirements spec becomes your software, but then writing the requirements becomes as hard as writing the software is now. You're just shifting the work but the energy / entropy required to get it done remains the same. Joel says it far more eloquently than I:

joelonsoftware.com/items/2007/ ...

Roger Browne [PersonRank 10]

12 years ago #

Unfortunately the formatting wasn't retained. Here's the same function with formatting (which of course should be system-maintained so that the programmer never needs to think about it):

pastebin.com/f627393dd

Philipp Lenssen [PersonRank 10]

12 years ago #

[Rupert, that is interesting! Here's another story built on that...]

> What do you want to do?

I want to add the ability to add stars to a forum message.

> You mean the Google Blogoscoped forum on your first server?

Yes.

> What do you mean by "star" specifically?

An icon showing a star image.

> Are you OK with using a Creative Commons-licensed existing icon?

Thanks but no, I created my own, it's the one on the hard disk I created today called "star.png".

> I found this file and will upload it to your server. I found a way to compress the file size without decreasing quality, should I do so?

OK!

> Which users do you want to be able to star a comment?

Everyone, but only once per IP. Also, save the rating in a cookie. And close the ability to rate after 1 month.

> OK, will do. Caveat: do you know that sometimes, a household or office shares a single IP, causing potential problems?

Yes, ignore this problem. Please do not remind me of this problem in future sessions.

> OK, noted. I will not remind you of this problem in future sessions. How do you want the rating interaction to work?

Please offer me the two most popular patterns you find in your library.

> OK. You can either [1] use a combo box which shows the rating, along with a "Submit" button, which will cause the page to be submitted. Or [2] you can do this via real-time interaction which works on mouse hover.

OK, I take that one.

> Sorry, I did not understand you. Would you want choice [1] or [2]?

Give me #2.

> OK, done. (Note I adjusted my parser just now for future sessions to better understand you.) Would you like to preview this change to the forum software as usual?

Yes, please populate the forum with sample data and show me a preview I can play around with.

> Should I use the same sample data and preview URL as we specified during our session last week?

Yes.

> OK, please preview the new software at http: // blogoscoped.com/forum/preview/ (you have the password, if not, let me know). Note I prepared the HTML/ CSS output to render the same in the top 8 browsers used to access Google Blogoscoped, according to your last month's statistics.

Thanks, I will talk to you again in some minutes.

Tony Ruscoe [PersonRank 10]

12 years ago #

Philipp, that conversation is pretty similar to ones I've had with clients. The difference being that each question was sent in separate emails and the whole process took around two months... :-)

Roger Browne [PersonRank 10]

12 years ago #

> Yes, ignore this problem. Please do not remind me of
> this problem in future sessions.

And one day, that will come back to bite you. You'll be doing a different application, one where multiple users per IP-address really does matter, and you will have completely forgotten that you told your auto-program-buddy not to remind you about this again.

Reto Meier [PersonRank 10]

12 years ago #

It's an interesting though excersize but in real life that conversation would have to go on for about 30 pages.

Where do you want the stars placed?
what do you mean by rating? What does that have to do with stars?
How many stars do you want to show?
How many stars can a user add?
Where should the stars be placed?
How big should they be?

In your example there's assumed knowledge of what you mean by 'star ratings' because we all know what that is. A computer won't. Change:

"I want to add the ability to add stars to a forum message"

with:

"I want to add the ability to add wowzers to a forum message."

and it gets harder. When you replace the concept of stars representing 'ratings' it gets even harder:

"I want to add the ability to add wowzers to a forum message so users can phaloom the messages."

When you're inventing or innovating from scratch you have to go explain exactly what each new concept is.

shaneypoo [PersonRank 1]

12 years ago #

Interesting concept, kind of like the kiteh language. Another I'd like to see a prototype of is visual programming, I think it will happen soon with ajax widgets.

For example with webtops, you start with a box, you can drop in data type fields like images, links, prices, labels. Sort them by drag and drop. Another box could be a function or operator, draw lines with conditionals to connect items or columns.

Kind of like a functional flowchart.

Reto Meier [PersonRank 10]

12 years ago #

The sort of visual programming you describe already exists in the form of things like 'Rational Rose' that take a UML diagram and convert it to code. Yahoo Pipes does a fairly good job of it too.

Juan Sagasti [PersonRank 1]

12 years ago #

I would leave Natural Language to poets and artists. I'd rather prefer people speaking strict languages than computer speaking natural languages.

Ambiguity in people's communication reduces our efficiency as a society. In order to solve these ambiguities and subjetivities we need to support the burden of lawyers, accountants, and other ridiculous overpaid interpreters.

Jayenkai [PersonRank 2]

12 years ago #

It's a nice idea, but..
A) I don't like the "Do this" after each if/for, you could've easily done without that and kept it just as readable.
B) It's not easy to understand "At a glance". That's what you REALLY want out of a language, something that you can quickly scroll through to find that one line with the bug in it.

Reto Meier [PersonRank 10]

12 years ago #

Also, this is an arbitrary level of abstraction. It won't work meaningfully as specified, so you could have just as happily written it thus:

Function Show Books (search query)
   Search the book database for the search query. Display the results in a table limiting the text to 30 characters. Show error messages where appropriate and make sure it all happens quickly. Make sure text is displayed as human readable and takes the users location into account. If it takes longer than 5 seconds email the administrator.

Or

Search the book database for the search query and display the results quickly.

J. McNair [PersonRank 10]

12 years ago #

Sorry, but NL for PROGRAMMING is kind of a dead end. As soon as something starts to work people are going to want formal, strict grammars so that we can read each others programs.

Of course, programming languages should become more literate and readable. Programmers should carefully design and name things in their code, for themselves and other people. Languages should use symbols and special characters in a consistent and logical manner.

We shouldn't return to COBOL, but I do actually like AppleScript (you may all start laughing now).

Personman [PersonRank 8]

12 years ago #

Inform 7 (inform-fiction.org) is an interesting "NL" wrapper around the C++-like Inform 6, a language for developing interactive fiction. The IF community seems to like it in general, though there was lots of outcry when it first came out. It is of course nothing like actual NL, but there are some things that the English-like syntax makes easier. And of course some things that it makes harder. Worth checking out anyway.

stefan2904 [PersonRank 10]

12 years ago #

uh jea. Btw, i "speak" cobol! ;-)

Zim [PersonRank 10]

12 years ago #

It remember me this:
istartedsomething.com/20070809 ...

Visual Basic FTW! :P
I still love PHP.

Rich [PersonRank 0]

12 years ago #

HTML? This person hasn't even heard of MVC, and he's bothering us with natural language. Here we go again: a lot of effort to fix the age old problem of someone not learning what's already available.

As for the commenters; it's not ambiguity that's the problem. It's the *lack* of ambiguity: I should be able to say "it" and the parser know what I'm talking about, from context. I should be able to use real-world language like "what you found", rather than "record". An intelligent language parser isn't worth its salt if it can't learn.

I also see a problem with the olde-worlde programming language constructs (function, if then else, foreach and so on). If it's a function, where's the maths?

Finally, AppleScript is only good for quick hacks. Until Automator, OSAscript, and AppleScript achieve feature parity, it's useless.

Philipp Lenssen [PersonRank 10]

12 years ago #

The "view" as part of the MVC wasn't even in the code Rich... the fictituous programmer made sure to use CSS (and/ or XSLT) for that, restricting the (X)HTML to just semantics :)

Reto Meier [PersonRank 10]

12 years ago #

Actually Philipp that's not quite right.

You've coupled the view to the model by saying 'Display the record content in an HTML table row' and 'Wrap the above in an HTML table'.

To follow MVC better you'd need to decouple that to something like 'tell the UI that you found these new results'. Then you'd need a different function in the view that said 'display the search results in an HTML table'. The controller would live in between listening for the model to tell it about the new search results and telling the view to update. The CSS is the presentation layer of the view, it's not the view in the MVC.

Philipp Lenssen [PersonRank 10]

12 years ago #

Yes, OK, the "display" word implies that it will be displayed. That is not conformant with good semantic-only output from a function, which could then be either displayed or not depending on what the CSS or XSLT determine. In real life for bigger work projects (as opposed to this sample function), I might let the function return a string or XML object (as XHTML Strict – or an array, or another object of choice representing the data) which would not know anything about its display/ output, but be merely a semantic representation of the data. This XML object or string can then be transformed via XSLT depending on what is needed and how it is needed or be styled via CSS. Anyway, I hope it is clear that the function in the post was just a random sample... imagine any piece of code of your own and think of it in natural language to make the post work better :)

J. McNair [PersonRank 10]

12 years ago #

[put at-character here]Rich
Oh dear, pronouns. It's very hard to get DWIM* right. Not impossible (otherwise, there wouldn't be search engines), but very hard. One would hope to only do it where the results are predictable and the learning would have to be limited, lest it spew all kinds of craziness on your behalf.

If-then-else is one of the few ancient programming constructs that can be easily explained to people. It may never go away. Functions are probably better called "subroutines" unless you're a LISPer and then they are lambdas. Most of the other stuff could do with being closer to its mathematical equivalents (lists more like Set Theory) but you'd still have to get people to USE them.

I remember somewhere a proposal "skinnable syntax" for lisp dialects, so you can define your own grammars and it compiles/interprets to the same thing. I think it uses XML tomfoolery to accomplish this. I think the guy that proposed it works at Google now so who knows...

The biggest problem here is that programming as we know it enforces structure and rules, especially for "systems programming". The human mind is all over the place as reflected by our languages for communication. A programmer will always have to work to make his/her intentions concrete as mathematicians have to work to prove their hypotheses as formal hypotheses. It will never truly be "easy" or "simple" unless the task to be accomplished is also easy or simple.

*Do What I Mean [not what I say]

Freiddie [PersonRank 7]

12 years ago #

Looks like pseudocode. But I wonder if someone invents this kind of "Natural Language Code", would it be useful, or not?

Jabapyth [PersonRank 1]

12 years ago #

How's this for a proposal: we just change the english language so that it mirrors a programming language. ;)
Imagine trying to speak in pearl....mother of all tongue twisters :D

Haochi [PersonRank 10]

12 years ago #

I thought lolcode solved the problem...
en.wikipedia.org/wiki/LOLCODE

I think that NL programming works only good on paper (so far).

Leif902 [PersonRank 1]

12 years ago #

Programming and computers in general are meant to be mathematically based, not language based :)

jims tips [PersonRank 1]

12 years ago #

Hmmm. Do you really expect the IM culture to be so precisely verbose when programming? I'll believe it when I see it....

RockSlice [PersonRank 0]

12 years ago #

NL Programming isn't practical until we have AI (a program that is able to converse with people well enough to pass the Turing test).

At that point, it will probably not be so much the person writing the program in NL, but rather explaining what he wants to the AI, which would then search for code (perhaps via Google's codesearch) which does what the user wants.

(The AI would also have to be able to "speak" the different languages, though that would be easier)

The user could then describe changes in how they want the program to work, and the AI would make the necessary changes to the code.

DPic [PersonRank 10]

12 years ago #

Lojban could bring us closer to this! It eliminates ambiguity in language!

Reto Meier [PersonRank 10]

12 years ago #

"...but rather explaining what he wants to the AI, which would then search for code [...] which does what the user wants."

Arrrrrgh! This might become a 'good' way to create bad scripts but it would be a disaster for writing code thst does anything new. If my work days of writing software amounted to searching for code that does what I want and splicing it all together I would be a Very Bad Programmer.

I can see NL becoming the way we interact with out computers, but as many have pointed out, we not only want but *need* the precisely defined constructs of a programming language to write meaningful software.

It's the same reason why maths and logic have constructed their own codes and language to define problems and solutions rather than sticking with NL. There's a reason a mathematical proof isn't written out as a few paragraphs of NL text, same for software.

mak [PersonRank 5]

12 years ago #

I can't think of this as a machine-interpreted language that runs like this. But, as a programmer and instructor, I can see how it makes our life easier.

One of my code teaching techniques is to write the function in a similar manner, using natural language in the comments and writing almost all lines without actual code. Then the student's role is to convert this to actual code using the syntax of the language at hand (ActionScript or JavaScript in my case)

This method helps them to think in a structured way following these three logical steps:
1- Look at the task from afar, and try to come up with an understanding of what's required.
2- Write and outline of what you decided to do -> here comes the role of natural language and the method described above
3- convert natural language and outline of thoughts into lines of code

This works most of the time.

Philipp Lenssen [PersonRank 10]

12 years ago #

> "...but rather explaining what he wants to the
> AI, which would then search for code [...] which
> does what the user wants."
>
> Arrrrrgh! This might become a 'good' way to
> create bad scripts but it would be a disaster for
> writing code thst does anything new.

Why? All we did so far was further abstract the syntax – we did not talk about replacing the actual creative thought processes necessary for the software. The idea of an aiding AI could be: you can invent whenever necessary, but use existing patterns whenever you don't feel like (example: use MySQL, an abstraction of data, if you want, or if you're going for super-performance or a different database feature set – e.g. you're Google! – write your own database system or drill down into the code behind MySQL). Your craft would then be more about system knowledge – e.g. as web developer: understanding the web, understanding how websites work, what people look for – as well as common sense and good logic thinking, than syntax knowledge ("semicolon goes here, parameter order of database connection function is x y z") though.
Even some of today's scripting languages use more abstraction allowing you to more quickly write your programs. Like Python, for instance, though even with languages like that one there are often seemingly arbitrary syntax quirks which make the learning curve more steep (think of the colon in Python which you need to append to the end of each "for" statement).

By the way, the abstraction must be technically *right* of course. For instance I consider some of the abstractions of the .NET framework in the space of client-side browser libraries (the JS stuff that came with .NET some years ago, not sure about its current state) really ugly. That would be a library where I'd say, "I'd rather invent in this space than use these existing libraries."

Reto Meier [PersonRank 10]

12 years ago #

"...we did not talk about replacing the actual creative thought processes necessary for the software."

I disagree. "spread it across different servers for extra speed" is something your manager tell you to do to 'make it go faster' because he read something about cloud computing on Techcrunch. Figuring out how to do this effectively is context sensitive and required creativity to be effective.

Otherwise surely your goal would look more like this:

"Search the book database for the search query and display the results quickly."

You're approach only goes half way – if you're abstracting away syntax get rid of it all and jus describe the solution. Better still, just describe the problem:

"Find the books I want"

And let the AI figure out how to find them and how to show you the results.

My biggest problem is that this sort of abstraction creates lazy developers. Modern scripting languages which use a high level of abstractration gave rise to 'script kiddies'. It's not that you can't do anything useful at this level of abstraction, it's that a combination of search-copy-paste coding combined with a high level of abstraction and a poor understanding of what's actually happening under the hood has a much better chance of producing garbage. Witness a great many Web 2.0 sites that can't scale, have weird arbitrary limitations, and run slowly while consuming all your CPU cycles.

I can't wait until my PC has an AI that abstracts away scripts and macros so I just give it a problem and it figures out a solution based on similar problems and my previous preferences.

In short, you still need programming languages to write software, but the future of scripting is continual abstraction.

Philipp Lenssen [PersonRank 10]

12 years ago #

> I disagree. "spread it across different servers
> for extra speed" is something your manager tell
> you to do to 'make it go faster' because he read
> something about cloud computing on Techcrunch.
> Figuring out how to do this effectively is context
> sensitive and required creativity to be effective.

Absolutely, that "figuring out" is required *today*. But it may not always be in the future! I am hoping for systems to become smarter and smarter to figure out such technical optimization on their own, whereever possible, and whenever wanted by the software creator. As you probably know, even something like garbage collection, or dynamic typing, is the computer "figuring it out" for the programmer. (And there are of course use-cases when you want e.g. static typing, but there may also be use-cases where you prefer not to have it!)

Ljancho [PersonRank 1]

12 years ago #

Don't listen to them! I really really like the idea! Could someone with good skills start such a language?

Reto Meier [PersonRank 10]

12 years ago #

[put at-character here]Ljancho: People are trying. The thing is, the 'language' already exists. It's English. There are regional varients like 'German' and 'French', but the point of NL is that it's just that.

The challenge is creating an interpreter / compiler that understands natural language and can compile (or translate) that to C++ or bytecode or machine code.

Adrian Smith [PersonRank 0]

12 years ago #

May be the problem is nota natural language system but a better way of gettting the infomation that you require like how to do COM in Haskel for instance – I have no Idea then would have to go find out how and for my perticular com object.
   If the language was exceptiionally well documented and debuggable then the need for a Natural language might go away.
   I have real difficulty remembering 'how' to do things even in Python (love the syntax tho) so quick access on how to do stuff is a must.
   Also better wrapping of complex functionality, more abstraction would help like automatic garbage collection etc etc. Main line programming languages are always going to be needed to build the 'general purpose' languages that could be opened to the masses but one has to remember that it would, like more accurate speech recognition or approaching the speed of light in physics, have deminishing returns on improvement and people do not want to spend days and days of effort to get minimal returns. This is one reason why programming language development has 'stalled', its just too much effort for the return. Some people can use it and its 'relatively' easy so the next push is never done.

This thread is locked as it's old... but you can create a new thread in the forum. 

Forum home

Advertisement

 
Blog  |  Forum     more >> Archive | Feed | Google's blogs | About
Advertisement

 

This site unofficially covers Google™ and more with some rights reserved. Join our forum!