Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it better to use a "natural" language to write code?

Tags:

nlp

I recently saw a programming language called supernova and they said in the web page :

The Supernova Programming language is a modern scripting language and the

First one presents the concept of programming with direct Fiction Description using

Clear subset of pure Human Language.

and you can write code like:

i want window and the window title is Hello World.
i want button and button caption is Close.
and button name is btn1.

btn1 mouse click. instructions are
   you close window
end of instructions

my question is not about the language itself but it is that are we need such languages and did they make writing code easier or not?

like image 463
Mohamad Alhamoud Avatar asked May 01 '10 17:05

Mohamad Alhamoud


3 Answers

The code may look like natural language, but it's really just regular computer code with different keywords. In your example, I want is probably synonymous with new. It's not like you can use natural language directly and say make me a window instead (and if you could, things would get even uglier...).

Lets take a close look at your code and the language implications:

i want window and the window title is Hello World. 

i want means new, and denotes beginning of the argument list. the <type_name> <member_name> is sets instance variable member_name on the object being created. Note that you have to write the type_name twice.

i want button and button caption is Close.
and button name is btn1.

. ends a statement. However, you can 'chain' method calls on an object by starting the next statement with and. Also, how do you refer to a variable named Close instead of the string "Close"? Heck, we even have this problem in regular English: what the difference between 'Say your name' and 'Say "your name"'?

btn1 mouse click. instructions are
   you close window
end of instructions

mouse click is an identifier containing a space, should be mouseClick. instructions are defines a lambda (see the is vs. are keyword confusion causing trouble yet?). you close window calls window.close(). end of instructions is end of a lambda. All of these are longer than they need to be.

Remember all that? And those are only my guesses at the syntax, which could be completely wrong. Still seem simple? If so, try writing a larger program without breaking any of those rules, AND the additional rules you'll need to define things like conditional logic, loops, classes, generics, inheritance, or whatever else you'll need. All you're doing is changing the symbols in regular programming languages to 'natural language' equivalents that are harder to remember, unnecessarily verbose, and more ambiguous.


Try this translation:

var myWindow = new Window( title="Hello World" );
myWindow.addButton( new Button( caption="Close", name="btn1" ) );

btn1.onMouseClick = function() {
    myWindow.close();
}

See how each line maps to its counterpart in the previous example, but states the intent more directly? Natural language may be good for execution by humans, but it is terribly difficult to use for precise specifications.

The more you try to make English communicate these ideas easily and clearly, the more it's going to look like programming languages we already have. In short, programming languages are as close to natural language as we can get without losing clarity and simplicity. :D

like image 110
Gordon Gustafson Avatar answered Jan 03 '23 22:01

Gordon Gustafson


Since the fundamental difficulty of programming is getting your thoughts ordered enough to tell the computer what to do, making the language more “natural” is highly unlikely to make it more accessible to non-programmers; the language itself was never the real problem in the first place. What's more, all that extra clutter of natural language doesn't help any programmers (worth the name) with what they're doing either, so why add it?

Or can we have a real natural language programming language, complete with “Um”, “Er”, and “Oh, I don't really know”? :-)

like image 43
Donal Fellows Avatar answered Jan 03 '23 23:01

Donal Fellows


Edsger W. Dijkstra, On the foolishness of "natural language programming". I have nothing to add.

like image 40
Wildcat Avatar answered Jan 04 '23 00:01

Wildcat